Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Example problem on Polynomial Regression | MATLAB

Code:

clc
clear all
close all
x=[0 1 2 3 4 5];
y=[71 76 86 100 118 140];
a=2;
coeff=polyfit(x,y,a);
disp(coeff);
t=min(x):0.01:max(x);
c=0;
temp=a;
z=[];
for i=1:length(t)
t1=t(i);
for j=1:length(coeff)
c=c+coeff(j)*(t1^temp);
temp=temp-1;
end
temp=a;
z=[z c];
c=0;
end
plot(t,z);
hold on;
plot(x,y,'o');
grid on;

No comments

Popular Posts