35DEmthd.mws

Partial Differential Equations PowerTool

by Dr. Jim Herod

Section 8.1: Numerical Solutions for Ordinary Differential Equations: Difference Methods

Maple Packages used in Section 8.1

>    restart:

>    with(plots):

Warning, the name changecoords has been redefined

>    with(LinearAlgebra):

 

There are many methods for getting numerical solutions for ordinary differential equations. Through the years, with improving analysis, software and hardware, the methods have improved in accuracy. Euler's Method, Improved Euler's Method, and the Runge-Kutta Method are commonly taught in undergraduate classes as methods for obtaining numerical solutions for ordinary differential equations.  Maple uses a Runge-Kutta-Fehlberg 4/5th order integration method, among others.

In this Section 8.1, we will follow closely the methods presented by Douglas Meade in Unit 18 of his notes for the Ordinary Differential Equations Powertool at the Maplesoft web site. See

http://www.mapleapps.com/powertools/des/des.shtml

In that material, Meade has a complete section, Part IV, on numerical methods for initial value value problems. Part V in his materials contains numerical methods for boundary value problems.

Of course, in partial differential equations, derivatives are made with respect to more than one variable, so the ability to simply "step across the interval" is missing. The methods shown in this 8th Chapter uses the techniques of finite difference methods . The methods could be called discrete replacement methods  for, following the development in Unit 18 of Meade's work, we replace  the derivatives by discrete  approximations. With these methods, the job of getting an approximation for a solution of a differential equation is changed to a task in linear algebra.

The purpose of reviewing these ordinary differential equations methods is that similar techniques will be expanded for partial differential equations.

It should be no surprise that there are choices on what discrete replacements will be made for the derivatives. For example, there are forward difference replacements and backward difference replacements. We follow Meade as we make choices for the replacements. We use and apply the finite difference method to a two-point boundary value problem

   Diff(y,`$`(x,2))+p(x)*Diff(y,x)+q(x)*y = f(x) .

There will be a boundary condition at each endpoint of an interval over which we solve the equation. Meade calls the endpoints a  and b . The mesh points will be denoted [ x[0] , x[1], x[2] , ... , x[N] ].

We explain now how we will replace diff(y,x)  and diff(y,`$`(x,2)) .

Replacement for    diff(y,x) :

Recall Taylor's Series:

   y( x + h) = y(x) + h  y '(x) +   0 ( h^2 )

and

   y( x - h) = y(x) - h  y '(x) +   0 ( h^2 )

Thus,

   y '(x) is replaced by the difference 1/2   (y(x+h)-y(x-h))/h   and this is good with order   0 ( h^2 ).

Replacement for    diff(y,`$`(x,2)) :

Use Taylor's Series again:

   y(x + h) = y(x) + h y '(x) + h^2/2  y ''(x) + h^3/3!  y '''(x) + 0 ( h^4 ).
   y(x - h) = y(x) - h y '(x) +
