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

DI No.

:
Dr D Y PatilPratishthan’s
Dr. D. Y. Patil Institute of Engineering, Management and ACAD/DI/
Research, Akurdi, Pune
Academic Year: Practical-7 Revision : 00
2022-2023 (Group B) Dated :
Date of Preparation :
Term –I Department of Mechanical Engineering

Name of
Student Gurudatta Ghode
Roll Call
21214
Program Name Program on Curve Fitting using Least Square technique-Straight Line, Power Function,
Exponential Function

Question  Complete the curve fitting using SCi lab

Code
//Polynomial Fitting
//To fit a given set of data points to an n-degree polynomial
//Written By: Manas Sharma (www.bragitoff.com)
funcprot(0);
function A=npolyfit(x,y,n)
format(6);
N=size(x);
if N(2)>N(1) then
N=N(2)
else
N=N(1);
end
X(1)=N;
for i=1:2*n
X(i+1)=0;
for j=1:N
X(i+1)=X(i+1)+x(j)^i;
end
end
for i=1:n+1
for j=1:n+1
B(i,j)=X(i+j-1)
end
end
disp(B);
for i=0:n
C(i+1)=0;
for j=1:N
C(i+1)=C(i+1)+(x(j)^i)*y(j);
end
end
C=-C;
disp(C);
A=linsolve(B,C);
endfunction

Output
a =0.000– 0.0000.0001.

Output Graphs

You might also like