Disusun oleh :
Ilma Intan Sari (20117024)
Metode kuadrat diterapkan untuk mendekati solusi dari sistem overdetermined, yaitu sistem
persamaan di mana terdapat banyak persamaan yang belum diketahui. Kuadrat terkecil (least
square) sering diterapkan dalam konteks statistik, khususnya analisis regresi.
Tujuan dari Metode Kuadrat-adalah untuk menemukan estimasi parameter yang baik yang sesuai
dengan fungsi, M(x,t), dari suatu kumpulan data ( )( ) ( ) Metode Kuadrat-
Terkecil (Least-Squares Method) mensyaratkan bahwa fungsi yang diperkirakan menyimpang
sesedikit mungkin dari ( ). Secara umum, Metode Kuadrat-Terkecil memiliki dua kategori,
linear dan non-linear.
Metode kuadrat mengasumsikan bahwa kurfa yang cocok dan terbaikadalah kurva yang memiliki
jumlah kuadrat deviasi minimum (least square error) dari himpunan data.
( ) ∑( ( ))
Permasalahan;
( ) ∑( ( ))
a. Fittinglah data ( )
b. Tentukan nilai yang meminimumkan F(x) dengan metode Dogleg, Metode
Levenberg- Marquardt, dan Metode Quasi Newton. Gunakan tebakan awalnya
( )
0 0
0.5 0.213
0.25 0.3255
0.75 0.1051
0.125 0.2851
0.625 0.1526
0.375 0.2791
0.875 0.0704
0.0625 0.1887
0.5625 0.1814
0.3125 0.3076
0.8125 0.0863
0.1875 0.323
0.6875 0.1271
0.4375 0.2463
0.9375 0.0572
0.0313 0.1086
0.5313 0.1969
0.2813 0.3184
0.7813 0.0953
0.35
0.3
0.25
0.2
yi
0.15
0.1
0.05
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ti
b. Berikut Hasil Numerik dari 3 metode diatas
Nama Metode Nilai x yang meminimumkan F(x) Nilai F(x) Waktu iterasi
Metode Quasi (-4.0206, -4.9664, 3.9975,-3.9974) 0.0012 190.604319 seconds
Newton
Metode LM (-4.0000 , -5.0000, 4.0000 ,-4.0000) 2.3726 x 19.336083 seconds.
Metode Dogleg (-4.0000 , -5.0000, 4.0000 ,-4.0000) 6.0448 x 8.055959 seconds.
Berdasarkan tabel diatas dapat dilihat bahwa metode dogleng memiliki waktu iterasi
paling sedikit dibandingkan metode lainnya dalam mencari nilai x yang meminimumkan
F(x). dan dapat dilihat bahwa metode Quasi Newton membutuhkan waktu yang sangat
lama yaitu 190 detik , hal tersebut dikarenakan cara menentukan descent direction dalam
metode Quasi Newton masih kurang baik.
c. Plot grafik
( )
dengan segitiga warna biru
1. Plot Grafik Metode Quasi Newton
4
x 10
7
0
-10 -8 -6 -4 -2 0 2 4 6
2. Plot Grafik Metode Dogleg
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-14 -12 -10 -8 -6 -4 -2 0 2 4 6
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-8 -6 -4 -2 0 2 4
Lampiran
function [f,J, F]=fitexp(x,ty)
t=ty(:,1);
y=4*exp(t*(-4))+(-4)*exp(t*(-5))
figure (1);
plot(t,y,'b*');
grid on;
E=exp(t*[x(1),x(2)]);
f=y-E*[x(3);x(4)];
J=-[x(3)*t.*E(:,1), x(4)*t.*E(:,2),E];
n=length(f);
sumf=0;
for i=1:n
sumf=sumf+(f(i))^2;
end
sumf;
F=(1/2)*(sumf);
End
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%""" Metode Quasi-Newton """%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=0;
tic
x=[-1 -2 1 -1];
c=length(x);
ukuran=20;
p = qrandstream('sobol',1);
ty = rand(p,ukuran,1);
[f,J,F]=fitexp(x,ty);
g=(J')*f; B=eye(c);
eps1=10^-15; eps3=10^-15;
maxiter=200;
gradien=norm(g,inf)
min=F;
while gradien>eps1 && k<maxiter
k=k+1;
g=(J')*f;
delt=-B*g;
for c=0:0.1:1
xbaru=x+c*delt';
[fbaru,Jbaru,Fbaru]=fitexp(xbaru,ty);
if Fbaru<min
min=Fbaru;
alpha=c;
end
end
alpha
xbaru=x+alpha*delt';
[fbaru,Jbaru,Fbaru]=fitexp(xbaru,ty);
gbaru=(Jbaru')*fbaru;
s=xbaru-x;
y=gbaru-g;
B=B+((s'-B*y)*(s'-B*y)')/((s'-B*y)'*y);
min=Fbaru;
x=xbaru;
[f,J,F]=fitexp(x,ty);
gradien=norm(g,inf);
x
F
gradien
k
figure(2)
plot(x,F,'r*')
hold on
plot (x,norm(g),'b^')
end
toc
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%""" Metode Dog-Leg """%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=0; radius=1;
tic
x=[-1 -2 1 -1];
c=length(x);
ukuran=20;
p = qrandstream('sobol',1);
ty = rand(p,ukuran,1);
[f,J,F]=fitexp(x,ty);
g=(J')*f;
eps1=10^-15; eps3=10^-15;
found=(norm(f,inf)<=eps1) || (norm(g,inf)<=eps1);
maxiter=200;
while not(found) && k<maxiter
k=k+1;
hsd=-g;
alpha=-((hsd')*(J')*f)/norm(J*hsd)^2;
hgn=J\(-f);
a=alpha*hsd;
b=hgn;
c=(a')*(b-a);
if norm(hgn)<=radius
hdl=hgn;
elseif norm(alpha*hsd)>=radius
hdl=(radius/norm(hsd))*hsd;
else
if c<=0
beta=(-c+sqrt(c^2 + (norm(b-a))^2 *(radius^2 -
(norm(a))^2)))/(norm(b-a))^2;
else
beta=(radius^2 - (norm(a))^2)/(c+sqrt(c^2+(norm(b-a))^2
.*(radius^2 -(norm(a))^2)));
end
hdl=alpha*hsd+beta*(hgn-alpha*hsd);
end
if norm(hdl)<=eps1*(norm(x)+eps1)
found=true;
else
xnew=x+hdl';
[fnew,Jnew,Fnew]=fitexp(xnew,ty);
if hdl==hgn
L=F;
elseif hdl==(radius/norm(g))*(-g);
L=radius*(2*norm(alpha*g)-radius)/(2*alpha);
else
L=(1/2)*alpha*(1-beta)^2 *(norm(g))^2 + beta*(2-beta)*F;
end
rho=(F-Fnew)/L;
if rho>0
x=xnew; [f,J,F]=fitexp(x,ty);
g=(J')*f; found=(norm(f,inf)<=eps1) || (norm(g,inf)<=eps1);
end
if rho>0.75
radius=max(radius,3*norm(hdl));
elseif rho<0.25
radius=radius/2;
found=(radius<=eps1*(norm(x)+eps1));
end
end
x
F
g
figure(2)
plot(x,F,'r*')
hold on
plot (x,norm(g),'b^')
end
toc
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%""" Metode Levenberg- Marquardt """%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=0; v=2;
tic
x=[-1 -2 1 -1];
c=length(x);
ukuran=20;
p = qrandstream('sobol',1);
ty = rand(p,ukuran,1);
[f,J,F]=fitexp(x,ty);
A=(J')*J; g=(J')*f;
ukuranMatrixA=size(A);
eps1=10^-15; eps2=10^-15;
found=(norm(g,inf)<=eps1);
tau=10^-6;
aii=max(A);
miu=tau*max(aii);
maxiter=200;
while not(found) && k<maxiter
k=k+1;
hm=(A+miu*eye(ukuranMatrixA(1)))\(-g);
if norm(hm)<=eps2*(norm(x)+eps2)
found=true;
else
xnew=x+hm';
[fnew,Jnew,Fnew]=fitexp(xnew,ty);
L=(1/2)*(hm')*(miu*hm-g);
rho=(F-Fnew)/L;
if rho>0
x=xnew;
[f,J,F]=fitexp(x,ty);
A=(J')*J; g=(J')*f;
found=(norm(g,inf)<=eps1);
miu=miu*max((1/3),1-(2*rho-1)^3);
v=2;
else
miu=miu*v; v=2*v;
end
end
x
F
g
figure(2)
plot(x,F,'r*')
hold on
plot (x,norm(g),'b^')
end
toc