Saturday, 8 March 2014

PROGRAM TO IMPLEMENT CURVE FITTING

/* CSEMATTER.BLOGSPOT.IN
PROGRAM TO IMPLEMENT CURVE FITTING*/

#include<stdio.h>
#include<conio.h>
void main()
{float ag[3][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0}};
float a,b,c,x,y,xsg,t;
int i,j,k,n;
printf("enter the no. of pairs of observed values");
scanf("%d",&n);
ag[0][0]=n;
for(i=0;i<n;i++)
{
scanf("%f %f",&x,&y);
xsg=x+x;
ag[0][1]+=x;
ag[0][2]+=xsg;
ag[1][2]+=x*xsg;
ag[2][2]+=x*xsg*xsg;
ag[0][3]+=y;
ag[1][3]+=x*y;
ag[2][3]+=xsg*y;
ag[1][0]=ag[0][2];
ag[2][1]=ag[1][2];
ag[1][0]=ag[0][1];
ag[2][0]=ag[1][1];
for(j=0;j<3;j++)
for(i=0;i<3;i++)
if(i!=j)
{t=ag[i][j]/ag[j][i];
for(k=0;k<4;k++)
ag[i][k]-=ag[j][k]*t;}
a=ag[0][3]/ag[0][1];
b=ag[1][3]/ag[1][1];
c=ag[2][3]/ag[2][2];
printf("a=%f ,b=%f ,c=%f",a,b,c);
}

/*OUTPUT
Enter the no. of pairs of observed values 7
1.0  1.1
1.5  1.3
2.0  1.6
2.5  2.0
3.0  2.7
3.5  3.4
4.0  4.1
a=1.035712 b=-0.192972 c=0.242981
*/








No comments:

Post a Comment