微分方程组的数值模拟
例:某湖泊中有机物新城代谢系统模型的状态方程组
时间 t 是以年为单位,Xs 表示 t 时刻太阳提供的能量,Xp 表示 t 时刻植物生长的数 量,Xh 表示吞食植物的虫类生成数量;Xr 为 t 时刻食虫植物的生长数量;Xo 表示 t 时 刻湖底有机物的沉淀量;Xe 表示 t 时刻已扩散到周围环境的总能量。使用 Matlab 的 ode 命令求解并模拟 1900 年到 2020 年该湖泊每隔 10 年有机物新城代谢情况,Matlab 程序 如下所示:
%微分方程组求解主程序
clc;clear all;clf;close all;
%Windows 时钟自动计时
T1=clock;%Clock 函数返回的值是 clock = [year month day hour minute seconds] disp('计算机正在准备输出湖泊有机物新陈代谢结果,请耐心等待……'); [tt,y]=ode45('lbwfun',[0:10:2020],[95.9,0.83,0.003,0.0001,0.0,0.0]);
t=tt(191:end,:)
ys=y(191:end,1)
yp=y(191:end,2)
yh=y(191:end,3)
yr=y(191:end,4)
yo=y(191:end,5)
ye=y(191:end,6)
T2=clock;
API_elapsed_time=T2-T1;
if API_elapsed_time(6)<0
API_elapsed_time(6)=API_elapsed_time(6)+60;
API_elapsed_time(5)=API_elapsed_time(5)-1;
end
if API_elapsed_time(5)<0
API_elapsed_time(5)=API_elapsed_time(5)+60;
API_elapsed_time(4)=API_elapsed_time(4)-1;
end
str=sprintf('湖泊新陈代谢模拟程序共运行 %d 小时 %d 分钟 %.4f 秒
API_elapsed_time(4),API_elapsed_time(5),API_elapsed_time(6));
disp(str);
微分方程组的子函数&#