Why is the a vector not getting added to constants?
Show older comments
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
Torsten
on 9 May 2023
Maybe s = 0 or omega = 0.
John D'Errico
on 9 May 2023
Edited: John D'Errico
on 9 May 2023
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.
Athulya Thulaseedharan
on 9 May 2023
Edited: Athulya Thulaseedharan
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.
Answers (1)
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 Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!