SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void test_linear(vector<int> x, vector<int> y) {
  2.     double sumX = 0, sumY = 0, sumXY = 0, sumXSq = 0, sumYSq = 0;
  3.     double a, b, n = x.size();
  4.  
  5.     for (int i = 0; i < x.size(); i++) {
  6.         sumX += x[i];
  7.         sumY += y[i];
  8.         sumXY += x[i] * y[i];
  9.         sumXSq += x[i] * x[i];
  10.         sumYSq += y[i] * y[i];
  11.     }
  12.  
  13.     a = (sumX * sumY - n * sumXY) / (sumX * sumX - n * sumXSq);
  14.     b = (sumX * sumXY - sumXSq * sumY) / (sumX * sumX - n * sumXSq);
  15.     cout << "a = " << a << ", b = " << b << "\n";
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top