AnalyticalSolutions.mw

Analytical Solutions of PDEs using PDEtools in Maple 

Aleksandar Donev, Courant Institute 

This is largely based on examples in the excellent Maple documentation 

> restart:
 

The PDEtools package is a collection of commands and routines for finding analytical solutions for partial differential equations (PDEs) based on the paper "A Computational Approach for the Analytical Solving of Partial Differential Equations" by E.S. Cheb-Terrab and K. von Bulow (see References ), and the continuation of this work by the same authors ( Symmetry routines ) during 2004. 

> with(PDEtools):
 

First-Order PDEs 

Maple knows about the method of characteristics: 

> U := diff_table(u(x,t)): # To enable compact notation U_xx etc.
 

> PDE := U[t]+c*U[x]=-lambda*U[]; # Advection-reaction linear equation
 

`+`(`*`(c, `*`(diff(u(x, t), x))), diff(u(x, t), t)) = `+`(`-`(`*`(lambda, `*`(u(x, t))))) (1)
 

> IC := eval(U[], t=0) = phi(x); # Initial conditions
 

u(x, 0) = phi(x) (2)
 

> pdsolve([PDE,IC]); # Try to solve the PDE automatically - works!
 

u(x, t) = `*`(phi(`+`(`-`(`*`(c, `*`(t))), x)), `*`(exp(`+`(`-`(`*`(lambda, `*`(t))))))) (3)
 

Try to get a general solution: 

> pdsolve(PDE); # No initial condition
 

u(x, t) = `*`(_F1(`/`(`*`(`+`(`*`(c, `*`(t)), `-`(x))), `*`(c))), `*`(exp(`+`(`-`(`/`(`*`(lambda, `*`(x)), `*`(c))))))) (4)
 

> PDE := U[t]+c*U[x]=-lambda*U[]^2; # Advection-reaction nonlinear equation
 

`+`(`*`(c, `*`(diff(u(x, t), x))), diff(u(x, t), t)) = `+`(`-`(`*`(lambda, `*`(`^`(u(x, t), 2))))) (5)
 

> pdsolve([PDE,IC]); # Works here also since simple first-order equation
 

u(x, t) = `/`(`*`(phi(`+`(`-`(`*`(c, `*`(t))), x))), `*`(`+`(`*`(phi(`+`(`-`(`*`(c, `*`(t))), x)), `*`(lambda, `*`(t))), 1))) (6)
 

> PDE := U[t]+c*U[]*U[x]=0; # Burger's equation
 

`+`(`*`(c, `*`(u(x, t), `*`(diff(u(x, t), x)))), diff(u(x, t), t)) = 0 (7)
 

> pdsolve([PDE,IC]); # Does not return anything (cannot find solution)
 

Heat Equation 

> restart: with(PDEtools):
 

Maple knows about the method of separation of variables: 

> BVP:=[diff(u(x, t), t) = k*diff(u(x, t), x, x), u(0, t) = 0, u(Pi, t) = 0, u(x,0) = f(x)]; # Heat equation in 1D with homogeneous Dirichlet BCs
 

[diff(u(x, t), t) = `*`(k, `*`(diff(diff(u(x, t), x), x))), u(0, t) = 0, u(Pi, t) = 0, u(x, 0) = f(x)] (8)
 

> sol:=pdsolve(BVP);
 

