How to solve a quadratic equation coefficient a, b, c given 3 points
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 17 Apr 2016
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 Comments
See Also
Categories
Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!