From symbolic to numerical results for quadratic equation
조회 수: 3 (최근 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!