Info

This question is closed. Reopen it to edit or answer.

Please help me with this code ??

1 view (last 30 days)
dipin nair
dipin nair on 20 Dec 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
This code contains syms and when I run showing error If the input expression contains a symbolic variable, use the VPA function instead. I tried not working .Please suggest me a solution test_syms.m

Answers (1)

John D'Errico
John D'Errico on 20 Dec 2015
Edited: John D'Errico on 20 Dec 2015
syms x y
a=1;
b=3;
x=solve(a*x^2+b*x+y == 0,x)
x =
- (9 - 4*y)^(1/2)/2 - 3/2
(9 - 4*y)^(½)/2 - 3/2
I've chanced your code only slightly, assuming you wish to solve for x, as a function if y, with a and b known constants. When you passed the equation into solve using quotes around it, the symbolic toolbox does not use those values you have set for a and b. Nor does it need you to define the variables explicitly.
And of course roots will of course not work with a symbolic variable inside.
Now, you wish to create a matrix from the solutions in x. There is no need to use loops. And certainly you can write it directly.
A = [x,x.^2].'
A =
[ - (9 - 4*y)^(1/2)/2 - 3/2, (9 - 4*y)^(1/2)/2 - 3/2]
[ ((9 - 4*y)^(½)/2 + 3/2)^2, ((9 - 4*y)^(1/2)/2 - 3/2)^2]
The non-conjugate transpose (.') at the end was due to x being a column vector as it was created.

Community Treasure Hunt

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

Start Hunting!