linearode

<< Click to Display Table of Contents >>

Navigation:  Sample Problems > Usage > ODE >

linearode

Previous pageReturn to chapter overviewNext page

{ 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.

 

 Since FlexPDE requires a spatial domain, we solve the system over  

 a simple box with minimum mesh size.

 

}  

 

title  

"FIRST ORDER ORDINARY DIFFERENTIAL EQUATION"  

 

select  

{ Since no spatial information is required, use the minimum grid }  

 ngrid=1                  

 errlim = 1e-4  

 

variables  

{ declare Height to be the system variable }  

 Height(threshold=1)      

 

definitions                

{ define the equation parameters }  

 a = 2                    

 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  

 Height : 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 by 10 to 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