Anda di halaman 1dari 4

Table of Contents

........................................................................................................................................ 1
Data .................................................................................................................................. 1
PD .................................................................................................................................... 1
Initial value ........................................................................................................................ 1
Fungsi yang akan dioptimalkan ............................................................................................. 1
Plot ................................................................................................................................... 2

function Tugas5

Data
clc;clear
AData = [0.0154 0.01422 0.01335 0.01232 0.01181 0.01139 0.01092
0.01054...
0.00978 0.009157 0.008594 0.008395 0.007891 0.00751 0.00737
0.006646...
0.005833 0.005322 0.00496 0.004518 0.004075 0.003715]';
tData = [4.5 8.67 12.67 17.75 22.67 27.08 32 36 46.33 57 69 76.75...
90 102 108 147.92 198 241.75 270.25 326.25 418 501]';

PD
ktrial = rand(1,3);
k1 = ktrial(1,1); k2 = ktrial(1,2); k3 = ktrial(1,3);
function dY = fun1(t,Y)
dY = zeros(5,1);
dY(1) = -k1*Y(1)*Y(2)-k2*Y(1)*Y(3)-k3*Y(1)*Y(4);
dY(2) = -k1*Y(1)*Y(2);
dY(3) = k1*Y(1)*Y(2)-k2*Y(1)*Y(3);
dY(4) = k2*Y(1)*Y(3)-k3*Y(1)*Y(4);
dY(5) = k3*Y(1)*Y(4);
end

Initial value
A0 = 0.02090;
B0 = A0/3;
C0 = 0;
D0 = 0;
E0 = 0;

Fungsi yang akan dioptimalkan


function SSE = fun2(ktrial)

1
k1 = ktrial(1,1); k2 = ktrial(1,2); k3 = ktrial(1,3);
[t Y]=ode45(@fun1,tData,[A0 B0 C0 D0 E0]);
Ahit = Y(:,1);
SE = (AData-Ahit).^2;
SSE = sum(SE);
end

[k fval] = fminsearch(@fun2,ktrial);

Plot
figure(1)
plot(t,AData,t,Ahit,'o')
xlabel('Waktu, detik')
ylabel('Konsentrasi A')
legend('Data','Perhitungan')
title('Perbandingan Konsentrasi A Perhitungan dan Data terhadap
Waktu')
grid on

figure(2)
plot(t,Y)
xlabel('Waktu, detik')
ylabel('Konsentrasi')
title('Profil Konsentrasi Tiap Komponen terhadap Waktu')
legend('Konsentrasi A','Konsentrasi B','Konsentrasi C','Konsentrasi
D',...
'Konsentrasi E')
axis tight
grid on

fprintf('Nilai k1 adalah %2.2f, k2 adalah %2.2f, dan k3 adalah %2.2f.


\n',k)

Nilai k1 adalah 30.52, k2 adalah 1.69, dan k3 adalah 0.28.

2
3
end

Published with MATLAB R2015b