8. (C) Program for multiple linear regression.

8. (C) Program for multiple linear regression.

x1=[0,2.2,2.5,1,4,7];
x2=[0,1,2,3,6,2];
x1sum=0;
x2sum=0;
ysum=0;
x12sum=0;
x22sum=0;
x1ysum=0;
x2ysum=0;
x1x2sum=0;
n=6;
for i=1:6
y(i)=5+4*x1(i)-3*x2(i);
x12(i)=x1(i)^2;
x22(i)=x2(i)^2;
x1x2(i)=x1(i)*x2(i);
x1y(i)=x1(i)*y(i);
x2y(i)=x2(i)*y(i);
x1sum=x1sum+x1(i);
x2sum=x2sum+x2(i);
ysum=ysum+y(i);
x1ysum=x1ysum+x1y(i);
x2ysum=x2ysum+x2y(i);
x1x2sum=x1x2sum+x1x2(i);
x12sum=x12sum+x12(i);
x22sum=x22sum+x22(i);
end
X=[n,x1sum,x2sum;x1sum,x12sum,x1x2sum;x2sum,x1x2sum,x22sum];
Y=[ysum;x1ysum;x2ysum];
Z=inv(X)*Y;
a0=det(Z(1,1));
a1=det(Z(2,1));
a2=det(Z(3,1));
disp(a0,"a0=")
disp(a1,"a1=")
disp(a2,"a2=")
disp("Thus,y=a0+a1*x1+a2*x2")
8. (C) Program for multiple linear regression. 8. (C) Program for multiple linear regression. Reviewed by admin on December 24, 2019 Rating: 5

No comments:

Powered by Blogger.