///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;}

## Sunday, September 18, 2011

### Numerical Methods:Fitting the curve of the form y = a + bx using least square method in C

### About Author

**Bibek Subedi** is a computer engineering gratuate and founder of Programing Techniques. He loves researching in the field of Machine learning, data mining and Algorithms. He is a part time blogger, a bathroom singer (:D) and an employee of a software company. You can follow him in Twitter and find him in Facebook or mail him

Subscribe to:
Post Comments (Atom)

## No comments:

## Post a Comment