Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Program no

Name balwan dome


Roll no 14180
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

solution
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