Senin, 12 Oktober 2015

Source code MATLAB metode Euler Eksplisit

%Metode Euler Eksplisit
%dy/dt=f(t,y)
%f(t,y)=-(y+1)*(y+3);
clear all;
dt=0.01;
t=0:dt:2;
N=length(t)-1;
y=zeros(N+1,1);

y(1)=-2;
y_eks(1)=-2;
err(1)=0;
for n=1:N
    y(n+1)=y(n)+dt*(-(y(n)+1)*(y(n)+3));%solusi Euler eksplisit
    y_eks(n+1)=-3+2/(1+exp(-2*t(n+1)));%solusi eksak
    err(n+1)=abs(y(n+1)-y_eks(n+1));%kesalahan mutlak
end;
figure(1)
plot(t,y,'ko',t,y_eks,'r');
figure(2);%hold on
plot(t,err);

Tidak ada komentar:

Posting Komentar