Error: " Conversion to Logical from sym is impossible"

4 visualizaciones (últimos 30 días)
Yibo Li
Yibo Li el 12 de En. de 2013
I have my code here, it is very simple, I just want to solve the equation in "solve" function and then do a "if judgement", but error comes out and shows like this:
Code:
syms t t1 t2 Vds Vds1 Vds2 x y;
t1=0:1e-8:1e-6;
t2=1e-6:1e-8:2e-6;
t=[t1,t2];
Vpeak=1.5;
Vrise=(Vpeak/1e-6)*t1;
Vfall=(-Vpeak/1e-6)*t2+3;
t=[t1,t2];
Vsweep=[Vrise,Vfall];
Ce=2.2e-12;
Vgs=1.86;
Vt=1.742;
xpre=0;
tpre=0;
a=zeros(1,55);
for k=1:55
solve(0.032*((Vgs-Vt)*x-(0.5)*x^2)+Ce*((x-xpre)/(t(k)-tpre))==7.0063e-5*(Vsweep(k)-x)^2+2.2929e-5*(Vsweep(k)-x));
if x(1)<(Vgs-Vt)
Vds(k)=x(1);
else
Vds(k)=x(2);
end
xpre=a(1,k);
tpre=t(k);
end
Error:
Conversion to logical from sym is not possible.
Error in Codetest (line 32)
if x(1)<(Vgs-Vt)
Could somebody help me, thx.

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de En. de 2013
You do the solve() but you throw away the answer.
You then have
if x(1)<(Vgs-Vt)
but x is still a symbol from the "syms", so you are trying to compare a symbol (that has no value other than its own name) to a numeric value. You cannot test that in a MATLAB "if" statement as it is simultaneously true and not true.
If your solve() had been solving for "x" then you would probably still have a problem because x would then at best be a symbolic number rather than a floating point number. You would need to test it with
if double(x(1)) < (Vgs-Vt)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by