查看: 296|回复: 3|关注: 0

[已答复] pdepe自带例子运行错误

[复制链接]

新手

34 麦片

财富积分


050


5

主题

18

帖子

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;
回复主题 已获打赏: 0 积分

举报

新手

34 麦片

财富积分


050


5

主题

18

帖子

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;
回复此楼 已获打赏: 0 积分

举报

论坛优秀回答者

5

主题

2481

帖子

743

最佳答案
  • 关注者: 209
发表于 2020-5-29 10:53:16 | 显示全部楼层
没啥问题啊
你要是没把几个 function 对应的代码单独储存成对应的m文件
那就的在每个function结束的地方加上对应的 end
  1. clear; clc; close all;
  2. m = 0;
  3. x = linspace(0,1,20);
  4. t = linspace(0,2,5);

  5. sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
  6. % Extract the first solution component as u.
  7. u = sol(:,:,1);

  8. % A surface plot is often a good way to study a solution.
  9. surf(x,t,u)
  10. title('Numerical solution computed with 20 mesh points.')
  11. xlabel('Distance x')
  12. ylabel('Time t')

  13. % A solution profile can also be illuminating.
  14. figure
  15. plot(x,u(end,:))
  16. title('Solution at t = 2')
  17. xlabel('Distance x')
  18. ylabel('u(x,2)')
  19. % --------------------------------------------------------------
  20. function [c,f,s] = pdex1pde(x,t,u,DuDx)
  21. c = pi^2;
  22. f = DuDx;
  23. s = 0;
  24. end
  25. % --------------------------------------------------------------
  26. function u0 = pdex1ic(x)
  27. u0 = sin(pi*x);
  28. end
  29. % --------------------------------------------------------------
  30. function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
  31. pl = ul;
  32. ql = 0;
  33. pr = pi * exp(-t);
  34. qr = 1;
  35. end
复制代码
提问请:①准确描述问题②提出你的思考(等着抄作业的一律锁帖)③提供代码文本而非截图④及时反馈
回复此楼 已获打赏: 0 积分

举报

新手

34 麦片

财富积分


050


5

主题

18

帖子

0

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

举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

快速回复 返回顶部 返回列表