From symbolic to numerical results for quadratic equation
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
laura bagnale
le 17 Juin 2021
Modifié(e) : Walter Roberson
le 19 Juin 2021
Hello everyone,
I hope someone could help me, I'm starting using the symbolic toolbox but I have some difficulties.
I wrote this quadratic equation in symbolic form:
syms x y a1 b1 c1 d1 e1 f1
a = d1*y^2 + (e1 + b1*x)*y + a1*x^2 + c1*x + f1
then I tried to solve it:
ht=matlabFunction(a)
eqn = d1.*y.^2+(e1+b1.*x).*y+(a1.*x.^2+c1.*x+f1) == 0
S = solve(eqn, y)
I got what I expected from the formula
[-(e1 + b1*x - sqrt(b1^2*x^2 + 2*b1*e1*x + e1^2 - 4*a1*d1*x^2 - 4*c1*d1*x - 4*d1*f1))/(2*d1); -(e1 + b1*x + sqrt(b1^2*x^2 + 2*b1*e1*x + e1^2 - 4*a1*d1*x^2 - 4*c1*d1*x - 4*d1*f1))/(2*d1)]
However I don't know how to get the numerical real solutions.
I know the numerical values for the coeffcients a1, b1, c1, d1, e1, f1.
I tried to write the equation in this way:
syms x y
a = d1*y^2 + (e1 + b1*x)*y + a1*x^2 + c1*x + f1
ht=matlabFunction(a)
eqn = d1.*y.^2+(e1+b1.*x).*y+(a1.*x.^2+c1.*x+f1) == 0
S = solve(eqn, y, 'Real', true)
but the formula appears in the same form, with numbers in the places of the coefficients but with no solutions.
Can someone help me please.
Thank you very much in advance.
Laura
2 commentaires
KSSV
le 17 Juin 2021
Read about subs. Did you define the values of those coefficients? Show us the full code which you tried.
laura bagnale
le 17 Juin 2021
Modifié(e) : Walter Roberson
le 19 Juin 2021
Réponse acceptée
Stephan
le 17 Juin 2021
Modifié(e) : Stephan
le 17 Juin 2021
You could use symbolic functions:
syms y(a,b,x)
y(a,b,x) = a*x^2 - b*x
% Calculate values for a=1, b=2 and x in a range from 1:4 with stepwide 0.5
result_symbolic = y(1,2,1:0.5:4)
if you want that numbers (still symbolic) use double
result_numeric = double(result_symbolic)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Special Values dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!