lec27.mws

L-27 MCS 320 Friday 28 October 2005

> restart;

The command dsolve is almost as popular in Maple as solve.

1. Symbolic Solution of differential equations

This is the purely symbolic solution of an differential equation, obtained by anti-differentiation:

> ODE := x*diff(y(x),x) = y(x)*ln(x*y(x)) - y(x);

ODE := x*diff(y(x), x) = y(x)*ln(x*y(x))-y(x)

> sol := dsolve(ODE,y(x));

sol := y(x) = exp(x/_C1)/x

This is a first-order ODE, we derived only once with respect to x.  The result is a family parametrized by the complex constant C1.  To verify whether we have a solution, we substitute the solution into the ODE.  Conveniently that the solution is an equation, because we can give this as first argument to subs:

> subs(sol,ODE);

x*diff(exp(x/_C1)/x, x) = exp(x/_C1)*ln(exp(x/_C1))/x-exp(x/_C1)/x

> simplify(%);

exp(x/_C1)*(x-_C1)/(x*_C1) = exp(x/_C1)*(ln(exp(x/_C1))-1)/x

This is a nice illustration of the normalization problem in symbolic computation.

2. Series Expansions to solve

If a symbolic solution does not exist as an explicit formula, we may still compute symbolically an approximate answer, using series.

> diffeq := L*diff(theta(t),t$2) = -g*sin(theta(t));

diffeq := L*diff(theta(t), `$`(t, 2)) = -g*sin(theta(t))

This ODE expresses the motion of a pendulum, made from a mass hanging from a string of length L, subject to the gravitation (constant g).  In order to have a formal solution, we simplify sin(theta) = theta, for small values of theta.

We turn this problem into an Initial Value Problem (IVP) by the conditions

> inits := theta(0) = 0, D(theta)(0) = v[0];

inits := theta(0) = 0, D(theta)(0) = v[0]

The two initial conditions express that at t = 0, we have no deviation in the angle, but we have an initial velocity v[0].  Notice the introduction of the "D" operator, here we consider theta as a function, whereas in the differential equation, we use the "diff" operator.

> IVP := {diffeq,inits};

IVP := {L*diff(theta(t), `$`(t, 2)) = -g*sin(theta(t)), theta(0) = 0, D(theta)(0) = v[0]}

> sol := dsolve(IVP,theta(t),series);

sol := theta(t) = series(v[0]*t-1/6*g*v[0]/L*t^3+1/120*g*v[0]*(g+v[0]^2*L)/L^2*t^5+O(t^6),t,6)

This is a formal solution, we see the parameters L, g, v[0] as symbols.  But it is also an approximate solution, valid only for small values of t, t << 1.

3. Numerical Solutions

To illustrate the numerical option, we take another differential equation:

> diffeq := diff(y(t),t$2) - (1-y(t)^2)*diff(y(t),t) + y(t) = 0;

diffeq := diff(y(t), `$`(t, 2))-(1-y(t)^2)*diff(y(t), t)+y(t) = 0

> inits := y(0) = 0, D(y)(0) = -0.1;

inits := y(0) = 0, D(y)(0) = -.1

> IVP := {diffeq,inits};

IVP := {diff(y(t), `$`(t, 2))-(1-y(t)^2)*diff(y(t), t)+y(t) = 0, y(0) = 0, D(y)(0) = -.1}

> sol := dsolve(IVP,y(t),numeric);

sol := proc (x_rkf45) local res, data, vars, solnproc, outpoint, ndsol, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; _EnvDSNumericSaveDigits := Digits; Digits := 14; if ...

Maple returns a procedure, which we may evaluate, for any value of t, say t = 0:

> sol(0);

[t = 0., y(t) = 0., diff(y(t), t) = -.10000000000000]

On return we get a list of equations.  First the value of t, then the position y(t), and then the velocity.  Here we recognize our initial conditions.

> sol(1);

[t = 1., y(t) = -.144768564789424098, diff(y(t), t) = -.178104078335680316]

To plot the solution, we often create an extra function:

> ysol := t -> rhs(sol(t)[2]);

ysol := proc (t) options operator, arrow; rhs(sol(t)[2]) end proc

> ysol(1);

-.144768564789424098

> plot(ysol,0..20);

[Plot]

>

4. Graphical Solutions

We can plot a vector field of trajectories, for systems of first order equations.

See the handout to convert this problem into a system of two first order equations, introducting an extra variable yy(t) for diff(y(t),t).