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

Search This Blog

Polynomial Regression MATLAB Animation

Prerequisite:

https://www.matlabcoding.com/2020/02/polynomial-regression-in-matlab.html

Code:

clc
clear all
close all
figure;
grid on;
axis([1 10 -100000 10*10^5]);
pause(5);
for a=1:6
clf
x=[1 2 3 4 5 6 7 8 9 10];
y=[45000 50000 60000 80000 110000 150000 200000 300000 500000 1000000];
plot(x,y,'o','linewidth',5);
axis([1 10 -100000 10*10^5]);
hold on;
grid on;
pause(1);
coeff=polyfit(x,y,a);
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,'r','linewidth',3);
axis([1 10 -100000 10*10^5]);
grid on;
pause(1.5);
end

No comments

Popular Posts

Followers