about if statement and solution
1 次查看(过去 30 天)
显示 更早的评论
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..
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!