Using the solve function to solve for x in a quadratic
Afficher commentaires plus anciens
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=
Réponse acceptée
Plus de réponses (2)
Titus Edelhofer
le 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 commentaire
Titus Edelhofer
le 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
Damian Duffy
le 25 Jan 2012
0 votes
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!