Differences between revisions 20 and 21
Revision 20 as of 2012-04-18 17:46:53
Size: 19017
Editor: bvarberg
Comment:
Revision 21 as of 2012-04-18 17:51:57
Size: 18997
Editor: bvarberg
Comment:
Deletions are marked like this. Additions are marked like this.
Line 414: Line 414:
{{{#!sagecell {{{
Line 430: Line 430:
{{{#!sagecell {{{

Sage Interactions - Differential Equations

goto interact main page

Euler's Method in one variable

by Marshall Hampton. This needs some polishing but its usable as is.

eulermethod.png

Vector Fields and Euler's Method

by Mike Hansen (tested and updated by William Stein, and later by Dan Drake)

euler.png

Vector Field with Runga-Kutta-Fehlberg

by Harald Schilly

ode_runga_kutta.png

Linear two-dimensional ODEs

by Marshall Hampton

linear2x2.png

Euler's Method, Improved Euler, and 4th order Runge-Kutta in one variable

by Marshall Hampton. This is a more baroque version of the Euler's method demo above.

rk4.png

Mass/Spring systems

by Jason Grout

These two interacts involve some Cython code or other scipy imports, so I've posted a file containing them. You can download the worksheet or copy it online.

Picard iteration example

by Marshall Hampton and David Joyner

picard.png

Euler-Maruyama method and geometric Brownian motion (a common simple model of the stock market)

by Marshall Hampton

eulermaruyama.png

Autonomous equations and stable/unstable fixed points

by Marshall Hampton This needs the Cython functon defined in a seperate cell. Note that it is not a particularly good example of Cython use.

Autonomous1.png

Heat equation using Fourier series

by Pablo Angulo

heat_fourier.png

Heat equation using finite diferences in cython

by Pablo Angulo

%cython
#cython code implementing a very simple finite diference scheme
import numpy as np
def calor_cython(u0,float dx, float k,float t_f,int tsteps):
    cdef int m
    cdef float dt
    cdef float s
    u=np.array(u0)
    dt=t_f/tsteps
    s=k*dt/(dx**2)        #we cannot use ^ for exponentiation in cython
    for m in range(tsteps):
        u[1:-1]=(1-2*s)*u[1:-1]+s*u[0:-2]+s*u[2:]
    return u

#interact box wrapping the code above
var('x')

@interact
def _(f=input_box(default=x*exp(-x^2),label='f(x)'), longitud=input_box(default=2*pi),
      tiempo=input_box(default=0.1), M=input_box(default=100),
      k=input_box(default=1), tsteps=input_box(default=2000) ):
    efe=f._fast_float_(x)
    dx=float(longitud/M)
    xs=[n*dx for n in range(M+1)]
    u0=[efe(a) for a in xs]

    s=k*(tiempo/tsteps) /dx^2
    if s>0.5:
        print 's=%f > 1/2!!!  The method is not stable'%s

    ut=calor_cython(u0,dx,k,tiempo,tsteps)
    show( line2d(zip(xs, u0)) + line2d(zip(xs, ut), rgbcolor='green') )

heat_findif.png

DE with boundary values

The following interact demo looks at the DE+BC y'+y=0, y(0)=a, y(b)=c, and has a slider for b. When b=pi "problems arise":-)

de-interact-with-BCs.sws

interact/diffeq (last edited 2020-02-08 13:22:36 by chapoton)