///Curve fitting of a straight line of the form y = a + bx
#include<stdio.h>#include<math.h>int main(){
int ax[20], ay[20], i, n;
int sum_x = 0, sum_xy = 0, sum_x2 = 0, sum_y = 0 ;
float a , b;
printf("Enter no of records: ");scanf("%d", &n);printf("Enter Data: ");printf("\nX Y\n");for(i = 0; i < n; i++){
scanf("%d%d", &ax[i], &ay[i]);}for(i = 0; i < n; i++){
sum_x += ax[i];sum_y += ay[i];sum_xy += ax[i] * ay[i];sum_x2 += pow(ax[i], 2);
}b = (n*sum_xy - sum_x*sum_y)/(n*sum_x2 - pow(sum_x,2));
a = (sum_y - b*sum_x)/n;printf("\na = %.3f b = %.3f", a, b);printf("\nThe Equation is %.3f + %.3fX\n\n", a, b);return 0;
}
Java Strut,hibernate tutorial,best java example with source code,android tutorial,android interview question,iPhone all example,all c languages example,c languages project with source code,iPhone and android project free download.
Wednesday, 13 February 2013
Numerical Methods:Fitting the curve of the form y = a + bx using least square method in C
Labels:
Numerical Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Comment