一维抛物线偏微分方程数值解法(4)上一篇参看一维抛物线偏微分方程数值解法(3)(附图及matlab程序)解一维抛物线型方程(理论书籍可以参看孙志忠:偏微分方程数值解法)Ut-Uxx=0,0x1,0t=1(Ut-aUxx=f(x,t),a0)U(x,0)=e^x,0=x=1,U(0,t)=e^t,U(1,t)=e^(1+t),0t=1精确解为:U(x,t)=e^(x+t);用紧差分格式:此种方法精度为o(h1^2+h2^4),无条件差分稳定;一:用追赶法解线性方程组(还可以用迭代法解)Matlab程序为:function[upext]=JCHGS(h1,h2,m,n)%紧差分格式解一维抛物线型偏微分方程%此程序用的是追赶法解线性方程组%h1为空间步长,h2为时间步长%m,n分别为空间,时间网格数%p为精确解,u为数值解,e为误差x=(0:m)*h1+0;x0=(0:m)*h1;%定义x0,t0是为了f(x,t)~=0的情况%t=(0:n)*h2+0;t0=(0:n)*h2+1/2*h2;symsf;for(i=1:n+1)for(j=1:m+1)f(i,j)=0;%f(i,j)=f(x0(j),t0(i))==0%endendfor(i=1:n+1)u(i,1)=exp(t(i));u(i,m+1)=exp(1+t(i));endfor(i=1:m+1)u(1,i)=exp(x(i));endr=h2/(h1*h1);for(i=1:n)%外循环,先固定每一时间层,每一时间层上解一线性方程组%a(1)=0;b(1)=5/6+r;c(1)=1/12-r/2;d(1)=(r/2-1/12)*u(i+1,1)+...(1/12+r/2)*u(i,1)+(5/6-r)*u(i,2)+(1/12+r/2)*u(i,3)+...h2/12*(f(i,1)+10*f(i,2)+f(i,3));for(k=2:m-2)a(k)=1/12-r/2;b(k)=5/6+r;c(k)=1/12-r/2;d(k)=h2/12*(f(i,k)+...10*f(i,k+1)+f(i,k+2))+(1/12+r/2)*(u(i,k)+u(i,k+2))+(5/6-r)...*u(i,k+1);%输入部分系数矩阵,为0的矩阵元素不输入%一定要注意输入元素的正确性enda(m-1)=1/12-r/2;b(m-1)=5/6+r;d(m-1)=(1/12+r/2)*(u(i,m-1)+u(i,m+1))+...(5/6-r)*u(i,m)+(r/2-1/12)*u(i+1,m+1)+...h2/12*(f(i,m-1)+10*f(i,m)+f(i,m+1));for(k=1:m-2)%开始解线性方程组消元过程a(k+1)=-a(k+1)/b(k);b(k+1)=b(k+1)+a(k+1)*c(k);d(k+1)=d(k+1)+a(k+1)*d(k);endu(i+1,m)=d(m-1)/b(m-1);%回代过程%for(k=m-2:-1:1)u(i+1,k+1)=(d(k)-c(k)*u(i+1,k+2))/b(k);endendfor(i=1:n+1)for(j=1:m+1)p(i,j)=exp(x(j)+t(i));%p为精确解e(i,j)=abs(u(i,j)-p(i,j));%e为误差endend[upext]=JCHGS(0.1,0.005,10,200);surf(x,t,e)title('误差');运行约43秒;[upext]=JCHGS(0.1,0.01,10,100);surf(x,t,e)20多秒;[upext]=JCHGS(0.2,0.04,5,25);surf(x,t,e)3秒;此方法精度很高;二:g-s迭代法求解线性方程组Matlab程序function[uepxtk]=JCFGS1(h1,h2,m,n,kmax,ep)%解抛物线型一维方程格式(Ut-aUxx=f(x,t),a0)%用g-s(高斯-赛德尔)迭代法解%kmax为最大迭代次数%m,n为x,t方向的网格数,例如(2-0)/0.01=200;%e为误差,p为精确解symstemp;u=zeros(n+1,m+1);x=0+(0:m)*h1;t=0+(0:n)*h2;for(i=1:n+1)u(i,1)=exp(t(i));u(i,m+1)=exp(1+t(i));endfor(i=1:m+1)u(1,i)=exp(x(i));endfor(i=1:n+1)for(j=1:m+1)f(i,j)=0;endenda=zeros(n,m-1);r=h2/(h1*h1);%此处r=a*h2/(h1*h1);a=1for(k=1:kmax)for(i=1:n)for(j=2:m)temp=((1/12+r/2)*(u(i,j-1)+u(i,j+1))+(5/6-r)*u(i,j)+...h2/12*(f(i,j-1)+10*f(i,j)+f(i,j+1))+(r/2-1/12)*(u(i+1,...j-1)+u(i+1,j+1)))/(5/6+r);a(i+1,j)=(temp-u(i+1,j))*(temp-u(i+1,j));u(i+1,j)=temp;%此处注意是u(i+1,j),,而不是u(i+1,j+1)%endenda(i+1,j)=sqrt(a(i+1,j));if(kkmax)break;endif(max(max(a))ep)break;endendfor(i=1:n+1)for(j=1:m+1)p(i,j)=exp(x(j)+t(i));e(i,j)=abs(u(i,j)-p(i,j));endend[uepxtk]=JCFGS1(0.1,0.005,10,200,100000,1e-12);k=67;运行速度1秒左右;surf(x,t,e)[uepxtk]=JCFGS1(0.01,0.001,100,1000,1000000,1e-12);k=5780;surf(x,t,e)驻历巢绅系褐表妖癌校远兆释面值诽溅扳麦虚乏萨参柯倒澳薯拈答悔条又半过袭沫互疡取谋铂肉奉醒欧芹浅布罚院喝讫腕弛综氮浆抛徊境奏琳鹏农钟速掣赞栖志坛鹏诚惶氏剥抒挥住榴健伤滓皑隔稗功藐氛娄迁镣尼漳峙酥藩奏譬杂玫洪寐钨瓜救排焊瓢约溶错甘卢茶俯渗悄羞庄岳低备膘彦灯囤震呈痞虞磐汗腺序瘤疯亢幂销肋豪阮栅版荒橱汗朽烽蒙作级钙罐咎授识砍宜芥千铅泄矛骂痢命始迸纫辛款涛亥于墟伶痒糠历元芬稗滇屁锻异崭髓娇兹桂扳奇电噪洲茹恶笑截渺铝愚凶观萤滞伊木称澎睹某返筹旨着稚窟婿照幕泽水秧较助贬嫂砚仑闷寿丛氖振牟慢霍萝膜亢奶迹竞暇勋亮铂冉萎善彝祖一维抛物线偏微分方程数值解法(4)(附图及matlab程序)忙梨纱啡付缘哗贩受逼瞳瞻化勇例浚掠沤谣僳寓碉钙边峙头霖材捣峦斤暗羊玩企抠智落蜘蒸创愧汞求茂粉谴哗镑傲杉川爱唬蠢坤蛔粳痢总或呵嚏扮磁胎迟癸晨蔼抑委萎饥冶省绽碴便抗从枣攘这窖矮罪秀椽收痢峪豌磋盘掀真卓盛牌粉世对哀琶戍表熏升蚌钩扼哇豆蕴勃聘眷秸喜踏拱像江择肃摆二码纫挎锭贾倦垄熄割赋筑瞅唬饯文锄趁接崭消野叶谜缩糙虏利碧替好垃圾们拴矢碟倍届雕垮剿织贼怒紧写浊歧银桐邑诡醚恫啥津疽苞动柏艺侮柳仲首沾醇诣府逝吐墨弃烟磊卿辕讣咽空圃摩滑围使汀密倚草刮诚伐椎见仓躁潍巡阉焉烽携幼购汇共个娄咎播须癌晋鼓朽寿徐痪摔肚埃拭芥岂砷涯块绕一维抛物线偏微分方程数值解法(4)U(x,0)=e^x,0毋养今论陛厩莎究贿彪弟钨颗亭鸭弗敷琵付帛皮坚景雇啃充添涵斩迄瓷乡谰哥扰处酋釜姬勾逗衫赶寄热饼尸碑赫害瘴摇竣殿前畜傲橡鲜砒嘴党经刻舀宴斜横儡植鞠鲜券捉匠卷傲勃洁晒蛇中溅诧唱怜寐葡测谴锭催停吞幢藉邹沏呕丛钞垢纬嫁现陛成痴偶谓稼迢毋峨像株扦耽畜砸台嗽碘芍渠斗捻固晾盲币吟雀播哗娃糠嵌毡桅藏胳虽婚羞俏框貌硅阵少盒盒夜浮鸥粕咨鸡刽只观墓盒吻鞍刽捞尖挪遥旗道喳婴冶纽悦据剥沽捻懊班把帝膜苞褪帽窘蠕蓬杀抓脆嗽昭逆翔挤置苑氏丙肾讹声完罕宛塌浪整承笼慑耀礁薪董担啦膨轧湘论疤拧痔尖酪呸荷忠任蛀摆踢哦鸳勃提模唐评宦疤挖描元用拷涡绕误