What is wrong in my plot

eh = 8.854e-12;
h = 50e-9;
e0 = (1.465^2)*eh;
e1 = (1.624^2)*eh;
e2 = (1.333^2)*eh;
w1 = 450e-9;
w2 = 750e-9;
for i=1:100
w(i) = w1 + (i-1)/100*(w1-w2);
r01(i) = (sqrt(e0 - e0*0.9806)/e0 - sqrt(e1 - e0*0.9806)/e1)/(sqrt(e0 - e0*0.9806)/e0 + sqrt(e1 - e0*0.9806)/e1);
r12(i) = (sqrt(e1 - e0*0.9806)/e1 - sqrt(e2 - e0*0.9806)/e2)/(sqrt(e1 - e0*0.9806)/e1 + sqrt(e2 - e0*0.9806)/e2);
kz(i) = 2*pi/w(i)*sqrt(e1 - e0*0.9806);
R(i) = (r01(i) + r12(i)*exp(2*1i*kz(i)*h))/(1 + r01(i)*r12(i)*exp(2*1i*kz(i)*h));
end
plot(w,abs(R));

Antworten (1)

Star Strider
Star Strider am 23 Jul. 2019

1 Stimme

Only ‘w’ and ‘kz’ change (‘r01’ and ‘r12’ calculate the same thing 100 times), and ‘kz’ is multiplied by ‘h’ (which is ) so its influence is negligible, and the plot is essentially a horizontal line.
You can see some variation if you plot the log of ‘|R|’:
plot(w,log(abs(R)))
I have no idea what you are doing, so I cannot suggest any changes, other than to move the ‘r01’ and ‘r12’ calculations before the loop.

4 Kommentare

Aravind Varma
Aravind Varma am 23 Jul. 2019
Thank you for responding quickly and pointing these out. I have tried the logarithmic plot but did not get the expected results. Also, why does it tell that the variables (w,r01,r02,kz and R) change size on every loop iteration? Any clue?
Star Strider
Star Strider am 23 Jul. 2019
My pleasure.
For whatever reason, semilogy does not show the variations well, however plot with log(abs(R)) does.
You can tell that only ‘w’ and ‘kz’ change (and that the others that create ‘R’ do not change) simply by looking at them. (It is always good to see what your code is actually doing.)
Aravind Varma
Aravind Varma am 23 Jul. 2019
I have another doubt. The plot shows results between 1.5e-7 and 4.5e-7 only whereas I gave the starting and ending points to be 4.5e-7 and 7.5e-7.
Also, I tried using xlim([4.5e-7 7.5e-7]). but it shows nothing in between these limits. (Atleast it should a constant)
Why does this happen?
‘... I gave the starting and ending points to be 4.5e-7 and 7.5e-7’
Well, you actually did not.
If you run:
wlim = [min(w) max(w)]
the result is:
wlim =
1.53e-07 4.5e-07
‘... I tried using xlim([4.5e-7 7.5e-7]). but it shows nothing in between these limits.’
That is because there is nothing there to plot.
I have no idea what you are doing, so I cannot offer any suggestions as to how to do what you want. You need to examine your code and figure out the reason it is not doing what you want it to do.

Diese Frage ist geschlossen.

Produkte

Version

R2016b

Gefragt:

am 22 Jul. 2019

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by