3rd degree polynomial interpolation in functions
16 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Michael Madelaire
2018-12-30
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)))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!