3rd degree polynomial interpolation in functions

16 views (last 30 days)
How can I find "y" at "x=28" with 3rd degree?
x y
0 0
10 0.2
15 0.5
20 0.9
22.5 1.2
25 1.6
30 2.2
35 3.1
40 4.1
45 5.2
50 6.5
75 13.9
100 24.9
150 58.3
200 97.6

Accepted Answer

Michael Madelaire
Michael Madelaire on 30 Dec 2018
Please do not send your data in like that. I have to copy it in some how and now it is just ugly...
% Define x
x = [0
10
15
20
22.5
25
30
35
40
45
50
75
100
150
200];
% Define y
y = [0
0.2
0.5
0.9
1.2
1.6
2.2
3.1
4.1
5.2
6.5
13.9
24.9
58.3
97.6
];
% Make fit
degree = 3;
fit = polyfit(x,y,degree);
x_fit = 0:0.01:200;
y_fit = polyval(fit, x_fit);
% Illustrate fit
figure;
plot(x,y);
hold on;
plot(x_fit, y_fit);
grid on;
xlabel('x');
ylabel('y');
legend('Data', 'Polyfit', 'Location', 'best');
title(sprintf('at x = 28 y is %.2f',polyval(fit,28)))

More Answers (0)

Categories

Find more on Polynomials 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!