Search & Find out

Thursday, December 3, 2009

STRAIGHT LINE CURVE FITTING

#include "stdio.h"
#include "conio.h"
#include "math.h"

void main ()
{
    int n,i;
    float a,la,b,x[50],y[50],x2[50],xy[50];
    float ex = 0,ey = 0,ex2 = 0,exy = 0;
    clrscr ();
    printf ("Straight line Curve Fitting:\n\n");
    printf ("\n-------------------------------------\n\n\n");
    printf ("Enter the number of values: ");
    scanf ("%d",&n);
    clrscr ();
    for (i=0; i
    {
        printf ("Enter X%d: ",i);
        scanf ("%f",&x[i]);
        printf ("Enter Y%d: ",i);
        scanf ("%f",&y[i]);
        printf ("\n");
    }
    for (i=0; i
    {
        x2[i]  = x[i] * x[i];
        xy[i]  = x[i] * y[i];
    }
    for (i=0; i
    {
        ex  += x[i];
        ey  += y[i];
        ex2 += x2[i];
        exy += xy[i];
    }
    b  = ((n * exy) - (ex * ey)) / ((n * ex2) - (ex * ex));
    a = (ey - (b * ex)) / n;
    clrscr ();
    printf ("Xi\t\tYi\t\t(Xi)2\t\t(Xi)(Yi)\n\n");
    for (i=0; i
    {
        printf ("%f\t",x[i]);
        printf ("%f\t",y[i]);
        printf ("%f\t",x2[i]);
        printf ("%f\n",xy[i]);
        printf ("\n");
    }
    printf ("\n-------------------------------------");
    printf ("\n\n\na = %f",a);
    printf ("\n\nb = %f",b);
getch ();
}



Download the executable (.exe)  file for this program..
download

0 comments:

Post a Comment

 

My Blog List

Term of Use