声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1994|回复: 0

[工具箱] MATLAB解偏微分方程

[复制链接]
发表于 2016-3-16 14:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本帖最后由 think2015 于 2016-3-16 14:54 编辑
  1. <div style="text-align: center;"><img src="http://forum.vibunion.com/forum.php?mod=image&aid=71816&size=300x300&key=a007c670780730af&nocache=yes&type=fixnone" border="0" aid="attachimg_71816" alt=""></div><div><span style="font-size: 14px; line-height: 1.5;">
  2. </span></div><div><span style="font-size: 14px; line-height: 1.5;">function </span><wbr style="font-size: 14px; line-height: 1.5;"><span style="font-size: 14px; line-height: 1.5;"> </span><wbr style="font-size: 14px; line-height: 1.5;"><span style="font-size: 14px; line-height: 1.5;"> </span><wbr style="font-size: 14px; line-height: 1.5;"><span style="font-size: 14px; line-height: 1.5;"> </span><wbr style="font-size: 14px; line-height: 1.5;"><span style="font-size: 14px; line-height: 1.5;">zzz</span></div><div>
  3. <span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>主函数:</span>
  4. <span style="word-wrap: normal; word-break: normal;">x=0:0.05:1;</span>
  5. <span style="word-wrap: normal; word-break: normal;">t=0:0.05:2;</span>
  6. <span style="word-wrap: normal; word-break: normal;">m=0;</span>
  7. <span style="word-wrap: normal; word-break: normal;">sol=pdepe(m,@pdefun,@pdeic,@pdebc,x,t);</span>
  8. <span style="word-wrap: normal; word-break: normal;">figure('numbertitle','off','name','PDE <wbr>Demo')</span>
  9. <span style="word-wrap: normal; word-break: normal;">subplot(211)</span>
  10. <span style="word-wrap: normal; word-break: normal;">surf(x,t,sol(:,:,1))</span>
  11. <span style="word-wrap: normal; word-break: normal;">title('The <wbr>solution <wbr>of <wbr>u_1')</span>
  12. <span style="word-wrap: normal; word-break: normal;">xlabel('X')</span>
  13. <span style="word-wrap: normal; word-break: normal;">ylabel('T')</span>
  14. <span style="word-wrap: normal; word-break: normal;">zlabel('U')</span>
  15. <span style="word-wrap: normal; word-break: normal;">subplot(212)</span>
  16. <span style="word-wrap: normal; word-break: normal;">surf(x,t,sol(:,:,2))</span>
  17. <span style="word-wrap: normal; word-break: normal;">title('The <wbr>Solution <wbr>of <wbr>u_2')</span>
  18. <span style="word-wrap: normal; word-break: normal;">xlabel('X')</span>
  19. <span style="word-wrap: normal; word-break: normal;">ylabel('T')</span>
  20. <span style="word-wrap: normal; word-break: normal;">zlabel('U')</span>

  21. <span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>目标函数:</span>
  22. <span style="word-wrap: normal; word-break: normal;">function <wbr>[c,f,s]=pdefun(x,t,u,du)</span>
  23. <span style="word-wrap: normal; word-break: normal;">c=[1;1];</span>
  24. <span style="word-wrap: normal; word-break: normal;">f=[0.024*du(1);0.17*du(2)];</span>
  25. <span style="word-wrap: normal; word-break: normal;">temp=u(1)-u(2);</span>
  26. <span style="word-wrap: normal; word-break: normal;">s=[-1;1].*(exp(5.73*temp)-exp(-11.46*temp));</span>

  27. <span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>边界条件:</span>
  28. <span style="word-wrap: normal; word-break: normal;">function <wbr>[pa,qa,pb,qb]=pdebc(xa,ua,xb,ub,t)</span>
  29. <span style="word-wrap: normal; word-break: normal;">pa=[1;ua(2)];</span>
  30. <span style="word-wrap: normal; word-break: normal;">qa=[1;0];</span>
  31. <span style="word-wrap: normal; word-break: normal;">pb=[ub(1)-1;0];</span>
  32. <span style="word-wrap: normal; word-break: normal;">qb=[0;1];</span>

  33. <span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>初值条件:</span>
  34. <span style="word-wrap: normal; word-break: normal;">function <wbr>u0=pdeic(x)</span>
  35. <span style="word-wrap: normal; word-break: normal;">u0=[1;0];</span></div><div></div>
复制代码


4.png


想得到x为定值,比如x=0.2时,U1和U2随时间的变化曲线。

因为x=0.2在位置中的第5列,所以
  1. <p style="margin-bottom: 16px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">figure
  2. U1t <wbr>= <wbr>sol(:,5,1)
  3. plot(t,U1t)
  4. title('The <wbr>solution <wbr>of <wbr>u_1 <wbr>t')</p><div></div>
复制代码
2.png 3.png


1.png
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-29 05:44 , Processed in 0.062521 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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