Boundary-value problems

Maple is also very good a finding analytic solutions to boundary-value problems if a solution exists.

Boundary-value problems with Dirichlet conditions

Let us consider a second-order boundary-value problem with Dirichlet boundary conditions:

[> dsolve( {(D@@2)(u)(x) - D(u)(x) + u(x) = sin(x), u(0) = 1, u(Pi) = 2}, {u(x)} );

$u(x) =3{\frac {{e^{x/2}}\sin \left( \sqrt { 3}x/2 \right) }{{e^{\pi/2}}\sin \left( \sqrt {3}\pi/2 \right) } } +\cos(x) $

While in your calculus courses, you would have seen how to find solutions when the ordinary differential equation is linear, Maple can also, in some cases, find solutions when the ODE is nonlinear:

[> dsolve( {(D@@2)(u)(x) = D(u)(x)^2, u(0) = 1, u(10) = 2}, {u(x)} );

$u(x) = -\ln \left( \frac {xe-xe^2 + 10e^2}{10 e^3} \right)$

[> simplify( % );

$u(x) = \ln(2) + \ln(5) + 2 - \ln((10 - x)e + x)$

If you want to use u as a function, you can do the following:

[> u1 := unapply( rhs(%), x ):
   u1(0);

$1$

[> u1(10);

$2$

[> u1(1);

$-\ln\left(\frac{e + 9e^2}{10e^3}\right)$

[> evalf( % );

$1.065298336$

If you assign to u, then be careful to unassign it before you use it again:

[> u := 'u': # Unassign the symbol 'u'

Boundary-value problems with Neumann conditions

Maple can also have Neumann boundary conditions:

[> dsolve( {(D@@2)(u)(x) - D(u)(x)^2 = 1, u(0) = 1, D(u)(10) = 0}, {u(x)} );

$u(x) =-\ln \left( {\frac {\cos \left( 10 \right) \cos \left( x \right) +\sin \left( 10 \right) \sin \left( x \right) }{\cos \left( 10 \right) }} \right) + 1$

[> simplify( % );

$u(x) = \ln(-\cos(10))-\ln(-\cos(10)\cos(x) - \sin(10)\sin(x)) + 1$