Program:-15
/* Polynmial Regresion */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
float *x,*y,n,i,x1=0,x12=0,y1=0,x1y1=0,a1,a0,e;
printf("How many values You are Entering");
scanf("%f",&n);
x=(float*)malloc(n*4);
y=(float*)malloc(n*4);
puts("Enter coressponding Elements X & Y");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i]);
x1+=x[i];
y1+=y[i];
x1y1+=(x[i]*y[i]);
x12+=(x[i]*x[i]);
}
a1=(n*x1y1-x1*y1)/(n*x12-x1*x1);
a0=y1/n-a1*x1/n;
e=y[0]-a0-a1*x[0];
printf("ao=%f\na1=%f\ne%f",a0,a1,e);
}
Output of Program:-
How many values You are Entering
6
Enter coressponding Elements X & Y
0 2.1
1 7.7
2 13.6
3 27.2
4 40.4
5 61.1
Matrix
6.000000 15.000000 55.000000 152.100006
15.000000 55.000000 225.000000 583.599976
55.000000 225.000000 979.000000 2480.800049
Required Equation
Y=4.632166+2.271759X+1.869648X2
No comments:
Post a Comment