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
int main(){ unsigned int i; vector
/* . . 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
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started