#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int n, i, xi[20], yi[20];
double sum1 = 0, sumpowx = 0, sum2 = 0, msum = 0, z, y;
double b, a;
cout << "Enter how many values you want? : " ;
cin >> n;
for(i=1;i<= n;i++)
{
cout << "Enter value of xi's : " ;
cin >> xi[i];
sum1 = sum1 + xi[i];
z = pow(xi[i],2);
sumpowx = sumpowx + z;
}
for(i=1; i<=n;i++)
{
cout << "Enter value of yi's: ";
cin >> yi[i];
sum2 = sum2 + yi[i];
}
for(i=1;i<=n;i++)
{
msum = (xi[i] * yi[i]) + msum;
}
cout << endl << endl <<"Summation xi = " << sum1 << endl << "Summation yi = " << sum2 << endl;
cout << "Summation Square of xi = " << sumpowx << endl << "Summation xi * yi = " << msum << endl;
b = (n * msum - (sum1 * sum2))/ (n * sumpowx) - ((sum1) * ( sum1));
a = (sum2 / n)- ((n * msum - (sum1 * sum2))/ (n * sumpowx) - ((sum1) * ( sum1)))*(sum1 /n);
cout << "The required line is Y = "<<a <<" + " <<b <<" x";
getch();
return 0;
}
These codes are tested in Dev C++ and are error free. If any error occurs, comment below. Other programs will be uploaded as soon as possible.
Thank you! :)
Friday, April 15, 2016
Least Square Regression [Program]
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
If you have any problem, please leave your message here.