From symbolic to numerical results for quadratic equation
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
KSSV
2021-6-17
Read about subs. Did you define the values of those coefficients? Show us the full code which you tried.
采纳的回答
Stephan
2021-6-17
编辑:Stephan
2021-6-17
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Values 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!