2010. 3. 9. 21:22

[MATLAB] Comparison of Euler's Method with Tustin's Method

clear all; clf
T = 0.5; End = 3;
k = 0:T:End;
t = 0:0.01:End;
y = zeros(1,length(k));
ytz = y;
for n = 1:length(k)-1
    y(n+1) = (1-T)*y(n) + T*1;
    ytz(n+1) = ( (2-T)*ytz(n) + 2*T )/(T+2);
end
yc = 1 - exp(-t);
plot(t,yc); hold on;
plot(k,y,'ro');
plot(k,ytz,'go');
legend('Continuous','Euler`s Method','Tustin`s Method','location','southeast');
title('Comparison of Euler`s Method with Tustin`s Method');

사용자 삽입 이미지