Content-Length: 3092765 | pFad | https://www.scribd.com/doc/52060192/multi-reg

4 Multi Reg | PDF | Mathematics | Multivariate Statistics
0% found this document useful (0 votes)
39 views6 pages

Multi Reg

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

Ex.No.

11
29.03.2011

Multi Linear Regression Line of Given Points

Aim :
To write a program in C language for Multi linear regression line of given
points.

C Program:
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main ()
{
int i,j,m,n,k,c, nv;
float x[20][20],y[20],a[20][20],b,sum,u[20],ratio,Sr,St,r2,y1,d;
printf("\n\tMultiple Linear Regression Line of Given Points \n");
printf("\nEnter no. of inputs availabe :") ;

scanf("%d",&m);
printf("\n Enter no. of independent variables :") ;
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter x[%d] values :\n",i+1);
for(j=0;j<m;j++)
{
printf("x[%d][%d] :",j,i);
scanf("%f",&x[j][i]);
}
}
printf("\nEnter y values :\n");
for(i=0;i<m;i++)
{
printf("y[%d] :",i);
scanf("%f",&y[i]);
}

for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{

if((i==0)&&(j==0))
a[i][j]= m;
else
{sum=0;
for(k=0;k<m;k++)
{
if((i==0)||(j==0))
{
b=1;
}
else
{
b=x[k][i-1];
}
if(i>j)
a[i][j]=a[j][i];
else
{
c=j-1;
sum=sum+((x[k][c])*b);
}
a[i][j]=sum;
}
}
}
}
printf("\nThe Coefficient matrix-1 is,");
for(i=0;i<=n;i++)
{
printf("\n");
for(j=0;j<=n;j++)
{
if(i>j)
a[i][j]=a[j][i];
printf("\t%.2f",a[i][j]);
}
}

printf("\nThe Coefficient matrix-2 is,");


sum=0;
for(i=0;i<m;i++)
{
sum+=y[i];
}
a[0][n+1]=sum;
printf("\n%0.2f",sum);
y1=sum/m;

for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<m;j++)
{
sum+=x[j][i]*y[j];
}
a[i+1][n+1]=sum;
printf("\n%0.2f",sum);
}

nv=n+1;
for (j=0;j<nv-1;j++)
{
for (i=j+1;i<nv;i++)
{
ratio=(a[i][j]/a[j][j]);
for (k=0;k<nv+1;k++)
{
a[i][k] =a[i][k]-(a[j][k]*ratio);
}
}
}
for(i=0;i<nv;i++)
u[i]=a[i][nv];
for(i=0;i<nv;i++)
u[i]=a[i][nv];
for(i=nv-1;i>=0;i--)
{
for(j=i+1;j<nv;j++)
u[i]=u[i]-(a[i][j]*u[j]);
u[i]=u[i]/a[i][i];
}
printf("\nThe Coefficients of polynomial are,");
for(i=0;i<=n;i++)
printf("\na[%d]= %f",i,u[i]);

sum=0;
for(j=0;j<m;j++)
{

for(i=1;i<=n;i++)
{
sum+=u[i]*x[j][i-1];
}

}
d=sum;

sum=0;
for(i=0;i<m;i++)
{
sum+=y[i]-u[0];

}
Sr=pow((sum-d),2);
printf("\n\nSr : %.3f",Sr);

sum=0;
for(j=0;j<m;j++)
{
sum+=pow((y[j]-y1),2);
}
St=sum;
printf("\nSt : %.3f",St);
r2=(St-Sr)/St;
printf("\n\nCoefficient of determination : %.3f",r2);
getch();
}
Result:
The program was executed and printed.

Sample Output:

Multiple Linear Regression Line of Given Points

Enter no. of inputs availabe :6

Enter no. of independent variables :2

Enter x[1] values :


x[0][0] :0
x[1][0] :2
x[2][0] :2.5
x[3][0] :1
x[4][0] :4
x[5][0] :7

Enter x[2] values :


x[0][1] :0
x[1][1] :1
x[2][1] :2
x[3][1] :3
x[4][1] :6
x[5][1] :2

Enter y values :
y[0] :5
y[1] :10
y[2] :9
y[3] :0
y[4] :3
y[5] :27

The Coefficient matrix-1 is,


6.00 16.50 14.00
16.50 76.25 48.00
14.00 48.00 54.00

The Coefficient matrix-2 is,


54.00
243.50
100.00

The Coefficients of polynomial are,


a[0]= 5.000000
a[1]= 4.000000
a[2]= -3.000000

Sr : 0.000
St : 458.000

Coefficient of determination : 1.000

You might also like









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.scribd.com/doc/52060192/multi-reg

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy