Matlab

Thread Starter

Cerkit

Joined Jan 4, 2009
286
Hi. Can someone explain to me why I am getting a series of dots in a straight line when i try to plot this in matlab

E=0:0.01:70;
X=sqrt((75-E)/E);
plot(E,X)

Thanks
 

steveb

Joined Jul 3, 2008
2,431
Hi. Can someone explain to me why I am getting a series of dots in a straight line when i try to plot this in matlab

E=0:0.01:70;
X=sqrt((75-E)/E);
plot(E,X)

Thanks
Try the following:

Rich (BB code):
E=0:0.01:70;
X=sqrt((75-E)./E);
plot(E,X)
The use of the dot (.) before multiply and division allows the array values to be used in proper order as you intended. This notation is necessary because Matlab allows multiplication and division (inversion) of matrices.
 

Thread Starter

Cerkit

Joined Jan 4, 2009
286
Thanks that did it. Also if you have a look at

http://en.wikibooks.org/wiki/Materials_in_Electronics/Confined_Particles/1D_Finite_Wells

where they have a graph closer to the end of the page they manage to plot
Y=tan(((sqrt(2*me*E))/(hbar))*L);

how is it that when I plot this on matlab with similar method to plotting as for X I get something that looks like noise rather than the tan expected. The constants I use are
hbar=6.582e-016
me=9.11e-31
L=0.2*10^-9

what am I doing wrong?

 

steveb

Joined Jul 3, 2008
2,431
what am I doing wrong?
When I use the following code, I don't get noise.

Rich (BB code):
hbar=6.582e-016
me=9.11e-31
L=0.2*10^-9
E=0:0.01:70;
Y=tan(((sqrt(2*me.*E))/(hbar))*L);
plot(E,Y)
However, I think you need to check your units. The range of values does not seem realistic. I think the issue may stem from using E in eV and me in kg.

Note that sqrt(me*E)/hbar is not going give you the correct values, unless E is in J and me is in kg, with hbar in units of Js. I mentioned this potential "units" problem in the other post. It's usually safer to stick with SI units consistently.
 
Last edited:
Top