软件编程版 #243001 层

关于maple

楼主 · 1 楼
近期有个作业,看了半天有点明白大概意思,可就是不知道怎么做,找高手帮忙呀谢谢了
作业如下

1. Maple Code: Numerical Integrators

> Source: B. Leimkuhler and S. Reich. 2004. Simulating Hamiltonian Dynamics, Cambridge Monographs on Applied

> and Computational Mathematics, v. 14. Chapter 4.

>

>

> eulerb integrates q' = f(q,p), p' = g(q,p).

> h=stepsize

>

> eulerb := proc(f,g,h,q0::Vector,p0::Vector)

> local n,q1,p1,f1,eqs,p,sp;

>

> n := op(1,q0);

> q1 := q0 + h*f(q0,p0); #q1 is found explicitly

> f1 := proc(p::Vector) return p-p0+h*g(q0,p) end proc;

> p := < seq( x[i], i=1..n ) >;

> eqs := convert( Equate( f1(p), Vector(n) ), set );

> sp := convert( Equate(p,p0), set );

> p1 := subs( fsolve(eqs,sp,maxsols=1), p ); #p1 must be found implicity

> return (q1,p1);

>

> end proc:

>

>

>

> Stormer-Verlet algorithm

> sv integrates q'=f(p), p'=g(q).

> h=stepsize

> sv := proc(f,g,h,q0::Vector,p0::Vector)

> local q2,p1,p2;

>

> p1 := p0 + 0.5*h*g(q0); #both q2 and p2 are found explicity

> q2 := q0+h*f(p1);

> p2 := p1 + 0.5*h*g(q2);

> return (q2,p2);

>

> end proc:

>

>

>

>

2. Project 1: The cost and accuracy of numerical integrators





You will do one of the following projects:

A.





Section 2 contains 3 procedures to integrate a system of Hamiltonian differential equations over a single step.

For the first and second integrators, write a procedure that will integrate a system of Hamiltonian DEs over a time interval

t=0..T with a stepsize h. The procedure should return two lists of vectors - a list of position (q) vectors, and a list

of momentum (p) vectors - at the times t=i*h where i=0..T/h.



The Kepler (or 2-body) problem has a hamiltonian H = T+V where

T = 0.5*|p|^2 = Kinetic Energy,

V = -|q|^(-1) = Potential Energy,

and p,q are vectors in R^n. We will take n=2.



The differential equations are



(KDE) q' = H_p = p, p' = -H_q = |q|^(-3) q.



The following functions are constant along solutions to KDE:



H, [Total Energy]

M := q_1 * p_2 - q_2 * p_1, [Angular momemtum about 0]

L := M * p_2 - q_1 / |q| [Lenz-Runge integral].



Integrate the Kepler problem over the time intervals t=0..1,10,100 with initial conditions q0 = <0,0.3>, p0 = <0.1,-0.1>,

using various step sizes.



Compare the eulerb and Stormer-Verlet algorithms in terms of accuracy vs. cost.

You may measure "accuracy" with your first integrals. You may measure "cost" by the time each integrator takes.