CLICK ABOVE TO DOWNLOAD ALL PROGRAMS
curve fitting:
- Code:
# include
# include
# include
# include
void main()
{
int n,i,j;
float x[10],y[10],sumx=0,sumy=0,sumx2=0,sumxy=0,a,b,x0,fx;
clrscr();
printf("\nEnter the no of points:");
scanf("%d",&n);
printf("\nEnter the points(x,y):\n");
for(i=0;i
scanf("%f,%f",&x[i],&y[i]);
for(i=0;i
{
sumx+=x[i];
sumx2+=x[i]*x[i];
sumy+=y[i];
sumxy+=x[i]*y[i];
}
printf("\nsumx=%f\tsumx2=%f\tsumy=%f\tsumxy=%f\n",sumx,sumx2,sumy,sumxy);
a=(n*sumxy-sumx*sumy)/(n*sumx2-sumx*sumx);
b=(sumy*sumx2-sumx*sumxy)/(n*sumx2-sumx*sumx);
printf("The coefficients are a=%f\t b=%f\n",a,b);
printf("\nEnter the point x:");
scanf("%f",&x0);
fx=a*x0+b;
printf("\nf(%f)=%f",x0,fx);
getch();
}
Last edited by Formatted on 1st September 2009, 9:14 pm; edited 19 times in total