LinearODE

Top  Previous  Next

{ LINEARODE.PDE }

 

{ *************************************************************

 

This example shows the application of FlexPDE to the solution of a linear

first-order differential equation.

 

We select the simple example

 

    dH/dt = a - b*H

 

This equation has the exact solution

 

    H(t) = H(0)*exp(-b*t) + (a/b)*[1-exp(-b*t)]

 

The existence of an exact solution allows us to analyze the errors

in the FlexPDE solution.

 

************************************************************* }

 

title

"FIRST ORDER ORDINARY DIFFERENTIAL EQUATION"

 

select

ngrid=1                       { Since no spatial information is required,

                                 use the minimum grid }

errlim = 1e-4

 

variables

Height(threshold=1)           { declare Height to be the system variable }

 

definitions

a = 2                         { define the equation parameters }

b = 0.1

H0 = 100

                               { define the exact solution: }

Hexact = H0*exp(-b*t) + (a/b)*(1-exp(-b*t))

 

initial values

Height = H0

 

equations

dt(Height)  = a - b*Height    { The ODE }

 

boundaries

region 1

start (0,0)

line to (1,0) to (1,1) to (0,1) to close

 

time 0 to 100

 

plots

for time = 0,1,10,100

                               { Plot the solution: }

history(Height) at (0.5,0.5)

                               { Plot the error check: }

history((Height-Hexact)/Hexact) at (0.5,0.5) as "Relative Error"

 

end