about if statement and solution
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 31 May 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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!