matlab实现图灵斑图与反应扩散方程动态图

本文介绍了使用Laplacian算子和扩散方程实现的二维动态系统,通过my_laplacian函数计算邻域影响,模拟了物质扩散过程。初始条件设定后,通过迭代模拟了进料率、去除率和扩散速率对系统行为的影响,并以图像形式展示结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考链接:https://blog.csdn.net/weixin_30278943/article/details/112067158

function out = my_laplacian(in)
out = -in + .20*(circshift(in,[ 1, 0]) + circshift(in,[-1, 0])...
    + circshift(in,[ 0, 1]) + circshift(in,[ 0,-1]))...
    + .05*(circshift(in,[ 1, 1]) + circshift(in,[-1, 1])...
    + circshift(in,[-1,-1]) + circshift(in,[ 1,-1]));
end
function [t, A, B] = initial_conditions(n)
t = 0;
A = ones(n);
B = zeros(n);
B(51:60 ,51:70) = 1;
B(61:80,71:80) = 1;
end
clc
clear all
close all

% 设置系数值
f=0.055;   %进料率
k=0.062;   %去除率
da = 1.0;  %U的扩散率
db = 0.5;  %V的扩散率
% 网格的大小
width = 128;
%5,000个模拟秒,每模拟秒4步
dt = 0.25;
stoptime = 5000;

% 初始化矩阵
[t, A, B] = initial_conditions(width);
% 运行主程序
tic
nframes = 1;
while t<stoptime
    anew = A + (da*my_laplacian(A) - A.*B.^2 + f*(1-A))*dt;
    bnew = B + (db*my_laplacian(B) + A.*B.^2 - (k+f)*B)*dt;
    A = anew;
    B = bnew;
    t = t+dt;
    nframes = nframes+1;
end

%画图
figure('name','Tuling')
axis off
hi = image(B);
hi.CDataMapping ='scaled';
colorbar;
hold on

delta = toc;
disp([num2str(nframes) 'frames in ' num2str(delta) ' seconds']);

在这里插入图片描述

clc
clear all
close all

% 设置系数值
f=0.055;   %进料率
k=0.062;   %去除率
da = 1.0;  %U的扩散率
db = 0.5;  %V的扩散率
% 网格的大小
width = 128;
%5,000个模拟秒,每模拟秒4步
dt = 0.25;
stoptime = 5000;

% 初始化矩阵
[t, A, B] = initial_conditions(width);

targetframerate = 24;

frametime = 1/(24*60*60*targetframerate);

nextframe = now + frametime;

tic

nframes = 1;

B_cell = cell(0);
while t<stoptime
    anew = A + (da*my_laplacian(A) - A.*B.^2 + f*(1-A))*dt;
    bnew = B + (db*my_laplacian(B) + A.*B.^2 - (k+f)*B)*dt;
    A = anew;
    B = bnew;
    B_cell(nframes)={B};
    t = t+dt;
    ht.String = ['Time = ' num2str(t)];
        if now > nextframe
            drawnow
            nextframe = now + frametime;
        end
    nframes = nframes+1;
end
delta = toc;
disp([num2str(nframes) ' frames in ' num2str(delta) ' seconds'])

figure('name','Tuling')
imageB = B_cell{1};
h=image('CData',imageB);
h.CDataMapping = 'scaled';
colorbar;
hold on
for i=5:5:20000
    cell_B = B_cell{i};
    set(h,'CData', cell_B);
    drawnow;
end
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值