Tuesday, November 18, 2014

Numerical :Curve Fitting

 

Numerical :Curve Fitting

sample input

 

T

700

720

740

760

V

0.0977

0.12184

0.1406

0.15509

 

#include<stdio.h>
int main()
{
    float y[50],x[50],sumx=0,X,xx,sumxx=0,sumy=0,sumxy=0,xsum,ysum,a1,a0;
    int n;
printf("Enter the Range :");
scanf("%d",&n);
//....................................
printf("ENTER x =\n");
for(int i=0;i<n;i++)
{
    scanf("%f",&x[i]);
    sumx=sumx+x[i];
    sumxx=sumxx+(x[i])*(x[i]);
}
xsum=(sumx/n);
//....................................
printf("ENTER y =\n");
 
for(int i=0;i<n;i++)
{
    scanf("%f",&y[i]);
    sumy=sumy+y[i];
}
ysum=(sumy/n);
//.....................................
for(int i=0;i<n;i++)
{
    sumxy=sumxy+x[i]*y[i];
}
//.....................................
a1=((n*sumxy)-(sumx*sumy))/((n*sumxx)-((sumx)*(sumx)));
printf("a1=%f",a1);
a0=((ysum)-(a1*xsum));
printf("\n\na0=%f",a0);
printf("\n NOw ENTER the value of X :");
 
printf("\nY=a0+a1X=");
scanf("%f",&X);
xx=a0+a1*X;
printf("\nANS= %f",xx);
 
return 0;
 
}

No comments:

Post a Comment