In [1]:
using PyPlot
using Blink,Interact

Unable to load WebIO. Please make sure WebIO works for your Jupyter client. For troubleshooting, please see the WebIO/IJulia documentation.

Look at the ODE $$ \frac{dy}{dt} = y^2, 0 \le t \le 1 $$ which does not satisfy a Lipschitz condition.

In [5]:
T = 1.
function forward_euler_integrate(N::Int,T::Float64)
    y = zeros(N+1)
    h = T/N
    y[1] = 1.
    for i=1:N
        y[i+1]= y[i] + h*y[i]^2
    end
    return h, y
end
f=figure();
ui = @manipulate for N=1:1000; withfig(f) do
        h, y = forward_euler_integrate(N, T)
        PyPlot.plot(0:h:T, y);
    end
end
w = Window()
body!(w,ui)
Out[5]:
Page(4, WebSocket(server, CONNECTED), Dict{String,Any}("webio" => Blink.AtomShell.var"#24#25"{Blink.AtomShell.WebIOBlinkComm}(Blink.AtomShell.WebIOBlinkComm(Window(4, Electron(Process(`/Users/dgleich/.julia/packages/Blink/u1xcH/deps/Julia.app/Contents/MacOS/Julia /Users/dgleich/.julia/packages/Blink/u1xcH/src/AtomShell/main.js port 7449`, ProcessRunning), Sockets.TCPSocket(RawFD(0x0000003b) active, 0 bytes waiting), Dict{String,Any}("callback" => Blink.var"#1#2"())), Page(#= circular reference @-5 =#), Task (done) @0x0000000113691450))),"callback" => Blink.var"#1#2"()), Distributed.Future(1, 1, 4, Some(true)))

The following system can be shown to analytically decay to zero as t gets large.

In [7]:
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();
ui = @manipulate for N=1:10000; withfig(f) do
        h, y = forward_euler_integrate(N, T)
        PyPlot.plot(collect(0:h:T), y');
    end
end
w = Window()
body!(w,ui)
Out[7]:
Page(6, WebSocket(server, CONNECTED), Dict{String,Any}("webio" => Blink.AtomShell.var"#24#25"{Blink.AtomShell.WebIOBlinkComm}(Blink.AtomShell.WebIOBlinkComm(Window(6, Electron(Process(`/Users/dgleich/.julia/packages/Blink/u1xcH/deps/Julia.app/Contents/MacOS/Julia /Users/dgleich/.julia/packages/Blink/u1xcH/src/AtomShell/main.js port 7449`, ProcessRunning), Sockets.TCPSocket(RawFD(0x0000003b) active, 0 bytes waiting), Dict{String,Any}("callback" => Blink.var"#1#2"())), Page(#= circular reference @-5 =#), Task (done) @0x0000000113691690))),"callback" => Blink.var"#1#2"()), Distributed.Future(1, 1, 6, Some(true)))
Unexpected end of input
 ...when parsing byte with value '0'
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] _error(::String, ::JSON.Parser.StreamingParserState{Sockets.TCPSocket}) at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:150
 [3] byteat(::JSON.Parser.StreamingParserState{Sockets.TCPSocket}) at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:59
 [4] current at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:72 [inlined]
 [5] chomp_space! at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:117 [inlined]
 [6] parse_value(::JSON.Parser.ParserContext{Dict{String,Any},Int64,true,nothing}, ::JSON.Parser.StreamingParserState{Sockets.TCPSocket}) at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:160
 [7] parse(::Sockets.TCPSocket; dicttype::Type{T} where T, inttype::Type{Int64}, allownan::Bool, null::Nothing) at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:494
 [8] parse at /Users/dgleich/.julia/packages/JSON/d89fA/src/Parser.jl:492 [inlined]
 [9] macro expansion at /Users/dgleich/.julia/packages/Lazy/9Xnd3/src/macros.jl:268 [inlined]
 [10] macro expansion at /Users/dgleich/.julia/packages/Blink/u1xcH/src/AtomShell/process.jl:111 [inlined]
 [11] (::Blink.AtomShell.var"#9#10"{Electron})() at ./task.jl:356
In [6]:
T =500.
h, y = forward_euler_integrate(100000, T)
PyPlot.plot(collect(0:h:T), y');
In [7]:
Pkg.update()
INFO: Updating METADATA...
INFO: Updating cache of ColorTypes...
INFO: Updating cache of ReverseDiffSource...
INFO: Updating cache of FixedSizeArrays...
INFO: Updating cache of IJulia...
INFO: Updating cache of Clang...
INFO: Updating cache of ColorVectorSpace...
INFO: Updating cache of ProfileView...
INFO: Updating cache of UnicodePlots...
INFO: Updating cache of Interact...
INFO: Updating cache of Reactive...
INFO: Updating cache of Clang...
INFO: Updating JuliaParser...
INFO: Updating ProfileView...
INFO: Updating DGFun...
INFO: Computing changes...
WARNING: julia is fixed at 0.4.5 conflicting with requirement for JuliaParser: [0.5.0-,∞)
LoadError: AbstractTrees can't be installed because it has no versions that support 0.4.5 of julia. You may need to update METADATA by running `Pkg.update()`
while loading In[7], in expression starting on line 1

 in error at error.jl:22
 in resolve at /Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in update at /Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in anonymous at pkg/dir.jl:31
 in cd at /Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in cd at pkg/dir.jl:31
 in update at /Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib