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!