0% found this document useful (0 votes)
13 views

'/N Enter The No of Data Points' '/N Enter The Value of X Row Wise:' '/N Enter The Value of y Row Wise:'

The document contains a MATLAB function that calculates the linear regression line from a set of x and y data points input by the user. The function sums the x and y values, calculates the sums of squares and cross-products, and uses these to determine the slope and y-intercept of the best fit line through the least squares method. It then prints the linear regression equation.

Uploaded by

Onkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

'/N Enter The No of Data Points' '/N Enter The Value of X Row Wise:' '/N Enter The Value of y Row Wise:'

The document contains a MATLAB function that calculates the linear regression line from a set of x and y data points input by the user. The function sums the x and y values, calculates the sums of squares and cross-products, and uses these to determine the slope and y-intercept of the best fit line through the least squares method. It then prints the linear regression equation.

Uploaded by

Onkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

function st_line()

clc
n=input('\n enter the no of data points');
for i=1:n
x(i)=input('\n enter the value of x row wise:');
y(i)=input('\n enter the value of y row wise:');
end
sx=0;
sy=0;
sxy=0;
sxx=0;
for i=1:n
sx=sx+x(i);
sy=sy+y(i);
sxy=sxy+x(i)*y(i);
sxx=sxx+x(i)*x(i);
end
ds=(sx*sx-n*sxx);
da=(sy*sx-n*sxy);
db=(sx*sxy-sxx*sy);
a=da/ds;
b=db/ds;
fprintf('\ny=(%f)*x=(%f)',a,b);
end

enter the no of data points7

enter the value of x row wise:1

enter the value of y row wise:0.5

enter the value of x row wise:2

enter the value of y row wise:2.5

enter the value of x row wise:3

enter the value of y row wise:2.0

enter the value of x row wise:4

enter the value of y row wise:4

enter the value of x row wise:5

enter the value of y row wise:3.5

enter the value of x row wise:6

enter the value of y row wise:6.0

enter the value of x row wise:7

enter the value of y row wise:5.5

y=(0.839286)*x=(0.071429)>>

You might also like