フィルターのクリア

about if statement and solution

2 ビュー (過去 30 日間)
Dr. Siva Malla
Dr. Siva Malla 2012 年 5 月 31 日
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..

採用された回答

Walter Roberson
Walter Roberson 2012 年 5 月 31 日
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 件のコメント
Walter Roberson
Walter Roberson 2012 年 5 月 31 日
In any case, test double(f) not f itself.
Dr. Siva Malla
Dr. Siva Malla 2012 年 6 月 1 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeUtilities for the Solver についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by