MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Yunho Choi
on 27 Aug 2011

To use command 'solve',syms * * *.

After solve equation, i want plot. but it dosen't work

Conversion to double from sym is not possible

how to change dobule to sym...

or how to use solve without syms * * * only using double.

this is my code and answer. help me guys

syms x R2 R1;

[R2,x]=solve('a*(((1-R2)/(1-R1))+1)*x^2+((b+c)*(1-R2))*x+a*(((1-R2)/(1-R1))*R1+R2)=0','(b*((1-R2)/(1-R1))*R1-c*R2)*x^2+b*((1-R2)/(1-R1))-c=0','R2,x');

*No products are associated with this question.*

Answer by Walter Roberson
on 27 Aug 2011

Accepted answer

Are a, b, and c specific numeric values that are already defined in your workspace? When you use quoted strings for solve() the way you do, solve() does not know to fetch the values of the variables from the workspace and will treat the values as being symbolic.

If a, b, and c *do* have specific values, you could change your code to

[R2, x] = solve(a*(((1-R2)/(1-R1))+1)*x^2+((b+c)*(1-R2))*x+a*(((1-R2)/(1-R1))*R1+R2, (b*((1-R2)/(1-R1))*R1-c*R2)*x^2+b*((1-R2)/(1-R1))-c, R2, x);

Then the results returned would be symbolic only in terms of R1.

Because, though, they would contain a symbol, you would not be able to plot them directly. You could use subs() as Paulo suggests, but it might be easier to instead use

fR2 = matlabFunction(R2); fx = matlabFunction(x);

and then fR2 and fx would be function handles to functions of a single input, suitable for something like

r1vals = 0:.05:10; plot(r1vals, fR2(r1vals), 'r', r1vals, fx(r1vals), 'g');

Answer by Paulo Silva
on 27 Aug 2011

Your expressions R2 and x got several symbolic variables and because of that you can't convert it to double (by using double(expression)), you must replace those symbolic variables by double values and after it use double(R2) and double(x)

doc subs %see the documentation of the subs function

## 0 Comments