In [52]:
using PyPlot
using Interact
In [53]:
T = 50.
function forward_euler_integrate(N::Int,T::Float64)
    y = zeros(2,N+1)
    h = T/N
    A = [-0.01 1; -1 -0.01]
    y[:,1] = [0.;1.]
    for i=1:N
        y[:,i+1]= y[:,i] + h*A*y[:,i]
    end
    return h, y
end
#forward_euler_integrate(5,5.)
f=figure();
@manipulate for N=2000:2800; withfig(f) do
        h, y = forward_euler_integrate(N, T)
        PyPlot.plot(collect(0:h:T), y')
    end
end
Out[53]:
In [54]:
T = 50.
function forward_euler_integrate(N::Int,T::Float64)
    y = zeros(2,N+1)
    h = T/N
    A = [-0.01 1; -1 -0.01]
    y[:,1] = [0.;1.]
    for i=1:N
        y[:,i+1]= y[:,i] + h*A*y[:,i]
    end
    return h, y
end
#forward_euler_integrate(5,5.)
f=figure();
@manipulate for N=2000:2800; withfig(f) do
        h, y = forward_euler_integrate(N, T)
        PyPlot.plot(collect(0:h:T), sum(y.^2,1)')
    end
end
Out[54]:
In [50]:
A = [-0.01 1; -1 -0.01]
@show abs(eigvals(eye(2)+(50./2501)*A))
abs(eigvals(eye(2) + (50 ./ 2501) * A)) = [0.9999999400479694,0.9999999400479694]
Out[50]:
2-element Array{Float64,1}:
 1.0
 1.0