h^2/2  y ''(x)  - h^3/3!  y '''(x) + 0 ( h^4 ).

Add these two equations and we we get

   y( x + h) - y(x) + y(x - h) - y(x)  = h^2  y '' (x) + 0 ( h^4 ).

Thus,

    y ''(x) is replaced by the difference   (y(x+h)-2*y(x)+y(x-h))/(h^2)   and this is good with order 0 ( h^2 ).

We now work three problems. The first two were worked in Meade's Unit 18. We follow his syntax almost in the manner of "cut and paste."  In this Section 8.1, before the problems are finished we will have restated each of them as a matrix problem.

Example 1

Consider the boundary value problem

>    ode1:=diff(y(x),x$2)+2*diff(y(x),x)-10*y(x)=7*exp(-x)+4;
bc1:=y(0)=2,y(1)=-5;

ode1 := diff(y(x),`$`(x,2))+2*diff(y(x),x)-10*y(x) = 7*exp(-x)+4

bc1 := y(0) = 2, y(1) = -5

with boundary conditions specified at the points

>    a:=0;
b:=1;

a := 0

b := 1

To find the finite difference solution associated with this boundary value problem, Meade chooses 11 mesh points from a to b. He replaces the derivatives as we indicated above and shows graphically what a good approximation this makes to the exact solution. See his Unit 18.

Rather than repeat what he has done, we choose only 6 mesh points and emphasize the structure of the resulting equations to be solved. We will find there is a tridiagonal matrix associated with the analysis. We proceed. Choose N.

>    N:=5;

N := 5

This defines h and enables us to compute the X mesh.

>    h:=(b-a)/N;
X:=k->a+k*h;

h := 1/5

X := proc (k) options operator, arrow; a+k*h end proc

Next, we define the finite difference replacement terms.

>    Yp:=k->(y[k+1]-y[k-1])/2/h;
Ypp:=k->(y[k+1]-2*y[k]+y[k-1])/h^2;

Yp := proc (k) options operator, arrow; 1/2*(y[k+1]-y[k-1])/h end proc

Ypp := proc (k) options operator, arrow; (y[k+1]-2*y[k]+y[k-1])/h^2 end proc

The boundary conditions provide two equations.

>    eq[0]:=y[0]=rhs(bc1[1]);
eq[N]:=y[N]= rhs(bc1[2]);

eq[0] := y[0] = 2

eq[5] := y[5] = -5

Here are the remaining N-1 equations for the values at the interior mesh points. We make these equations by replacing

                             y '(x) and y ''(x).

>    for k from 1 to N-1 do
   eq[k]:=eval(ode1,{x=X(k),y(x)=y[k],
        diff(y(x),x)=Yp(k),diff(y(x),x$2)=Ypp(k)});
od;

eq[1] := 30*y[2]-60*y[1]+20*y[0] = 7*exp(-1/5)+4

eq[2] := 30*y[3]-60*y[2]+20*y[1] = 7*exp(-2/5)+4

eq[3] := 30*y[4]-60*y[3]+20*y[2] = 7*exp(-3/5)+4

eq[4] := 30*y[5]-60*y[4]+20*y[3] = 7*exp(-4/5)+4

>   

This system of N+1 equations can be realized in a tridiagonal matrix equation. The matrix will need N+1 rows. The first one comes from the boundary condition at x = a.

>    s[0]:=[1,seq(0,p=1..N)];

s[0] := [1, 0, 0, 0, 0, 0]

The next N-1 rows come from the interior mesh points.

>    for n from 1 to N-1 do
   s[n]:=[seq(0,p=1..n-1),
coeff(lhs(eq[n]),y[n-1]),
coeff(lhs(eq[n]),y[n]),
coeff(lhs(eq[n]),y[n+1]),
seq(0,p=1..N-1-n)];
od;

s[1] := [20, -60, 30, 0, 0, 0]

s[2] := [0, 20, -60, 30, 0, 0]

s[3] := [0, 0, 20, -60, 30, 0]

s[4] := [0, 0, 0, 20, -60, 30]

Finally, there is the last row that comes from the boundary condition at x = b.

>    s[N]:=[seq(0,p=1..N),1];

s[5] := [0, 0, 0, 0, 0, 1]

Now, we write this as a matrix. We list out the rows together.

>    rose:=[s[0],seq(s[n],n=1..N-1),s[N]];

rose := [[1, 0, 0, 0, 0, 0], [20, -60, 30, 0, 0, 0], [0, 20, -60, 30, 0, 0], [0, 0, 20, -60, 30, 0], [0, 0, 0, 20, -60, 30], [0, 0, 0, 0, 0, 1]]

We construct the matrix with these rows. Note that A is a tridiagonal matrix.

>    A:=Matrix(rose);

A := Matrix(%id = 16204992)

Here are the unknown values y[1], y[2] , ... , y[N] .

>    Y:=Vector([seq(y[p],p=0..N)]);

Y := Vector(%id = 15960992)

Here is the right hand side of the equations written as a column vector.

>    V:=Vector([rhs(bc1[1]),seq(rhs(eq[p]),p=1..N-1),rhs(bc1[2])]);

V := Vector(%id = 15961432)

Finally, here is the equation to be solve for y.

>    A.Y=V;

Vector(%id = 15963192) = Vector(%id = 15961432)

There are many ways to solve matrix equations. We leave this up to Maple.

>    Y:=LinearSolve(A,V);

Y := Vector(%id = 15964632)

In an attempt to make these numbers understandable by humans, we give a listing.

>    result:=eval([seq([X(k-1),evalf(Y[k],5)],k=1..N+1)]);

result := [[0, 2.], [1/5, -.15936], [2/5, -1.3277], [3/5, -2.2594], [4/5, -3.3722], [1, -5.]]

It will be interesting to compare how good this approximation is with the exact solution. The approximation may be improved by rerunning this example and increasing the size of N.
We draw graphs. First, compute the exact solution.

>    sol1:=combine(dsolve({ode1,bc1},y(x)));

sol1 := y(x) = 1/55*(-253*exp(11^(1/2))-167*exp(-1)+35*exp(-1+11^(1/2)))/(exp(2*11^(1/2))-1)*exp((-1+11^(1/2))*x+1)+1/55*(253-35*exp(-1)+167*exp(-1+11^(1/2)))/(exp(2*11^(1/2))-1)*exp(-(1+11^(1/2))*x+11...
sol1 := y(x) = 1/55*(-253*exp(11^(1/2))-167*exp(-1)+35*exp(-1+11^(1/2)))/(exp(2*11^(1/2))-1)*exp((-1+11^(1/2))*x+1)+1/55*(253-35*exp(-1)+167*exp(-1+11^(1/2)))/(exp(2*11^(1/2))-1)*exp(-(1+11^(1/2))*x+11...

Next, we superimpose the exact solution with this approximation.

>    plot([rhs(sol1),result],x=a..b,
  color=[BLACK,GREEN],thickness=[1,3],
  legend=[`exact`,`finite difference`]);

[Maple Plot]

Now a bad fit, yes? I say again, you might go back and increase the size of N to improve the approximation.

Example 2

Here is the second example from Meade's Unit 18. We make modifications to see it as a tridiagonal matrix again.

The boundary value problem in this example does not have constant coefficients.

>    ode2:=x^2*diff(y(x),x$2)+x*diff(y(x),x)+4*y(x)=-2*x+7;

>    bc2:=y(1)=7,y(4)=-1;

ode2 := x^2*diff(y(x),`$`(x,2))+x*diff(y(x),x)+4*y(x) = -2*x+7

bc2 := y(1) = 7, y(4) = -1

The boundary conditions are given at

>    a:=1;

>    b:=4;

a := 1

b := 4

Here is where we choose the number of mesh points. The number of mesh points will be N+1.

>    N:=5;

N := 5

The interval over which we approximate this equation is [a, b] and for this interval, we have defined the step size.

>    h:=(b-a)/N;

h := 3/5

Here are the mesh points.

>    X:=k->a+k*h;

X := proc (k) options operator, arrow; a+k*h end proc

The replacement operators are as they were explained in the discussion above.

>    Yp:=k->(y[k+1]-y[k-1])/(2*h);

Yp := proc (k) options operator, arrow; 1/2*(y[k+1]-y[k-1])/h end proc

>    Ypp:=k->(y[k+1]-2*y[k]+y[k-1])/h^2;

Ypp := proc (k) options operator, arrow; (y[k+1]-2*y[k]+y[k-1])/h^2 end proc

The boundary conditions provide two equations.

>    eq[0]:=y[0]=rhs(bc2[1]);
eq[N]:=y[N]= rhs(bc2[2]);

eq[0] := y[0] = 7

eq[5] := y[5] = -1

Here are the remaining N-1 equations for the values at the interior mesh points. We make these equations by replacing

                             y '(x) and y ''(x).

>    for k from 1 to N-1 do
   eq[k]:=eval(ode2,{x=X(k),y(x)=y[k],
          diff(y(x),x)=Yp(k),diff(y(x),x$2)=Ypp(k)} );
od;

eq[1] := 76/9*y[2]-92/9*y[1]+52/9*y[0] = 19/5

eq[2] := 275/18*y[3]-206/9*y[2]+209/18*y[1] = 13/5

eq[3] := 217/9*y[4]-356/9*y[3]+175/9*y[2] = 7/5

eq[4] := 629/18*y[5]-542/9*y[4]+527/18*y[3] = 1/5

We realize this system of N+1 equations as tridiagonal matrix equation. The matrix will need N+1 rows. The first one comes from the boundary condition at x = a.

>    s[0]:=[1,seq(0,p=1..N)];

s[0] := [1, 0, 0, 0, 0, 0]

The next N-1 rows come from the interior mesh points.

>    for n from 1 to N-1 do
   s[n]:=[seq(0,p=1..n-1),
coeff(lhs(eq[n]),y[n-1]),
coeff(lhs(eq[n]),y[n]),
coeff(lhs(eq[n]),y[n+1]),
seq(0,p=1..N-1-n)];
od;

s[1] := [52/9, -92/9, 76/9, 0, 0, 0]

s[2] := [0, 209/18, -206/9, 275/18, 0, 0]

s[3] := [0, 0, 175/9, -356/9, 217/9, 0]

s[4] := [0, 0, 0, 527/18, -542/9, 629/18]

Finally, there is the last row that comes from the boundary condition at x = b.

>    s[N]:=[seq(0,p=1..N),1];

s[5] := [0, 0, 0, 0, 0, 1]

Now, we write this as a matrix. We list out the rows together.

>    rose:=[s[0],seq(s[n],n=1..N-1),s[N]];

rose := [[1, 0, 0, 0, 0, 0], [52/9, -92/9, 76/9, 0, 0, 0], [0, 209/18, -206/9, 275/18, 0, 0], [0, 0, 175/9, -356/9, 217/9, 0], [0, 0, 0, 527/18, -542/9, 629/18], [0, 0, 0, 0, 0, 1]]

We construct the matrix with these rows.

>    A:=Matrix(rose);

A := Matrix(%id = 16723940)

Here are the unknown values y[1], y[2] , ... , y[N] .

>    Y:=Vector([seq(y[p],p=0..N)]);

Y := Vector(%id = 3098768)

Here is the right hand side of the equations written as a column vector.

>    V:=Vector([rhs(bc2[1]),seq(rhs(eq[p]),p=1..N-1),rhs(bc2[2])]);

V := Vector(%id = 17568612)

Finally, here is the equation to be solve for y.

>    A.Y=V;

Vector(%id = 20435160) = Vector(%id = 17568612)

Maple will solve this system for us.

>    Y:=LinearSolve(A,V);

Y := Vector(%id = 16724712)

We reprint for humans.

>    result:=eval([seq([X(k-1),evalf(Y[k],5)],k=1..N+1)]);

result := [[1, 7.], [8/5, 13.196], [11/5, 11.635], [14/5, 7.5723], [17/5, 3.0978], [4, -1.]]


Finally, we draw graphs. First, compute the exact solution.

>    sol2:=combine(dsolve({ode2,bc2},y(x)));

sol2 := y(x) = 1/20*(-23*sin(2*ln(x))-113*sin(2*ln(x)-4*ln(2))+35*sin(4*ln(2))-8*x*sin(4*ln(2)))/sin(4*ln(2))

Next, we superimpose the exact solution with this approximation.

>    plot([rhs(sol2),result],x=a..b,
   color=[BLACK,GREEN], thickness=[1,3],
   legend=[`exact`,`finite difference`]);

[Maple Plot]

The fit with N = 5 is not as good as we would have liked. Going back and increasing N is irresistible.

Example 3

This example differs from the previous two in that the boundary condition at the right hand side involves the derivative of y, instead of the value of y. Also, we make the right hand side of the equation not continuous.

Here is the example: we seek a graph for a function y(x) that satisfies

            diff(y(x),`$`(x,2))  - 3 y(x) = f(x)

with

boundary conditions y(-1) = 1 and y '(1) = -1. The function f is indicated below.

To the extent possible, we follow the pattern of the previous two examples.

We use a second order differential equation with forcing function f.

>    ode3:=diff(y(x),x$2)-9*y(x)=f(x);
bc3:=y(-1)=1,D(y)(1)=-1;

ode3 := diff(y(x),`$`(x,2))-9*y(x) = f(x)

bc3 := y(-1) = 1, D(y)(1) = -1

>    f:=x->(1-signum(x))/2;

f := proc (x) options operator, arrow; 1/2-1/2*signum(x) end proc

The boundary conditions are given at

>    a:=-1;

>    b:=1;

a := -1

b := 1

Here is where we choose the number of mesh points. The number of mesh points will be N+1.

>    N:=9;

N := 9

The interval over which we approximate this equation is [a, b] and for this interval, we have defined the step size.

>    h:=(b-a)/N;

h := 2/9

Here are the mesh points.

>    X:=k->a+k*h;

X := proc (k) options operator, arrow; a+k*h end proc

The replacement operators are as they were explained in the discussion above.

>    Yp:=k->(y[k+1]-y[k-1])/(2*h);

Yp := proc (k) options operator, arrow; 1/2*(y[k+1]-y[k-1])/h end proc

>    Ypp:=k->(y[k+1]-2*y[k]+y[k-1])/h^2;

Ypp := proc (k) options operator, arrow; (y[k+1]-2*y[k]+y[k-1])/h^2 end proc

Of course, the boundary condition at a  provides an equation of the same character as in the previous two examples. The boundary condition at b  needs some discussion.

>    eq[0]:=y[0]=rhs(bc3[1]);

eq[0] := y[0] = 1

>   

Here, we explain how to get equation N from the boundary condition at the right hand endpoint, b . Our replacement scheme for the derivative at b  = 1 = X[N]   should be

                  (Y[N+1]-Y[N-1])/(2*h)   =  -1.

However, the sequence of Y 's runs only from Y[0]  to Y[N]  . Thus we get eq[N]  in the following manner. From the previous line, we get that

           Y[N+1]  = Y[n-1]  - 2 h .

If we followed the discrete replacement scheme at X[N] , we would have

        (Y[N+1]-2*Y[N]+Y[N-1])/(h^2)   - 9 Y[N]   = f( X[N]  ).

Again, this has a value of Y , namely Y[N+1] , that we do not use. It is replaced by the value of Y[N+1]  that we got from the boundary condition to yield

       (Y[N-1]-2*h-2*Y[N]+Y[N-1])/(h^2)   - 9 Y[N]   = f( X[N]  ).
This defines
eq[N] .

>    eq[N]:=simplify((y[N-1]-2*y[N]+y[N-1])/h^2-9*y[N]=
       f(X(N))+2/h);

eq[9] := 81/2*y[8]-99/2*y[9] = 9

Here are the remaining N-1 equations for the values at the interior mesh points. We make these equations by replacing

                             y '(x) and y ''(x).

>    for k from 1 to N-1 do
   eq[k]:=eval(ode3,{x=X(k),y(x)=y[k],
          diff(y(x),x)=Yp(k),diff(y(x),x$2)=Ypp(k)} );
od;

eq[1] := 81/4*y[2]-99/2*y[1]+81/4*y[0] = 1

eq[2] := 81/4*y[3]-99/2*y[2]+81/4*y[1] = 1

eq[3] := 81/4*y[4]-99/2*y[3]+81/4*y[2] = 1

eq[4] := 81/4*y[5]-99/2*y[4]+81/4*y[3] = 1

eq[5] := 81/4*y[6]-99/2*y[5]+81/4*y[4] = 0

eq[6] := 81/4*y[7]-99/2*y[6]+81/4*y[5] = 0

eq[7] := 81/4*y[8]-99/2*y[7]+81/4*y[6] = 0

eq[8] := 81/4*y[9]-99/2*y[8]+81/4*y[7] = 0

We realize this system of N+1 equations as tridiagonal matrix equation. The matrix will need N+1 rows. The first one comes from the boundary condition at x = a.

>    s[0]:=[1,seq(0,p=1..N)];

s[0] := [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

The next N-1 rows come from the interior mesh points.

>    for n from 1 to N-1 do
   s[n]:=[seq(0,p=1..n-1),
coeff(lhs(eq[n]),y[n-1]),
coeff(lhs(eq[n]),y[n]),
coeff(lhs(eq[n]),y[n+1]),
seq(0,p=1..N-1-n)];
od;

s[1] := [81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0, 0]

s[2] := [0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0]

s[3] := [0, 0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0]

s[4] := [0, 0, 0, 81/4, -99/2, 81/4, 0, 0, 0, 0]

s[5] := [0, 0, 0, 0, 81/4, -99/2, 81/4, 0, 0, 0]

s[6] := [0, 0, 0, 0, 0, 81/4, -99/2, 81/4, 0, 0]

s[7] := [0, 0, 0, 0, 0, 0, 81/4, -99/2, 81/4, 0]

s[8] := [0, 0, 0, 0, 0, 0, 0, 81/4, -99/2, 81/4]

Finally, there is the last row that comes from the boundary condition at x = b.

>    s[N]:=[seq(0,p=1..N-2),coeff(lhs(eq[N]),y[N-2]),
        coeff(lhs(eq[N]),y[N-1]),coeff(lhs(eq[N]),y[N])];

s[9] := [0, 0, 0, 0, 0, 0, 0, 0, 81/2, -99/2]

Now, we write this as a matrix. We list out the rows together.

>    rose:=[s[0],seq(s[n],n=1..N-1),s[N]];

rose := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0, 0], [0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0], [0, 0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0], [0, 0, 0, 81/4, -99/2, 81/4, 0, 0,...
rose := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0, 0], [0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0], [0, 0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0], [0, 0, 0, 81/4, -99/2, 81/4, 0, 0,...
rose := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0, 0], [0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0, 0], [0, 0, 81/4, -99/2, 81/4, 0, 0, 0, 0, 0], [0, 0, 0, 81/4, -99/2, 81/4, 0, 0,...

We construct the matrix with these rows.

>    A:=Matrix(rose);

A := Matrix(%id = 2945520)

Here are the unknown values y[1], y[2] , ... , y[N] .

>    Y:=Vector([seq(y[p],p=0..N)]);

Y := Vector(%id = 19880268)

Here is the right hand side of the equations written as a column vector.

>    V:=Vector([rhs(bc3[1]),seq(rhs(eq[p]),p=1..N-1),rhs(eq[N])]);

V := Vector(%id = 19880348)

Finally, here is the equation to be solve for y.

>    A.Y=V;

Vector(%id = 16444644) = Vector(%id = 19880348)

Maple will solve this system for us.

>    Y:=LinearSolve(A,V);

Y := Vector(%id = 19880628)

We reprint for humans.

>    result:=eval([seq([X(k-1),evalf(Y[k],5)],k=1..N+1)]);

result := [[-1, 1.], [-7/9, .46877], [-5/9, .19526], [-1/3, .57923e-1], [-1/9, -.42913e-2], [1/9, -.19030e-1], [1/3, -.42226e-1], [5/9, -.84189e-1], [7/9, -.16357], [1, -.31565]]
result := [[-1, 1.], [-7/9, .46877], [-5/9, .19526], [-1/3, .57923e-1], [-1/9, -.42913e-2], [1/9, -.19030e-1], [1/3, -.42226e-1], [5/9, -.84189e-1], [7/9, -.16357], [1, -.31565]]


Finally, we draw graphs. First, compute the exact solution.

>    sol3:=combine(dsolve({ode3,bc3},y(x)));

sol3 := y(x) = PIECEWISE([(-1/18*exp(3*x+6)+1/18*exp(3*x+12)-1/3*exp(3*x+9)+10/9*exp(3*x+3)+1/18*exp(-3*x)+10/9*exp(-3*x+9)-1/18*exp(-3*x+6)+1/3*exp(-3*x+3)-1/9-1/9*exp(12))/(1+exp(12)), x <= 0],[(-1/1...
sol3 := y(x) = PIECEWISE([(-1/18*exp(3*x+6)+1/18*exp(3*x+12)-1/3*exp(3*x+9)+10/9*exp(3*x+3)+1/18*exp(-3*x)+10/9*exp(-3*x+9)-1/18*exp(-3*x+6)+1/3*exp(-3*x+3)-1/9-1/9*exp(12))/(1+exp(12)), x <= 0],[(-1/1...
sol3 := y(x) = PIECEWISE([(-1/18*exp(3*x+6)+1/18*exp(3*x+12)-1/3*exp(3*x+9)+10/9*exp(3*x+3)+1/18*exp(-3*x)+10/9*exp(-3*x+9)-1/18*exp(-3*x+6)+1/3*exp(-3*x+3)-1/9-1/9*exp(12))/(1+exp(12)), x <= 0],[(-1/1...
sol3 := y(x) = PIECEWISE([(-1/18*exp(3*x+6)+1/18*exp(3*x+12)-1/3*exp(3*x+9)+10/9*exp(3*x+3)+1/18*exp(-3*x)+10/9*exp(-3*x+9)-1/18*exp(-3*x+6)+1/3*exp(-3*x+3)-1/9-1/9*exp(12))/(1+exp(12)), x <= 0],[(-1/1...

Next, we superimpose the exact solution with this approximation.

>    plot([rhs(sol3),result],x=-1..1,
   color=[BLACK,GREEN], thickness=[1,3],
   legend=[`exact`,`finite difference`]);

[Maple Plot]

>   

If you don't think this fit is pretty good, go back and make N larger. Try N = 9.

This review of the finite difference methods, or discrete replacement methods, for boundary value problems in differential equations was made to suggest the techniques for partial differential equations. We examine these next.

EMAIL: herod@math.gatech.edu   or   jherod@tds.net

URL: http://www.math.gatech.edu/~herod

Copyright ©  2003  by James V. Herod

All rights reserved