How to solve a quadratic equation coefficient a, b, c given 3 points
조회 수: 6 (최근 30일)
이전 댓글 표시
How can I solve for a quadratic equation's coefficients a, b, c of the form: y(x) = ax2 + bx +c? Given: y(0) = 1 y(200) = 0.5 y(500) = 0.2
Need simple Matlab code, no other tools. Thank you.
댓글 수: 0
답변 (1개)
Star Strider
2016년 4월 17일
This is a linear equation (linear in the parameters), so you can use the mldivide,\ operator:
x = [0; 200; 500];
y = [1; 0.5; 2.0];
parms = [x.^2 x ones(size(x))]\y
xv = linspace(min(x), max(x))';
y_fit = [xv.^2 xv ones(size(xv))]*parms;
figure(1)
plot(x, y, 'bp')
hold on
plot(xv, y_fit, '-r')
hold off
grid
text(75, 1.5, sprintf('y(x) = %8.3E\\cdotx^2 - %8.3E\\cdotx + %8.3E', abs(parms)))
You can also use the polyfit function.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!