Why this is plotting blank window?

P=16;
a=5.51*(10^-10);
h=6.62*(10^-34)
m=9.11*(10*-31)
E=0:0.001:100;
h=6.62*(10^-34);
A=sqrt(2*m*E)/h;
f=(16*(sin(A*a)./(A*a)))+cos(A*a);
plot(abs(A),abs(f),'.b')

4 comentarios

John D'Errico
John D'Errico el 4 de Dic. de 2017
Please don't paste code as a picture. Instead, learn to use the "{} Code" button.
1. Paste in the code.
2. Select it with the mouse.
3. Click on "{} Code".
Image Analyst
Image Analyst el 4 de Dic. de 2017
Actually, your code does not plot anything at all. There is no call to any function which would create any kind of graph/plot/chart. It should not even plot/create a blank white rectangle. Please attach your actual code that you used.
SHEREEN AHMED
SHEREEN AHMED el 4 de Dic. de 2017
Editada: SHEREEN AHMED el 4 de Dic. de 2017
My mistake! I've just edited the question.
John D'Errico
John D'Errico el 4 de Dic. de 2017
Editada: John D'Errico el 4 de Dic. de 2017
Sorry. I mistakenly zapped the plot line away when I made the code readable.

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 4 de Dic. de 2017
What is f as you generated it?
f
f =
Columns 1 through 28
NaN Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Columns 29 through 56
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Columns 57 through 84
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
...
Look carefully at the variables you created. Do they make sense? Does A make sense? Only you know what you are trying to do here.

4 comentarios

SHEREEN AHMED
SHEREEN AHMED el 4 de Dic. de 2017
Actually, I'm new to Matlab. I'm working on my assignment which is plotting Kronig-penny model except for A which is constant here (16) instead of the main coefficient.
But we don't know if what you did makes any sense. For example, if I look at a few lines of yours:
P=16;
a=5.51*(10^-10);
h=6.62*(10^-34)
m=9.11*(10*-31)
Is m correct? I wonder if that is a typo on your part. Did you really want this?
m=9.11*(10*-31)
m =
-2824.1
Or, this?
m = 9.11e-31
m =
9.11e-31
I'd suggest that you get used to writing these numbers in scientific notation, thus I assume you wanted:
a=5.51e-10;
h=6.62e-34;
m=9.11e-31;
Less chance of a mistake when you write it that way.
As you had it, m is a negative number, and then you take a square root, to form A.
SHEREEN AHMED
SHEREEN AHMED el 4 de Dic. de 2017
Editada: SHEREEN AHMED el 4 de Dic. de 2017
I'm using Matlab R2017b, it converts those numbers (from the scientific notation I used to the second form you wrote) instantly when I run the code so, that's right I mean the second form.
SHEREEN AHMED
SHEREEN AHMED el 4 de Dic. de 2017
However, you're right.

Iniciar sesión para comentar.

Guillaume
Guillaume el 4 de Dic. de 2017
As indicated by John, your f is full of infinite or nan value, so you have to go back through your expressions and work out why.
Had you done that you would have seen straight away that your A is full of complex values. Since A is the square root of something, that something must be negative to result in complex values.
So let's look at the values of E and m that go into that something
>>m
m =
-2.824100000000000e+03
Well, there you go. m is negative. I'll let you work out why (hint: it's a typo).
That would have taken you the whole of 2 minutes to work out for yourself if you'd simply looked at the values of each of your variables. Instead you had to wait over two hours for somebody else to do it for you.

Categorías

Etiquetas

Preguntada:

el 4 de Dic. de 2017

Comentada:

el 4 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by