Fitting a linear sine curve with polynomial curve

2 次查看(过去 30 天)
I don't have any data points. I have seen your past answers of fitting the sinusoidal function using pure Matlab functions. But those coefficients is for non-linear sinusoidal function. Can you assist me in fitting a linear sine curve between o and 2pi with the polynomial curve of power 4? I am a noobie at Matlab coding. Kindly assist for the same.

采纳的回答

Torsten
Torsten 2018-2-26
编辑:Torsten 2018-2-26
x=linspace(0,2*pi,100);
x=transpose(x);
A=[ones(numel(x),1),x,x.^2,x.^3,x.^4];
b=sin(x);
sol=A\b; % Polynomial is given by sol(1)+sol(2)*x+sol(3)*x^2+sol(4)*x^3+sol(5)*x^4
Best wishes
Torsten.
  4 个评论
Torsten
Torsten 2018-2-26
编辑:Torsten 2018-2-26
polynomial=sol(1)+sol(2)*x+sol(3)*x.^2+sol(4)*x.^3+sol(5)*x.^4;
plot(x,sin(x),x,polynomial,x,sin(x)-polynomial)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by