Using the solve function to solve for x in a quadratic
8 views (last 30 days)
Show older comments
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=
0 Comments
Accepted Answer
Walter Roberson
on 25 Jan 2012
double() will convert a symbolic number to a double precision value.
0 Comments
More Answers (2)
Titus Edelhofer
on 25 Jan 2012
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
Titus Edelhofer
on 25 Jan 2012
But if you want to use the symbolic computation:
y = solve(a0*x^2-(B/A-Delta)*x +n,x);
yNumeric = double(y)
Titus
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!