think2015 发表于 2016-3-16 14:53

MATLAB解偏微分方程

本帖最后由 think2015 于 2016-3-16 14:54 编辑

<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;">
</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>
<span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>主函数:</span>
<span style="word-wrap: normal; word-break: normal;">x=0:0.05:1;</span>
<span style="word-wrap: normal; word-break: normal;">t=0:0.05:2;</span>
<span style="word-wrap: normal; word-break: normal;">m=0;</span>
<span style="word-wrap: normal; word-break: normal;">sol=pdepe(m,@pdefun,@pdeic,@pdebc,x,t);</span>
<span style="word-wrap: normal; word-break: normal;">figure('numbertitle','off','name','PDE <wbr>Demo')</span>
<span style="word-wrap: normal; word-break: normal;">subplot(211)</span>
<span style="word-wrap: normal; word-break: normal;">surf(x,t,sol(:,:,1))</span>
<span style="word-wrap: normal; word-break: normal;">title('The <wbr>solution <wbr>of <wbr>u_1')</span>
<span style="word-wrap: normal; word-break: normal;">xlabel('X')</span>
<span style="word-wrap: normal; word-break: normal;">ylabel('T')</span>
<span style="word-wrap: normal; word-break: normal;">zlabel('U')</span>
<span style="word-wrap: normal; word-break: normal;">subplot(212)</span>
<span style="word-wrap: normal; word-break: normal;">surf(x,t,sol(:,:,2))</span>
<span style="word-wrap: normal; word-break: normal;">title('The <wbr>Solution <wbr>of <wbr>u_2')</span>
<span style="word-wrap: normal; word-break: normal;">xlabel('X')</span>
<span style="word-wrap: normal; word-break: normal;">ylabel('T')</span>
<span style="word-wrap: normal; word-break: normal;">zlabel('U')</span>

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

<span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>边界条件:</span>
<span style="word-wrap: normal; word-break: normal;">function <wbr>=pdebc(xa,ua,xb,ub,t)</span>
<span style="word-wrap: normal; word-break: normal;">pa=;</span>
<span style="word-wrap: normal; word-break: normal;">qa=;</span>
<span style="word-wrap: normal; word-break: normal;">pb=;</span>
<span style="word-wrap: normal; word-break: normal;">qb=;</span>

<span style="word-wrap: normal; word-break: normal;">% <wbr> <wbr>初值条件:</span>
<span style="word-wrap: normal; word-break: normal;">function <wbr>u0=pdeic(x)</span>
<span style="word-wrap: normal; word-break: normal;">u0=;</span></div><div></div>



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

因为x=0.2在位置中的第5列,所以
<p style="margin-bottom: 16px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">figure
U1t <wbr>= <wbr>sol(:,5,1)
plot(t,U1t)
title('The <wbr>solution <wbr>of <wbr>u_1 <wbr>t')</p><div></div>
转自:http://blog.sina.com.cn/s/blog_3ecbcc070101b4ei.html
页: [1]
查看完整版本: MATLAB解偏微分方程