about if statement and solution

1 Ansicht (letzte 30 Tage)
Dr. Siva Malla
Dr. Siva Malla am 31 Mai 2012
Dear sir,
when I run this bellow code, it shows this error,
code:
syms x
a=solve(x^2+4*x+4);
b=a(1)
if b>2
s=2
else
s=3
end
error:
Undefined function or method 'gt' for input arguments of type 'sym'.
Error in ==> solution at 4
if b>2
my target is, I have to compare the value of 'x' in the equation with constant. but I got this error.
please help me the solution for my problem..

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Mai 2012
If you want numeric answers, work numerically:
a = roots([1, 4, 4]);
solve() does not return numbers: it returns formula, some of which happen to print out like numbers. If you happen to get a solve() result that involves only known functions of constants, then you can use double() on the result to calculate the double-precision approximation of the result.
By the way, you should not assume that the results of solve() are returned in any particular order.
  4 Kommentare
Walter Roberson
Walter Roberson am 31 Mai 2012
In any case, test double(f) not f itself.
Dr. Siva Malla
Dr. Siva Malla am 1 Jun. 2012
Sir,
I have to extract first f1, f2....fn in the vector f, means in all values of f, and I have to test any value of f. like if f2>2; because, first I have to take only real values of f and only I should test these real values of f to 2,( any real value of f). this way I want.
here I am giving complete my program please test. in this program, I cant work with if statement. so please rectify this problem and please help me.
program:
L=1.0*1e-4;
a=0.15*1e-4;
W=10*1e-4;
q=1.6*1e-19;
Es=85.845*1e-14;
Nd=5*1e17;
Nc=1.83*1e19;
Nv=4.07*1e19;
Nref=2*1e17;
KT=0.0259;
q1=1;
h1=0.98;
Umin=40;
Umax=950;
r=0.76
x1=1;
vsat=2.07*1e7;
k1=q*Nd*W*a*x1*vsat;
Vbi=0.8-((KT*q1)*log(Nc/Nd));
U0= Umin + ((Umax - Umin)/(1+ ((Nd/Nref)^r)));
G0=(q*Nd*U0*W*a)/L;
Vp=(q*Nd*a^2)/(2*Es);
Ip=G0*Vp/3;
Z=(q*Nd*a^2*U0)/(2*Es*L*vsat);
Ec=vsat*(h1/(1-h1))/U0;
VG=-8
for k=1:8
Vd=1:20;
a1=((Vbi-VG)/Vp)^0.5;
syms x
for i=1:20
b=x^2-a1^2;
c=h1*(1-x);
d=2*(x^3-a1^3)/3;
e=L*Z*((b-d)/c-b);
y=Vp*b+2*Ec*a*x/pi*sinh(pi*(L-e)/(2*a*x))-Vd(i);
f=solve(y);
f
VL1=Vp*(f^2-a1^2);
end
VG=VG+1;
if Vd(i)>VL1
w=2;
else
w=3;
end
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by