Using the solve function to solve for x in a quadratic

Hi,
I'm having a few problems using the solve function to solve my quadratic equation.
It's quite basic but still causing problems for me.
This is my code:
syms x positive
B=13.69515; A=1.01; Delta=7.425 n=354.375; a0=-0.01660;
solve(a0*x^2-(B/A-Delta)*x +n,x);
When this is run it returns:
ans =
(75*2^(1/2)*346625777^(1/2))/8383 - 1548975/8383
which is fine but I need the single value answer, not that string type answer.
For example, if I say,
Q=(75*2^(1/2)*346625777^(1/2))/8383 - 1548975/8383
I get the answer I need which is 50.7873
How I get this single answer first time around without getting that string. I'm sure it is something simple but I'm a bit of a novice so I'm unsure.
Thanks for any help!
A=

 Accepted Answer

double() will convert a symbolic number to a double precision value.

More Answers (2)

Hi,
why do you then compute symbolically?
x = roots([a0 -(B/A-Delta) n]);
xpos = x(x>0)
gives you 50.7873.
Titus

1 Comment

But if you want to use the symbolic computation:
y = solve(a0*x^2-(B/A-Delta)*x +n,x);
yNumeric = double(y)
Titus

Sign in to comment.

Thank you both for your answers. It's definitely cleared it up for me. I'm very unfamiliar with the symbolic toolbox.
For a case in which the values for B,A,Delta and n change at every iteration, is it straightforward to set up using symbolic computation?
Walter,I saw an answer you provided on this:
syms x y z xin = input('x ='); yin = input('y ='); zsol = solve('z-y=x', z); disp(['z = ' char(zsol)]); znum = double(subs(zsol, {x, y}, {xin, yin})); disp(['z = ' num2str(znum)]);
Would a similar solution be applicable for my example?
Thanks again!

Community Treasure Hunt

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

Start Hunting!