Hello, this is my matlab script that is supposed to take data from an excel spread sheet and use it to create a y = mx+b function by linear regression. Here is my code and attached is the excel spread sheet. The first row is the amount in gallons and the next two rows are the amount of time it took to move the gallons in seconds.
points = xlsread('data.xlsx');
n = size(points,1);
sum_x = 0;
sum_y = 0;
sum_xy = 0;
sum_x2 = 0;
for i = i:n
sum_x = sum_x + points(i,2); sum_y = sum_y + points(i,3); sum_xy = sum_xy + points(i,2)*(points(i,3)); sum_x2 = sum_x2 + (points(i,2)^2);end
a1 = (n*sum_xy – sum_x*sum_y)/(n*sum_x2 – sum_x2);
a0 = (sum_y/n)-a_1*(sum_x/n);
y_new = a1*x + a_0;
THank you for your help.
Best Answer