函数·分析·方程版 #466801 层

FlexPDE求解一阶微分方程和非线性方程实例

楼主 · 1 楼
用FlexPDE做一阶微分方程

选择一阶微分方程: dH/dt = a - b*H
化解之后得到精确解: H(t) = H(0)*exp(-b*t) + (a/b)*[1-exp(-b*t)]



在FlexPDE中根据精确解输入代码:

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 235251124



FlexPDE求解非线性方程


选择黏性流中的一个方城: dH/dt = a - b*sqrt(H)
解析解满足关系式: sqrt(H0) + (a/b)ln[a-b*sqrt(H0)] - sqrt(H) - (a/b)ln[a-b*sqrt(H)] = (b/2)*t


在FlexPDE中根据关系式输入代码(具体代码如下):


title
"NONLINEAR FIRST ORDER ORDINARY DIFFERENTIAL EQUATION"

select
ngrid=1 { Since there is no spatial information required,
use the minimum grid size }

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 accuracy check }
T0 = sqrt(H0) + (a/b)*ln(a-b*sqrt(H0))
Tcheck = sqrt(Height) + (a/b)*ln(a-b*sqrt(Height))

initial values
Height = H0

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

boundaries
region 1 { define a fictitious spatial domain }
start (0,0)
line to (1,0) to (1,1) to (0,1) to close

time 0 to 1000 { define the time range }

histories
{ Plot the solution: }
history(Height) at (0.5,0.5)
{ Plot the accuracy check: }
history([T0 - Tcheck - (b/2)*t]/[(b/2)*t]) at (0.5,0.5)
as "Relative Error"

end 14185
4607

附件为非线性方程的结果图。


申请FlexPDE免费试用光盘请登入中国科研软件网(www.SoftSale.cn)
您也可以在中国科研软件论坛(forum.SoftSale.cn)获得更多关于FlexPDE的资料

user posted image



user posted image

user posted image