Conversion to double from sym is not possible.

조회 수: 2 (최근 30일)
Smail
Smail 2012년 2월 29일
Hii,
I have calculated something with matrix and want to plot it after wards. But i got this message from matlab "Conversion to double from sym is not possible".
here is my code. There are a lot of variables, but the point is the plot. Hope that someone can help me
thanx
syms k q a b
beta=(1/2)*(1+((i*k)/q));
betah=(1/2)*(1+(q/(i*k)));
betahcon=(1/2)*(1-(q/(i*k)));
betacon=(1/2)*(1-((i*k)/q));
Sm=[betah betahcon; betahcon betah];
sp=[beta betacon; betacon beta];
thb=[exp(q*b) 0; 0 exp(-q*b)];
tha=[exp(-q*a) 0; 0 exp(q*a)];
thab=thb*tha;
ta=[exp(i*k*a) 0; 0 exp(-i*k*a)];
tb=[exp(-i*k*b) 0; 0 exp(i*k*b)];
Vh=Sm*thab*sp;
M=tb*Vh*ta;
M1=1./M(2,2);
AA=10^-10;
eV=1.602*10^-19;
a=10*AA;
b=500*AA;
V=1*eV;
m=0.067*9.109*10^-31;
hbar=(6.626*10^-34)/2*pi;
E=linspace(0.001*V,4*V,1000);
q=((sqrt((V-E).*2.*m))./hbar);
k=((sqrt(2.*m.*E))./hbar);
abs(M1).^2 ;
plot(E,M2)
  댓글 수: 2
Smail
Smail 2012년 2월 29일
M2=abs(M1).^2
Smail
Smail 2012년 2월 29일
I have also tried this
M2= double(abs(M1).^2) and
M2= vpa(abs(M1).^2)
but it doesnt work

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 29일
Remove the assignments
a=10*AA;
b=500*AA;
q=((sqrt((V-E).*2.*m))./hbar);
k=((sqrt(2.*m.*E))./hbar);
Then after assigning to E, use
M1M2 = double( subs({M1, M2}, {a,b,q,k}, {10*AA, 500*AA, ((sqrt((V-E).*2.*m))./hbar), ((sqrt(2.*m.*E))./hbar)}) );
M1n2 = abs(M1M2{1}).^2;
M2n = M1M2{2};
plot(E, M2n);
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 3월 6일
Sorry "does not work" is not specific enough for me to know what you are seeing.
Smail
Smail 2012년 3월 6일
Ohh, my bad
i get this message from matlab
??? Error using ==> mupadmex
Error in MuPAD command: not a square matrix
[(Dom::Matrix(Dom::ExpressionField()))::_power]
Error in ==> sym.subs>mupadsubs at 152
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in ==> sym.subs at 127
G = mupadsubs(F,X,Y);
Error in ==> subs at 64
r_unique_name = subs(sym(f_unique_name),varargin{:});
Error in ==> plotenbarrier at 35
M1M2 = double( subs({M1, M2}, {a,b,q,k}, {10*AA, 500*AA,
((sqrt((V-E).*2.*m))./hbar), ((sqrt(2.*m.*E))./hbar)}) );

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 29일
You probably need to subs-titute a value in for your symbolic variable.
doc subs
  댓글 수: 1
Smail
Smail 2012년 2월 29일
okay, how do i do that? Can you please show me

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by