Why is the a vector not getting added to constants?

2 views (last 30 days)
I have a vector omega with 110 elements. I am trying to calculate D1. alpha and detun are constants.
While I add the constant term to the third term that containes omega^2, I am getting D1 as an array with 110 elements that corresponds to (-alpha/2 - 1i*detun). It seems like the third term with omega.^2 is not coming to the calculation. Can someone comment on why I have this issue?
D1 = -alpha/2 - 1i*detun + 1i*s*omega.^2;
  4 Comments
Athulya Thulaseedharan
Athulya Thulaseedharan on 9 May 2023
Edited: Athulya Thulaseedharan on 10 May 2023
Hi John,
Here are the values for s, detun and the omega.
s=-1;
detun = 1e-4;
alpha=140;
nT = 110; T = 3;
omega = fftshift((2*pi/T)*(-nT/2:nT/2-1));
D1 = -alpha/2 - 1i*detun + 1i*s*omega.^2;
After running the code I get a vector ( -70.0000 - 0.0001i repeated 110 times, which corresponds to (-alpha/2 - 1i*detun). I tried to debug but could't find any solutionto this issue.
Walter Roberson
Walter Roberson on 10 May 2023
s=-1;
detun = 1e-4;
alpha=140;
nT = 110; T = 3;
omega = fftshift((2*pi/T)*(-nT/2:nT/2-1));
D1 = -alpha/2 - 1i*detun + 1i*s*omega.^2;
plot(real(D1), 'k-');
hold on
plot(imag(D1), 'b-');
hold off
The values differ for sure.

Sign in to comment.

Answers (1)

Prateekshya
Prateekshya on 16 Aug 2023
I understand that you can see a vector of repeated numbers which is incorrect. Assuming that you have executed the same code that you have provided in the comment section, I added a few more lines to see the first five elements individually. The code that I executed is given below:
s=-1;
detun = 1e-4;
alpha=140;
nT = 110; T = 3;
omega = fftshift((2*pi/T)*(-nT/2:nT/2-1));
D1 = -alpha/2 - 1i*detun + 1i*s*omega.^2;
D1(1)
D1(2)
D1(3)
D1(4)
D1(5)
Here are the values printed in the command window:
-70.0000 - 0.0001i
-70.0000 - 4.3866i
-70.0000 -17.5461i
-70.0000 -39.4785i
-70.0000 -70.1840i
Hence, "omega" is included in the calculation. You can also look at the plot given in the comment. You can also verify if the code that you are executing is same as the one you have provided here in comments.

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!