Differences between revisions 15 and 20 (spanning 5 versions)
Revision 15 as of 2010-04-13 18:39:23
Size: 16870
Comment:
Revision 20 as of 2012-04-18 17:46:53
Size: 19017
Editor: bvarberg
Comment:
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:
{{{ {{{#!sagecell
Line 30: Line 30:
    steps_shown = max(nsteps,show_steps)     steps_shown = min(nsteps,show_steps)
Line 49: Line 49:
{{{ {{{#!sagecell
Line 83: Line 83:
{{{ {{{#!sagecell
Line 130: Line 130:
== Linear two-dimensional ODEs ==
by Marshall Hampton
{{{#!sagecell
%cython
cpdef c_euler_m(double t0, double x10, double x20, double tend, int steps, double a11, double a12, double a21, double a22, double cutoff = 10):
    cdef double h = (tend-t0)/steps
    traj = [[x10,x20]]
    cdef double x1current = x10
    cdef double x2current = x20
    cdef int i
    cdef double newx1
    cdef double newx2
    for i in range(0,steps):
        newx1 = x1current + h*a11*x1current + h*a12*x2current
        newx2 = x2current + h*a21*x1current + h*a22*x2current
        if newx1 > cutoff or newx2 > cutoff or newx1 < -cutoff or newx2 < -cutoff:
            break
        traj.append([newx1,newx2])
        x1current = newx1
        x2current = newx2
    return traj
}}}
{{{#!sagecell
@interact
def planarsystem(a11 = slider(srange(-10,10,1/10),default = -1), a12 = slider(srange(-10,10,1/10),default = -1), a21 = slider(srange(-10,10,1/10),default = 1), a22 = slider(srange(-10,10,1/10),default = -1), time_tracked = slider(srange(1,100,1.0),default=10)):
    A = matrix(RDF,[[a11,a12],[a21,a22]])
    eigs = A.eigenvalues()
    html('<center>$x\' = Ax$ dynamics<BR>$A = '+latex(A)+'$, eigenvalues: $%2.2f + %2.2fI, %2.2f + %2.2fI$</center>'%(eigs[0].real(),eigs[0].imag(),eigs[1].real(),eigs[1].imag()))
    trajs = Graphics()
    for q in srange(0,2*pi,.15):
        astart = randint(1,10)
        ntraj = c_euler_m(0,cos(q),sin(q),time_tracked,300,a11,a12,a21,a22)
        for i in range(astart,len(ntraj)-1,10):
            trajs = trajs + arrow(ntraj[i],ntraj[i+1],width=1, arrowsize=2)
        trajs = trajs + line(ntraj)
        ntraj = c_euler_m(0,cos(q),sin(q),-time_tracked,300,a11,a12,a21,a22)
        trajs = trajs + line(ntraj)
        for i in range(astart,len(ntraj)-1,10):
            trajs = trajs + arrow(ntraj[i+1],ntraj[i],width=1, arrowsize=2)
    show(trajs, figsize = [6,6], xmin = -1, xmax = 1, ymin = -1, ymax = 1)
}}}
{{attachment:linear2x2.png}}
Line 132: Line 175:
{{{ {{{#!sagecell
Line 212: Line 255:
{{{ {{{#!sagecell
Line 259: Line 302:

{{{
by Marshall Hampton
{{{#!sagecell
Line 294: Line 337:
{{{ {{{#!sagecell
Line 320: Line 363:
{{{ {{{#!sagecell
Line 350: Line 393:
{{{ {{{#!sagecell
Line 358: Line 401:
alpha=[(n,c*numerical_integral(f(x)*sin(x*n/2),0,2*pi)[0] ) for n in range(1,orden)] alpha=[(n,c*numerical_integral(f*sin(x*n/2),0,2*pi)[0] ) for n in range(1,orden)]
Line 368: Line 411:
== Heat equation using finite diferences in cython (very fast!) == == Heat equation using finite diferences in cython ==
Line 371: Line 414:
{{{ {{{#!sagecell
Line 387: Line 430:
{{{ {{{#!sagecell
Line 392: Line 435:
def _(f=input_box(default=x*exp(-x^2)), longitud=input_box(default=2*pi), def _(f=input_box(default=x*exp(-x^2),label='f(x)'), longitud=input_box(default=2*pi),
Line 395: Line 438:
    efe=f._fast_float_()     efe=f._fast_float_(x)
Line 414: Line 457:
{{{ {{{#!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

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)