# Matlab

Discussion in 'Programmer's Corner' started by Cerkit, Jan 10, 2010.

1. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
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

2. ### steveb Senior Member

Jul 3, 2008
2,433
469
Try the following:

Code ( (Unknown Language)):
1.
2.
3. E=0:0.01:70;
4. X=sqrt((75-E)./E);
5. plot(E,X)
6.
7.
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.

3. ### Cerkit Thread Starter Active Member

Jan 4, 2009
275
3
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?

4. ### steveb Senior Member

Jul 3, 2008
2,433
469
When I use the following code, I don't get noise.

Code ( (Unknown Language)):
1.
2. [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]hbar=6.582e-016[/SIZE][/FONT]
3. [SIZE=2][FONT=Courier New]me=9.11e-31[/FONT][/SIZE]
4. [SIZE=2][FONT=Courier New]L=0.2*10^-9[/FONT][/SIZE]
5. [SIZE=2][FONT=Courier New]E=0:0.01:70;[/FONT][/SIZE]
6. [SIZE=2][FONT=Courier New]Y=tan(((sqrt(2*me.*E))/(hbar))*L);[/FONT][/SIZE]
7. [SIZE=2][FONT=Courier New]plot(E,Y)[/FONT][/SIZE]
8. [/SIZE][/FONT]
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: Jan 11, 2010