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=

 채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 25일

0 개 추천

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

추가 답변 (2개)

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

댓글 수: 1

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
Damian Duffy 2012년 1월 25일

0 개 추천

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!

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by