2010. 3. 9. 14:19

[MATLAB] Euler's Method second order case

\begin{align*} y'' + 2y' + y = \sin (t),\quad y(0) = 0,\quad y'(0) = 0 \end{align*}


clear all;
T = 0.2;
n = 0:T:8;
y = zeros(1,length(n));

for k = 1:length(y)-2
    y(k+2) = (2-2*T)*y(k+1) + (2*T-1-T^2)*y(k) + T^2*sin(k*T);
end

num = 1;
den = conv([1 2 1],[1 0 1]);
impulse(num,den); hold on;
axis([0 8 -1 1]); grid on;
plot(n,y,'o')

사용자 삽입 이미지사용자 삽입 이미지