微分方程在建模中的应用

微分方程在建模中的应用
在温度扩散和浓度扩散模型中,微分方程形式为y'+g(x)*y=g(x)*f(x),目前我们假定g(x),f(x)均为常量,并且有g(x)=k,f(x)=m,下面解答这个方程并验证;
y'+k*y=k*m  (k,m为常量)
GO
采用标准解法有:
{ C*e^(kx) *  y}'=C*e^(kx)*k*m
GO
y=A+B*e^(-kx)
假设初始值y(0)=2,y(1)=1,k=1
2=A+B
1=A+B*e^(-1)
Go
A=(1-2e)/(1-e)
B=e/(e-1)
注意将y=A+B*e^(-kx)回代入原方程中有ka=km,所以m=a




下面写程序来证明:
(setq  k  1)
(setq  b  (/ e
             (- e  1)))
(setq  a  (- 2 b))
(setq  m  a)


(defun pow (num count)
(if (or (> count 1) (eq  count  1) )
      (* num 
         (pow num 
              (- count 1) ) )
      1))


(defun slayer ( count)
(if (or (> count 1) (eq  count  1) )
      (* count 
         (slayer  
              (- count 1) ) )
      1))


(defun slayerex (num count)
(if (or (> count 1) (eq  count  1) )
      (* num 
         (slayerex 
              (-  num  1) 
              (- count 1) ) )
      1))




(defun  expr (x1 y1 )
(+  y1
    (*  1
        (-  (* k m)
            (* k y1)))))


(defun  calc (n x)
(if  (eq  n  0)
       1.0
    (+ (calc (1- n)
             x)
       (*  (pow  x  
                 n)
           (/    1
                 (slayer n))))))


(setq  e  (calc 10  1))
     


(defun  formula  (x)
(+   (*  b
         (/  1
             (pow e (* k  
                       x))))
     a))




(defun  exprhelp (x1 )
(if (< (abs (-  x1  0))
       0.1)
        (formula  0)
    (expr  x1  
           (exprhelp  (-  x1  
                          1)))))                  


(defun  test (n)
(if (or (>  n 0) (eq  n  0))
  (progn 
       (print (exprhelp n))
       (print  'compare)
       (print (formula n))      
       (test (- n 1)))
  (print 'over)))


[85]> (test  30)


0.48508513
COMPARE
0.41802335
0.49253646
COMPARE
0.41802335
0.5008157
COMPARE
0.41802335
0.51001483
COMPARE
0.41802335
0.52023613
COMPARE
0.41802335
0.5315931
COMPARE
0.41802335
0.5442119
COMPARE
0.41802335
0.5582329
COMPARE
0.41802335
0.57381177
COMPARE
0.41802335
0.5911216
COMPARE
0.41802335
0.6103548
COMPARE
0.41802335
0.63172495
COMPARE
0.41802335
0.6554696
COMPARE
0.41802338
0.6818525
COMPARE
0.4180234
0.71116686
COMPARE
0.41802353
0.74373835
COMPARE
0.41802382
0.7799289
COMPARE
0.41802466
0.82014066
COMPARE
0.41802692
0.86482036
COMPARE
0.41803306
0.9144645
COMPARE
0.41804978
0.9696246
COMPARE
0.41809517
1.0309136
COMPARE
0.41821858
1.0990125
COMPARE
0.41855404
1.174678
COMPARE
0.41946593
1.2587507
COMPARE
0.42194468
1.3521649
COMPARE
0.42868263
1.4559584
COMPARE
0.44699824
1.5712844
COMPARE
0.4967853
1.6994245
COMPARE
0.6321206
1.8418024
COMPARE
1.0
2.0
COMPARE
2.0
OVER
OVER
1.这里有个问题,关于m和a的关系问题,在解微分方程的过程中需要涉及到换元问题,有的时候需要回代获得忽略的关系;
2.在这里的数值解法相当于差分方程的解法,因为取的步长为1,误差比较大;从这里也可以看出差分与微分的区别所在了;
下面是减少间距后的测试结果
(defun  exprhelp (x1 )
(if (< (abs (-  x1  0))
       0.1)
        (formula  0)
    (expr  x1  
           (exprhelp  (-  x1  
                          0.1)))))   
[87]> (test  30)


0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802335
0.41802347
COMPARE
0.41802338
0.41802347
COMPARE
0.4180234
0.41802347
COMPARE
0.41802353
0.41802362
COMPARE
0.41802382
0.41802403
COMPARE
0.41802466
0.41802537
COMPARE
0.41802692
0.41802904
COMPARE
0.41803306
0.41803962
COMPARE
0.41804978
0.41807005
COMPARE
0.41809517
0.41814384
COMPARE
0.41821858
0.41836894
COMPARE
0.41855404
0.41901457
COMPARE
0.41946593
0.42086616
COMPARE
0.42194468
0.4261765
COMPARE
0.42868263
0.44140634
COMPARE
0.44699824
0.48508513
COMPARE
0.4967853
0.63172495
COMPARE
0.6321206
1.0309136
COMPARE
1.0
2.0
COMPARE
2.0
OVER
OVER
可以看出基本没有误差了;       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值