u(x, t) = Sum(`+`(`/`(`*`(2, `*`(Int(`*`(f(x), `*`(sin(`*`(_Z1, `*`(x))))), x = 0 .. Pi), `*`(sin(`*`(_Z1, `*`(x))), `*`(exp(`+`(`-`(`*`(k, `*`(`^`(_Z1, 2), `*`(t)))))))))), `*`(Pi))), _Z1 = 1 .. infi... (9)
 

> g(x):=piecewise(x<1/2,0,x>Pi/2,Pi,x=Pi/2,Pi/2);
 

piecewise(`<`(x, `/`(1, 2)), 0, `<`(`+`(`*`(`/`(1, 2), `*`(Pi))), x), Pi, x = `+`(`*`(`/`(1, 2), `*`(Pi))), `+`(`*`(`/`(1, 2), `*`(Pi)))) (10)
 

> plot(g(x),x=0..Pi)
 

Plot_2d
 

> pdsolve(eval(BVP, f(x)=g(x)));
 

Error, (in casesplit/K) this version of casesplit is not yet handling the function: piecewise
 

> temp:=eval(sol, f(x)=g(x));
 

u(x, t) = Sum(`+`(`/`(`*`(2, `*`(Int(`*`(piecewise(`<`(x, `/`(1, 2)), 0, `<`(`+`(`*`(`/`(1, 2), `*`(Pi))), x), Pi, x = `+`(`*`(`/`(1, 2), `*`(Pi))), `+`(`*`(`/`(1, 2), `*`(Pi)))), `*`(sin(`*`(_Z1, `*`... (11)
 

> sol_series:=value(temp);
 

u(x, t) = sum(`+`(`/`(`*`(2, `*`(`+`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(_Z1))))), `-`(`^`(-1, _Z1))), `*`(sin(`*`(_Z1, `*`(x))), `*`(exp(`+`(`-`(`*`(k, `*`(`^`(_Z1, 2), `*`(t)))))))))), `*`(_Z1))), _Z... (12)
 

Numerical Evaluation 

Plotting the Solution 

To plot this we need to truncate the sum to a few terms 

> summand:=op(1, rhs(sol_series));
 

`+`(`/`(`*`(2, `*`(`+`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(_Z1))))), `-`(`^`(-1, _Z1))), `*`(sin(`*`(_Z1, `*`(x))), `*`(exp(`+`(`-`(`*`(k, `*`(`^`(_Z1, 2), `*`(t)))))))))), `*`(_Z1))) (13)
 

> summand:=eval(summand, {_Z1=n, k=1});
 

`+`(`/`(`*`(2, `*`(`+`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(n))))), `-`(`^`(-1, n))), `*`(sin(`*`(n, `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(t))))))))), `*`(n))) (14)
 

Here we only take 10 terms: 

> sol_approx:=unapply(simplify(add(summand, n=1..10)),t);
 

proc (t) options operator, arrow; `+`(`*`(2, `*`(sin(x), `*`(exp(`+`(`-`(t)))))), `-`(`*`(2, `*`(sin(`+`(`*`(2, `*`(x)))), `*`(exp(`+`(`-`(`*`(4, `*`(t))))))))), `*`(`/`(2, 3), `*`(sin(`+`(`*`(3, `*`(...
proc (t) options operator, arrow; `+`(`*`(2, `*`(sin(x), `*`(exp(`+`(`-`(t)))))), `-`(`*`(2, `*`(sin(`+`(`*`(2, `*`(x)))), `*`(exp(`+`(`-`(`*`(4, `*`(t))))))))), `*`(`/`(2, 3), `*`(sin(`+`(`*`(3, `*`(...
(15)
 

> plot( {seq(sol_approx(i*0.05), i=0..5)}, x=0..Pi);
 

Plot_2d
 

We can turn this into an animation to make it more informative: 

> plots[animate]( plot, [sol_approx(t), x=0..Pi], t=0..2 );
 

Plot_2d
 

Gibbs Phenomenon 

At t=0 we are getting the Gibbs phenomenon, lets explore this some more: 

> summ0:=eval(summand, t=0);
 

`+`(`/`(`*`(2, `*`(`+`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(n))))), `-`(`^`(-1, n))), `*`(sin(`*`(n, `*`(x)))))), `*`(n))) (16)
 

> plot( {seq(add(summ0, n=1..4*N), N=1..5)}, x=0..Pi);
 

Plot_2d
 

Numerical Accuracy 

To see how good our solution is, we should really compare with the solution obtained by including more terms 

> sol_better_approx:=unapply(simplify(add(summand, n=1..20)),t):
 

> plots[animate]( plot, [{sol_approx(t), sol_better_approx(t)}, x=0..Pi], t=0..0.1, frames=50);
 

Plot_2d
 

Wave Equation (from recitation) 

Here we try to solve  Problem 9 in section 4.7 of APDE, as was done in recitation on 4/15/2016 by recitation leader JT. Look at his solution notes first. 

> restart: with(PDEtools):
 

> BVP:=[diff(u(x, t), t,t) = diff(u(x, t), x, x), u(0, t) = 0, u(1, t) = sin(t), u(x,0) = x*(1-x), D[2](u)(x,0)=0];
 

[diff(diff(u(x, t), t), t) = diff(diff(u(x, t), x), x), u(0, t) = 0, u(1, t) = sin(t), u(x, 0) = `*`(x, `*`(`+`(1, `-`(x)))), (D[2](u))(x, 0) = 0] (17)
 

> #infolevel[pdsolve]:=5; # If you want to see what Maple is trying out
 

> sol:=pdsolve(BVP); # No solution returned
 

(18)
 

Let's try to see what the problem is, inhomogeneous BCs, or initial condition, or what: 

> BVP_hom:=[diff(u(x, t), t,t) = diff(u(x, t), x, x), u(0, t) = 0, u(1, t) = 0,  u(x,0) = x*(1-x), D[2](u)(x, 0) = 0]; # Make the BC at x=1 be homogeneous
 

[diff(diff(u(x, t), t), t) = diff(diff(u(x, t), x), x), u(0, t) = 0, u(1, t) = 0, u(x, 0) = `*`(x, `*`(`+`(1, `-`(x)))), (D[2](u))(x, 0) = 0] (19)
 

> sol:=pdsolve(BVP_hom); # Now it worked fine
 

u(x, t) = Sum(`+`(`-`(`/`(`*`(4, `*`(`+`(`^`(-1, _Z1), `-`(1)), `*`(sin(`*`(_Z1, `*`(Pi, `*`(x)))), `*`(cos(`*`(_Z1, `*`(Pi, `*`(t)))))))), `*`(`^`(Pi, 3), `*`(`^`(_Z1, 3)))))), _Z1 = 1 .. infinity) (20)
 

So let's break up the problem into two problems just like done in class: 

 

First a simple Laplace equation to take care of the BC. Note that here we tell Maple the solution is only a function of x, since for each t we are solving only an equation for x. If we wrote v(x,t) below it wouldn't work even though the same solution would work: 

> BVP_BC:=[0 = diff(v(x), x, x), v(0) = 0, v(1) = sin(t)];
 

[0 = diff(diff(v(x), x), x), v(0) = 0, v(1) = sin(t)] (21)
 

> sol_BC:=pdsolve(BVP_BC);
 

v(x) = `*`(sin(t), `*`(x)) (22)
 

> v(x,t):=rhs(sol_BC);
 

`*`(sin(t), `*`(x)) (23)
 

Now solve with homogeneous BCs but make sure to subtract the time derivative of the v(x,t) from the right hand side as a source term: 

> BVP_IC:=[diff(u(x, t), t,t) = diff(u(x, t), x, x) - diff(v(x,t),t), u(0, t) = 0, u(1, t) = 0,  u(x,0) = x*(1-x) - eval(v(x,t), t=0) , D[2](u)(x, 0) = 0];
 

[diff(diff(u(x, t), t), t) = `+`(diff(diff(u(x, t), x), x), `-`(`*`(cos(t), `*`(x)))), u(0, t) = 0, u(1, t) = 0, u(x, 0) = `*`(x, `*`(`+`(1, `-`(x)))), (D[2](u))(x, 0) = 0] (24)
 

> pdsolve(BVP_IC); # Sadly, it again does not return an answer!
 

Seems Maple hasn't learned how to solve this sort of problem with forcing yet, at least not automatically. We can still use Maple to help us with some of the integrals, however: 

> a_k:=simplify(2*int(x*sin(k*Pi*x),x=0..1)) assuming k,integer; # Eq. (9) in JT's solution
 

`+`(`/`(`*`(2, `*`(`^`(-1, `+`(1, k)))), `*`(k, `*`(Pi)))) (25)
 

> b_k:=simplify(2*int(x*(1-x)*sin(k*Pi*x),x=0..1)) assuming k,integer; # Eq. (10) in JT's solution
 

`/`(`*`(`+`(`*`(4, `*`(`^`(-1, `+`(1, k)))), 4)), `*`(`^`(k, 3), `*`(`^`(Pi, 3)))) (26)
 

> sol_ODE:=dsolve({diff(T(t),t,t)+(k*Pi)^2*T(t)=a_k*sin(t),T(0)=b_k,D(T)(0)=-a_k}, T(t)); # Eqs. (14,15,23) in JT's solution, the most tedious step
 

T(t) = `+`(`-`(`/`(`*`(2, `*`(sin(`*`(k, `*`(Pi, `*`(t)))), `*`(`^`(-1, `+`(1, k))))), `*`(`+`(`*`(`^`(Pi, 2), `*`(`^`(k, 2))), `-`(1))))), `/`(`*`(4, `*`(cos(`*`(k, `*`(Pi, `*`(t)))), `*`(`+`(`^`(-1,... (27)
 

Giving Hints 

For complicated nonlinear PDEs usually Maple won't know what to do (perhaps no one does!) 

> V := diff_table(v(x,y)):
 

> PDE := V[]*V[x,y ] + V[x]*V[y] = 1;
 

`+`(`*`(v(x, y), `*`(diff(diff(v(x, y), x), y))), `*`(diff(v(x, y), x), `*`(diff(v(x, y), y)))) = 1 (28)
 

> pdsolve(PDE); # Maple tried separation of variables and it worked!
 

PDESolStruc(v(x, y) = `*`(_F1(x), `*`(_F2(y))), [{diff(_F1(x), x) = `/`(`*`(_c[1]), `*`(_F1(x))), diff(_F2(y), y) = `+`(`/`(`*`(`/`(1, 2)), `*`(_F2(y), `*`(_c[1]))))}]) (29)
 

> pdsolve(PDE, HINT=X(x)*Y(y)); # Give hint to use separation of variables
 

PDESolStruc(v(x, y) = `*`(X(x), `*`(Y(y))), [{diff(X(x), x) = `/`(`*`(_c[1]), `*`(X(x))), diff(Y(y), y) = `+`(`/`(`*`(`/`(1, 2)), `*`(Y(y), `*`(_c[1]))))}]) (30)
 

Maple did not by default try to solve the ODEs above, but we can ask it to continue solving: 

> pdsolve(PDE, HINT=X(x)*Y(y), build);
 

v(x, y) = `/`(`*`(`^`(`+`(`*`(2, `*`(x, `*`(_c[1]))), _C1), `/`(1, 2)), `*`(`^`(`+`(`*`(_C2, `*`(`^`(_c[1], 2))), `*`(y, `*`(_c[1]))), `/`(1, 2)))), `*`(_c[1])) (31)
 

> pdsolve(PDE, HINT=sqrt(P(x,y))); # Find an even more general solution
 

v(x, y) = `*`(`^`(`+`(_F2(x), _F1(y), `*`(2, `*`(x, `*`(y)))), `/`(1, 2))) (32)
 

>
 

Solitons in the Korteweg–de Vries Equation 

Now we try an equation we have not seen in class, one that exhibits solutions called solitons, which are stable traveling waves that find uses in fiber optic communication, and can be observed in certain water channels. 

> restart: with(PDEtools):
 

> U := diff_table(u(x,t)): # To enable compact notation U_xx etc.
 

The KdV equation is a nonlinear third-order PDE that adds a third derivative term to the Burgers equation 

> PDE := U[t]+6*U[]*U[x]+U[x,x,x]=0; # The KdV equation with coefficient 6 chosen for convenience
 

`+`(`*`(6, `*`(u(x, t), `*`(diff(u(x, t), x)))), diff(u(x, t), t), diff(diff(diff(u(x, t), x), x), x)) = 0 (33)
 

> infolevel[pdsolve]:=3:
 

> sol:=pdsolve(PDE); # Looks like Maple knew to look for traveling wave solutions
 

 

First set of solution methods (general or quasi general solution)
 

Second set of solution methods (complete solutions)
Third set of solution methods (simple HINTs for separating variables)
PDE linear in highest derivatives - trying a separation of variables by *
HINT = *
Fourth set of solution methods
Preparing a solution HINT ...
Trying HINT = _F1(x)*_F2(t)
Fourth set of solution methods
Preparing a solution HINT ...
Trying HINT = _F1(x)+_F2(t)
Trying travelling wave solutions as power series in tanh ...
* Using tau = tanh(t*C[2]+x*C[1]+C[0])
* Equivalent ODE system: {-C[1]^3*(tau^2-1)*(tau^4-2*tau^2+1)*diff(diff(diff(u(tau),tau),tau),tau)-C[1]^3*(tau^2-1)*(6*tau^3-6*tau)*diff(diff(u(tau),tau),tau)+(-6*u(tau)*C[1]*(tau^2-1)-C[2]*(tau^2-1)-C[1]^3*(tau^2-1)*(6*tau^2-2))*diff(u(tau),tau)}
* Ordering for functions: [u(tau)]
* Cases for the upper bounds: [[n[1] = 2]]
* Power series solution [1]: {u(tau) = tau^2*A[1,2]+tau*A[1,1]+A[1,0]}
* Solution [1] for {A[i, j], C[k]}: [[A[1,1] = 0, A[1,2] = 0], [A[1,0] = 1/6*(8*C[1]^3-C[2])/C[1], A[1,1] = 0, A[1,2] = -2*C[1]^2]]
travelling wave solutions successful.
u(x, t) = `+`(`-`(`*`(2, `*`(`^`(_C2, 2), `*`(`^`(tanh(`+`(`*`(_C2, `*`(x)), `*`(_C3, `*`(t)), _C1)), 2))))), `/`(`*`(`/`(1, 6), `*`(`+`(`*`(8, `*`(`^`(_C2, 3))), `-`(_C3)))), `*`(_C2))) (34)
 

> soliton:=u(x,t)=1/2*c*(sech(sqrt(c)/2*(x-c*t)))^2;
 

u(x, t) = `+`(`*`(`/`(1, 2), `*`(c, `*`(`^`(sech(`+`(`*`(`/`(1, 2), `*`(`^`(c, `/`(1, 2)), `*`(`+`(`-`(`*`(c, `*`(t))), x)))))), 2))))) (35)
 

> convert(soliton, expln);
 

u(x, t) = `+`(`/`(`*`(2, `*`(c)), `*`(`^`(`+`(exp(`+`(`*`(`/`(1, 2), `*`(`^`(c, `/`(1, 2)), `*`(`+`(`-`(`*`(c, `*`(t))), x)))))), exp(`+`(`-`(`*`(`/`(1, 2), `*`(`^`(c, `/`(1, 2)), `*`(`+`(`-`(`*`(c, `... (36)
 

> pdetest(soliton,PDE); # Check if it a solution of the PDE
 

0 (37)
 

> sol_example:=eval(rhs(soliton),c=1);
 

`+`(`*`(`/`(1, 2), `*`(`^`(sech(`+`(`*`(`/`(1, 2), `*`(t)), `-`(`*`(`/`(1, 2), `*`(x))))), 2)))) (38)
 

> plots[animate]( plot, [{sol_example}, x=-10..50], t=0..50, frames=50);
 

Plot_2d
 

> ODE:=eval(eval(PDE, u(x,t)=f(x-c*t)), x-c*t=xi);
 

`+`(`*`(6, `*`(f(xi), `*`((D(f))(xi)))), `-`(`*`((D(f))(xi), `*`(c))), ((`@@`(D, 3))(f))(xi)) = 0 (39)
 

> ODE:=convert(ODE,diff);
 

`+`(`*`(6, `*`(f(xi), `*`(diff(f(xi), xi)))), `-`(`*`(diff(f(xi), xi), `*`(c))), diff(diff(diff(f(xi), xi), xi), xi)) = 0 (40)
 

> simpler_ODE:=int(lhs(ODE),xi)-A=0;
 

`+`(`*`(3, `*`(`^`(f(xi), 2))), `-`(`*`(c, `*`(f(xi)))), diff(diff(f(xi), xi), xi), `-`(A)) = 0 (41)
 

> sols:=dsolve(simpler_ODE,f(xi)); # There are many solutions and they are not simple
 

`+`(Intat(`/`(1, `*`(`^`(`+`(`-`(`*`(2, `*`(`^`(_a, 3)))), `*`(`^`(_a, 2), `*`(c)), `*`(2, `*`(A, `*`(_a))), _C1), `/`(1, 2)))), _a = f(xi)), `-`(xi), `-`(_C2)) = 0, `+`(Intat(`+`(`-`(`/`(1, `*`(`^`(`... (42)
 

Let's give up on analytical solutions and just use numerics to explore our special soliton solutions...next class 

>