Why is the a vector not getting added to constants?

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

Maybe s = 0 or omega = 0.
It is literally impossible to know, since we see only one line of code.
Are the elements of omega so small, that when you square them, they contribute nothing to the result? Is s==0, or again, so small that you do not see the result? Or, is the variable s imaginary, so that when you multiply it by 1i, the result is real, and so it appears in the real part of the result?
This is the kind of thing that we cannot debug, because we are given insufficient information, and no testable code. BUT you can. Just learn to use the debugger. Then at that line, check each variable.
And, even though you may THINK that s is not zero, or that omega is not just a vector of zeros, the only way to know that for a fact is to check what is in those variables. You seem to be quite certain that something is wrong. So it is you who needs to do the work to learn what is wrong.
LEARN TO USE THE DEBUGGER.
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.
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)

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.

Products

Release

R2022b

Answered:

on 16 Aug 2023

Community Treasure Hunt

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

Start Hunting!