搜索内容 搜索用户

# 34 麦片

050

5主题 0最佳答案
楼主| 发表于 2020-5-28 22:58:42 | 显示全部楼层 |阅读模式
 help pdepe中自带的两个例子，复制代码后运行报错： 错误使用 pdepe 输入参数太多。 出错 pdex11 (line 7) sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); 复制的代码如下： function pdex11m = 0;x = linspace(0,1,20);t = linspace(0,2,5);sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);% Extract the first solution component as u.u = sol(:,:,1);% A surface plot is often a good way to study a solution.surf(x,t,u) title('Numerical solution computed with 20 mesh points.')xlabel('Distance x')ylabel('Time t')% A solution profile can also be illuminating.figureplot(x,u(end,:))title('Solution at t = 2')xlabel('Distance x')ylabel('u(x,2)')% --------------------------------------------------------------function [c,f,s] = pdex1pde(x,t,u,DuDx)c = pi^2;f = DuDx;s = 0;% --------------------------------------------------------------function u0 = pdex1ic(x)u0 = sin(pi*x);% --------------------------------------------------------------function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)pl = ul;ql = 0;pr = pi * exp(-t);qr = 1;

# 34 麦片

050

5主题 0最佳答案
楼主| 发表于 2020-5-28 23:04:32 | 显示全部楼层
 function pdex11 m = 0; x = linspace(0,1,20); t = linspace(0,2,5); sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); % Extract the first solution component as u. u = sol(:,:,1); % A surface plot is often a good way to study a solution. surf(x,t,u) title('Numerical solution computed with 20 mesh points.') xlabel('Distance x') ylabel('Time t') % A solution profile can also be illuminating. figure plot(x,u(end,:)) title('Solution at t = 2') xlabel('Distance x') ylabel('u(x,2)') % -------------------------------------------------------------- function [c,f,s] = pdex1pde(x,t,u,DuDx) c = pi^2; f = DuDx; s = 0; % -------------------------------------------------------------- function u0 = pdex1ic(x) u0 = sin(pi*x); % -------------------------------------------------------------- function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t) pl = ul; ql = 0; pr = pi * exp(-t); qr = 1;

# 论坛优秀回答者

5主题 743最佳答案
• 关注者： 209

 没啥问题啊 你要是没把几个 function 对应的代码单独储存成对应的m文件 那就的在每个function结束的地方加上对应的 end clear; clc; close all; m = 0; x = linspace(0,1,20); t = linspace(0,2,5); sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); % Extract the first solution component as u. u = sol(:,:,1); % A surface plot is often a good way to study a solution. surf(x,t,u) title('Numerical solution computed with 20 mesh points.') xlabel('Distance x') ylabel('Time t') % A solution profile can also be illuminating. figure plot(x,u(end,:)) title('Solution at t = 2') xlabel('Distance x') ylabel('u(x,2)') % -------------------------------------------------------------- function [c,f,s] = pdex1pde(x,t,u,DuDx) c = pi^2; f = DuDx; s = 0; end % -------------------------------------------------------------- function u0 = pdex1ic(x) u0 = sin(pi*x); end % -------------------------------------------------------------- function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t) pl = ul; ql = 0; pr = pi * exp(-t); qr = 1; end复制代码

# 34 麦片

050

5主题 0最佳答案
楼主| 发表于 2020-5-29 11:34:19 | 显示全部楼层
 感谢解答，但是还是存在问题 1. 加上end后仍然报相同的错 2. 我把之前的代码给同学运行，他就能跑通 是不是我软件有问题。。。(但是我下载的我们学校提供的正版的啊 )

 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页