You are on page 1of 2

Name: Aditya Kumar

Roll no.: 3914

Group: A+B

Scilab Code 6

Aim: Least Square fitting of data points in a


parabola
clc
clear

x=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
y=[0.33,0.70,1.30,1.90,2.42,3.41,4.02,4.99,5.98,6.95]
$x=0
$y=0
$xy=0
$x2=0
n=length(x)
m=length(y)
if n~=m then
disp("Dimensions of x and y are not same, ABORTING PROGRAM !")
end
$x=sum(x)
$y=sum(y)
$xy=sum(x.*y)
$x2=sum(x^2)
$x3=sum(x^3)
$x4=sum(x^4)
$x2y=sum((x^2).*y)
v=[$x4 $x3 $x2; $x3 $x2 $x; $x2 $x n]
w=[$x2y; $xy; $y]
r=inv(v)*w
disp(r)
c=r(1)
d=r(2)
e=r(3)
disp('The least square fitting curve is= '+string(c)+'*x'+string(d))
plot(x,y,'or')
y=c*(x^2)+d*(x)+e
plot(x,y)
legend(['Data points','Least square fitted curve'])
xtitle('LEAST SQUARE FITTING:PARABOLA','x-axis','y-axis')
Output:

You might also like