Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, Calculate the best fit line from a list of 10 points. With Input: x and y where x and y are the vectors

In C++, Calculate the best fit line from a list of 10 points.

With Input: x and y where x and y are the vectors of type double

1.0 6.0 2.0 9.0 3.0 12.0 4.0 15.0 5.0 18.0 6.0 21.0 7.0 24.0 8.0 27.0 9.0 30.0 10.0 33.0

Output:

sX=55.00 (Sum of all x's) sY=195.00 (Sum of all y's) sXX=385.00 (Sum of all x's power squared) sXY=1320.00 (Sum of all product of x and y) sYY=4545.00 (Sum of all y's power squared) a=3.00 b=3.00

Example,

#include #include #include #include #include //use setprecision(n) using namespace std;

int main(){ unsigned int i; vector x(10); double sX; for(i=0; i> x.at(i); sX = (x.at(0) + x.at(1)) + (x.at(2)+ x.at(3))+ (x.at(4) + x.at(5)) + (x.at(6)+ x.at(7)) + (x.at(8)+ x.at(9)); cout << sX; }

/* . . b = [Sum of product of x and y - (Sum of x's * Sum of y's)/no. of elements in x ] / [Sum of all x's power squared - (Sum of x's power squared/no. of elements in x)]

a = [1.0/no. of elements in x] * Sum of all y's - b*[1.0/no. of elements in x] * Sum of all x's */ return 0; }

Please write code in C++, thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago