i make this programme in order to get a plot in physics ,, but when i run it ,, i get error which i cant identify and correct it .. please i want a help to identify the correct

syms x;
syms E;
syms A;
syms B;
syms K;
syms T;
syms v;
n=1*10^19; %number of electrons
area=1*10^-3; %area
A=2;
w=1*10^-4; %width
q=1.6*10^-19;
h=6.6*10^-34;
v=1*10^6; % electron velocity
K=1.38*10^-23; %boltzman constant
m=0.5; %effective mass
Va=0.1:0.1:5 %applied voltage
E=Va/w;
x=(q*Va)/w;
B=A*x.^2;
a=sqrt((E-A)./B);
Twkb=(1./(sqrt(2*m*B*((a.^2)+1./(x^2))))).*exp((2*sqrt(2*m*B/(h^2))).*((-sqrt(a.^2+(1./x^2))./(1/x))+log((1/x)+sqrt(a.^2+(1./x^2)))));
I=area.*q.*v.*n.*Twkb;
semilogy(Va ,I ,'*','r')
xlabel('Applied Voltage (Va)in Volts')
ylabel('current in(A)')

2 Comments

Aalaa - please copy and paste the full error message (all the red text) to this question.
Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
Error in current (line 25) Twkb=(1./(sqrt(2.*m.*B.*((a.^2)+1./(x.^2)))))*exp((2*sqrt(2.*m*B/(h.^2)))*((-sqrt(a.^2+(1./x^2))./(1./x))+log((1./x)+sqrt(a.^2+(1./x.^2)))));

Sign in to comment.

 Accepted Answer

Aalaa - I suspect the problem is with (at least)
x^2
x appears to be a 1x50 array and so the error message is telling you that is is invalid for the ^ operation since we can only use ^ if the x is a scalar or a square matrix. Are you trying to square each element of x? If so, then use
x.^2
instead.

8 Comments

yes i try it . but i get other error
Error using * Inner matrix dimensions must agree.
Error in current (line 25) Twkb=(1./(sqrt(2.*m.*B.*((a.^2)+1./(x.^2)))))*exp((2*sqrt(2.*m*B/(h.^2)))*((-sqrt(a.^2+(1./x.^2))./(1./x))+log((1./x)+sqrt(a.^2+(1./x.^2)))))
So you will need to look at where you are doing a matrix multiplication operation and ensure that the dimensions of the two matrices are compatible. Start with just
(1./(sqrt(2.*m.*B.*((a.^2)+1./(x.^2)))))
Does the above line work? It probably should since there is no * for matrix multiplication. So if this does compute and produces a result, then log the dimensions of this matrix. Then do the same for
exp((2*sqrt(2.*m*B/(h.^2))
Does this work? I think that it might not since this has been coded slightly differently than the first line. Note the
2.*m*B
vs
2.*m.*B
Which is correct?
i divide it to 3 part (1./(sqrt(2.*m.*B.*((a.^2)+1./(x.^2))))) exp((2*sqrt(2.*m.*B/(h.^2))) ((-sqrt(a.^2+(1./x.^2))./(1./x))+log((1./x)+sqrt(a.^2+(1./x.^2)))) and 3 parts are work ,, and its size are the same[1 50]
Thank but has you any comment want to add And can you tell may what i can do to solve it!!
well what should the result be? a scalar or a 1x50 array?
The result for Twkb must be array in order to substitute in I and get set of data then plot it
so how should the three parts of your equation be multiplied together? with .*?

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics 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!