%name-priyanka nirwan %div='A' T3740 %--------------------------------------------------- clear all; clc; %------------------------------------------------------ n=input('enter the value of n='); for i=1:n; fprintf('enter the value of x(%d)',i); x(i)=input(''); fprintf('enter the value of y(%d)',i); y(i)=input(''); end %-------------------------------------------- s1=sum(x); s2=sum(x.^2); s3=sum(y); s4=sum(x.*y); %----------------------------------------- d=det([n,s1;s1,s2]); d1=det([s3,s1;s4,s2]); d2=det([n,s3;s1,s4]); c0=d1/d; c1=d2/d; yn=c0+c1*x; fprintf('the best fitted equation is, yn=%0.3f+%0.3f(x)\n',c0,c1); plot(x,y,'*--r',x,yn,'.--b'); xlabel('x axis'); ylabel('y axis'); title('curve fitting of 1st degree equation'); legend('normal curve','smooth curve'); %- -------------------------------------------------