偏微分方程数值解题目

合集下载

偏微分方程数值解期末试题及标准答案

偏微分方程数值解期末试题及标准答案

偏微分方程数值解试题(06B )参考答案与评分标准信息与计算科学专业一(10分)、设矩阵A 对称,定义)(),(),(21)(n R x x b x Ax x J ∈-=,)()(0x x J λλϕ+=.若0)0('=ϕ,则称称0x 是)(x J 的驻点(或稳定点).矩阵A 对称(不必正定),求证0x 是)(x J 的驻点的充要条件是:0x 是方程组 b Ax =的解 解: 设n R x ∈0是)(x J 的驻点,对于任意的n R x ∈,令),(2),()()()(2000x Ax x b Ax x J x x J λλλλϕ+-+=+=, (3分)0)0('=ϕ,即对于任意的n R x ∈,0),(0=-x b Ax ,特别取b Ax x -=0,则有0||||),(2000=-=--b Ax b Ax b Ax ,得到b Ax =0. (3分)反之,若n R x ∈0满足b Ax =0,则对于任意的x ,)(),(21)0()1()(00x J x Ax x x J >+==+ϕϕ,因此0x 是)(x J 的最小值点. (4分)评分标准:)(λϕ的展开式3分, 每问3分,推理逻辑性1分二(10分)、 对于两点边值问题:⎪⎩⎪⎨⎧==∈=+-=0)(,0)(),()('b u a u b a x f qu dx du p dx d Lu 其中]),([,0]),,([,0)(min )(]),,([0min ],[1b a H f q b a C q p x p x p b a C p b a x ∈≥∈>=≥∈∈建立与上述两点边值问题等价的变分问题的两种形式:求泛函极小的Ritz 形式和Galerkin 形式的变分方程。

解: 设}0)(),,(|{11=∈=a u b a H u u H E为求解函数空间,检验函数空间.取),(1b a H v E ∈,乘方程两端,积分应用分部积分得到 (3分))().(),(v f fvdx dx quv dxdv dx du p v u a b a ba ==+=⎰⎰,),(1b a H v E ∈∀ 即变分问题的Galerkin 形式. (3分)令⎰-+=-=b a dx fu qu dxdu p u f u u a u J ])([21),(),(21)(22,则变分问题的Ritz 形式为求),(1*b a H u E ∈,使)(m in )(1*u J u J EH u ∈= (4分) 评分标准:空间描述与积分步骤3分,变分方程3分,极小函数及其变分问题4分,三(20分)、对于边值问题⎪⎩⎪⎨⎧-====⨯=∈=∂∂+∂∂====x u u u u G y x y u x u y y x x 1||,0|,1|)1,0()1,0(),(,010102222 (1)建立该边值问题的五点差分格式(五点棱形格式又称正五点格式),推导截断误差的阶。

第6章_偏微分方程数值解法(附录)

第6章_偏微分方程数值解法(附录)

第6章附录6.1 对流方程例题6.1.2计算程序!ADVECT.F!!!! advect - Program to solve the advection equation! using the various hyperbolic PDE schemesprogram advectinteger*4 MAXN, MAXnplotsparameter( MAXN = 500, MAXnplots = 500 )integer*4 method, N, nStep, i, j, ip(MAXN), im(MAXN)integer*4 iplot, nplots, iStepreal*8 L, h, c, tau, coeff, coefflw, pi, sigma, k_wavereal*8 x(MAXN), a(MAXN), a_new(MAXN), plotStepreal*8 aplot(MAXN,MAXnplots+1), tplot(MAXnplots+1)!* Select numerical parameters (time step, grid spacing, etc.).write(*,*) 'Choose a numerical method: 'write(*,*) ' 1) FTCS, 2) Lax, 3) Lax-Wendroff : 'read(*,*) methodwrite(*,*) 'Enter number of grid points: 100'read(*,*) NL = 1. ! System sizeh = L/N ! Grid spacingc = 1 ! Wave speedwrite(*,*) 'Time for wave to move one grid spacing is ', h/cwrite(*,*) 'Enter time step: 0.001'read(*,*) taucoeff = -c*tau/(2.*h) ! Coefficient used by all schemescoefflw = 2*coeff*coeff ! Coefficient used by L-W schemewrite(*,*) 'Wave circles system in ', L/(c*tau), ' steps'write(*,*) 'Enter number of steps: 300'read(*,*) nStep!* Set initial and boundary conditions.pi = 3.141592654sigma = 0.1 ! Width of the Gaussian pulsek_wave = pi/sigma ! Wave number of the cosinedo i=1,Nx(i) = (i-0.5)*h - L/2 ! Coordinates of grid pointsa(i) = cos(k_wave*x(i)) * exp(-x(i)**2/(2*sigma**2))enddo! Use periodic boundary conditionsdo i=2,(N-1)ip(i) = i+1 ! ip(i) = i+1 with periodic b.c.im(i) = i-1 ! im(i) = i-1 with periodic b.c.enddoip(1) = 2ip(N) = 1im(1) = Nim(N) = N-1!* Initialize plotting variables.iplot = 1 ! Plot counternplots = 50 ! Desired number of plotsplotStep = float(nStep)/nplotstplot(1) = 0 ! Record the initial time (t=0)do i=1,Naplot(i,1) = a(i) ! Record the initial stateenddo!* Loop over desired number of steps.do iStep=1,nStep!* Compute new values of wave amplitude using FTCS,! Lax or Lax-Wendroff method.if( method .eq. 1 ) then !!! FTCS method !!!do i=1,Na_new(i) = a(i) + coeff*( a(ip(i))-a(im(i)) )enddoelse if( method .eq. 2 ) then !!! Lax method !!!do i=1,Na_new(i) = 0.5*( a(ip(i))+a(im(i)) ) +& coeff*( a(ip(i))-a(im(i)) )enddoelse !!! Lax-Wendroff method !!!do i=1,Na_new(i) = a(i) + coeff*( a(ip(i))-a(im(i)) ) +& coefflw*( a(ip(i))+a(im(i))-2*a(i) ) enddoendifa(i) = a_new(i) ! Reset with new amplitude valuesenddo!* Periodically record a(t) for plotting.if( (iStep-int(iStep/plotStep)*plotStep) .lt. 1 ) theniplot = iplot+1tplot(iplot) = tau*iStepdo i=1,Naplot(i,iplot) = a(i) ! Record a(i) for plotingenddowrite(*,*) iStep, ' out of ', nStep, ' steps completed'endifenddonplots = iplot ! Actual number of plots recorded!* Print out the plotting variables: x, a, tplot, aplotopen(11,file='x.txt',status='unknown')open(12,file='a.txt',status='unknown')open(13,file='tplot.txt',status='unknown')open(14,file='aplot.txt',status='unknown')do i=1,Nwrite(11,*) x(i)write(12,*) a(i)do j=1,(nplots-1)write(14,1001) aplot(i,j)enddowrite(14,*) aplot(i,nplots)enddodo i=1,nplotswrite(13,*) tplot(i)enddo1001 format(e12.6,', ',$) ! The $ suppresses the carriage return stopend!***** To plot in MATLAB; use the script below ******************** !load x.txt; load a.txt; load tplot.txt; load aplot.txt;!%* Plot the initial and final states.!figure(1); clf; % Clear figure 1 window and bring forward!plot(x,aplot(:,1),'-',x,a,'--');!legend('Initial','Final');!pause(1); % Pause 1 second between plots!%* Plot the wave amplitude versus position and time!figure(2); clf; % Clear figure 2 window and bring forward!mesh(tplot,x,aplot);!ylabel('Position'); xlabel('Time'); zlabel('Amplitude');!view([-70 50]); % Better view from this angle!****************************************************************** ================================================6.2 抛物形方程例题6.2.2计算程序!!!!dftcs.f!!!!!!!!!!! dftcs - Program to solve the diffusion equation! using the Forward Time Centered Space (FTCS) scheme.program dftcsinteger*4 MAXN, MAXnplotsparameter( MAXN = 300, MAXnplots = 500 )integer*4 N, i, j, iplot, nStep, plot_step, nplots, iStepreal*8 tau, L, h, kappa, coeff, tt(MAXN), tt_new(MAXN)real*8 xplot(MAXN), tplot(MAXnplots), ttplot(MAXN,MAXnplots)!* Initialize parameters (time step, grid spacing, etc.).write(*,*) 'Enter time step: 0.0001'read(*,*) tauwrite(*,*) 'Enter the number of grid points: 50 'read(*,*) NL = 1. ! The system extends from x=-L/2 to x=L/2h = L/(N-1) ! Grid sizekappa = 1. ! Diffusion coefficientcoeff = kappa*tau/h**2if( coeff .lt. 0.5 ) thenwrite(*,*) 'Solution is expected to be stable'elsewrite(*,*) 'WARNING: Solution is expected to be unstable'endif!* Set initial and boundary conditions.do i=1,Ntt(i) = 0.0 ! Initialize temperature to zero at all pointstt_new(i) = 0.0enddo!! The boundary conditions are tt(1) = tt(N) = 0!! End points are unchanged during iteration!* Set up loop and plot variables.iplot = 1 ! Counter used to count plotsnStep = 300 ! Maximum number of iterationsplot_step = 6 ! Number of time steps between plots nplots = nStep/plot_step + 1 ! Number of snapshots (plots)do i=1,Nxplot(i) = (i-1)*h - L/2 ! Record the x scale for plotsenddo!* Loop over the desired number of time steps.do iStep=1,nStep!* Compute new temperature using FTCS scheme.do i=2,(N-1)tt_new(i) = tt(i) + coeff*(tt(i+1) + tt(i-1) - 2*tt(i))enddodo i=2,(N-1)tt(i) = tt_new(i) ! Reset temperature to new valuesenddo!* Periodically record temperature for plotting.if( mod(iStep,plot_step) .lt. 1 ) then ! Every plot_step stepsdo i=1,N ! record tt(i) for plottingttplot(i,iplot) = tt(i)enddotplot(iplot) = iStep*tau ! Record time for plotsiplot = iplot+1endifenddonplots = iplot-1 ! Number of plots actually recorded!* Print out the plotting variables: tplot, xplot, ttplotopen(11,file='tplot.txt',status='unknown')open(12,file='xplot.txt',status='unknown')open(13,file='ttplot.txt',status='unknown')do i=1,nplotswrite(11,*) tplot(i)enddowrite(12,*) xplot(i)do j=1,(nplots-1)write(13,1001) ttplot(i,j)enddowrite(13,*) ttplot(i,nplots)enddo1001 format(e12.6,', ',$) ! The $ suppresses the carriage returnstopend!***** To plot in MATLAB; use the script below ********************!load tplot.txt; load xplot.txt; load ttplot.txt;!%* Plot temperature versus x and t as wire-mesh and contour plots.!figure(1); clf;!mesh(tplot,xplot,ttplot); % Wire-mesh surface plot!xlabel('Time'); ylabel('x'); zlabel('T(x,t)');!title('Diffusion of a delta spike');!pause(1);!figure(2); clf;!contourLevels = 0:0.5:10; contourLabels = 0:5;!cs = contour(tplot,xplot,ttplot,contourLevels); % Contour plot!clabel(cs,contourLabels); % Add labels to selected contour levels!xlabel('Time'); ylabel('x');!title('Temperature contour plot');!******************************************************************! program diffu_explicit.for! explicit methods for finite diffrencedimension T(51,51)real dx,dt,lamda,kp,Tmax,Tminopen(2,file='diffu_1.dat')dx=0.5dt=0.1kp=0.835lamda=kp*dt/dx/dxTmax=100.Tmin=0.imax=21write(*,*) 'lamda=',lamdado i=1,50do j=1,50T(i,j)=0.0do j=1,40T(1,j)=TmaxT(imax,j)=Tminend dodo j=1,40do i=2,20T(i,j+1)=T(i,j)+lamda*(T(i+1,j)-2.*T(i,j)+T(i-1,j)) end dowrite(2,222) (T(i,j),i=1,21)end do222 format(1x,21(2x,f18.10))end% diffu_explicit.mclc; clear all;nl = 20.; nt = 40;dx = 0.5; dt = 0.1; kp = 0.835;lamda = kp*dt/dx/dx;Tl = 0.; Tr = 100.;T = zeros(nl,nt);T(1,:) = Tl; T(nl,:)=Tr;for j=1:nt-1for i =2:nl-1T(i,j+1)=T(i,j)+lamda*(T(i+1,j)-2.*T(i,j)+T(i-1,j));endendsurf(T');xlabel('x');ylabel('time');zlabel('Temperature');title('explicit scheme');! diffu_implicit.for! implicit methods for finite diffrenceexternal tridparameter (imax=21,kmax=50)dimension t(imax),a(imax),b(imax),c(imax),r(imax),u(imax) real dx,dt,lamda,kp,tmax,tminopen(2,file='diffu_2.dat')dx=0.5lamda=kp*dt/dx/dxtmax=100.tmin=0.write(*,*) 'lamda=',lamdado i=2,imax-1! t(i)=tmax-(tmax-tmin)/(imax-1.)*(i-1.) t(i)=0.0end dot(1)=tmaxt(imax)=tmin! write(*,*) a(i),b(i),c(i)b(1)=1.c(1)=0.r(1)=t(1)a(imax)=0.b(imax)=1.r(imax)=t(imax)do i=2,imax-1a(i)=-lamdab(i)=1.+2.*lamdac(i)=-lamdar(i)=t(i)end dok=01 k=k+1call trid(a,b,c,r,u,imax)do i=1,imaxt(i)=u(i)r(i)=u(i)end dowrite(2,222) (t(i),i=1,imax)! write(*,222) (t(i),i=1,imax)if(k.lt.kmax) goto 1222 format(1x,21(2x,f18.12))endsubroutine trid(a,b,c,r,u,n)parameter (nmax=100)real gam(nmax),a(n),b(n),c(n),u(n),r(n)if (b(1)==0.) pause 'b(1)=0 in trid'bet=b(1)u(1)=r(1)/betdo j=2,ngam(j)=c(j-1)/betbet=b(j)-a(j)*gam(j)if (bet==0.) pause 'bet=0 in trid'u(j)=(r(j)-a(j)*u(j-1))/betend dodo j=n-1,1,-1u(j)=u(j)-gam(j+1)*u(j+1)end doend subroutine trid================================================== 6.3椭圆方程例题6.3.1计算程序! program overrelaxation.for! overrelaxation_iteration_methods for finite diffrence! of the 2d_Laplacian difference equationparameter(imax=25,jmax=25,pi=3.1415926)dimension T(imax,jmax),a(imax,jmax),& qx(imax,jmax),qy(imax,jmax),q(imax,jmax),an(imax,jmax) real lamda,Tu,Td,Tl,Tr,kpx,kpy,dx,dyopen(2,file='overrelaxation.dat')open(3,file='q.dat')lamda=1.5;Tu=100.;Tl=75.;Tr=50.;Td=0.;dx=1.;dy=1.;kmax=9 kpx=-0.49/2./dx;kpy=-0.49/2./dydo i=1,imaxdo j=1,jmaxT(i,j)=0.0end doend doT(1,1)=0.5*(Td+Tl) ;T(1,jmax)=0.5*(Tl+Tu)T(imax,jmax)=0.5*(Tu+Tr);T(imax,1)=0.5*(Tr+Td)do j=2,jmax-1T(1,j)=Tl; T(imax,j)=Trend dodo i=2, imax-1T(i,1)=Td; T(i,jmax)=Tuend dok=0do i=2,imax-1do j=2,jmax-1a(i,j)=T(i,j)T(i,j)=0.25*(T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1))T(i,j)=lamda*T(i,j)+(1.-lamda)*a(i,j)end doend doep=abs((T(2,2)-a(2,2))/T(2,2))if(k.lt.kmax) goto 5write(*,*) 'ep=',epdo j=1,jmaxwrite(2,222) (T(i,j),i=1,imax)end do222 format(1x,25(2x,f14.10))do i=2,imax-1do j=2,jmax-1qx(i,j)=kpx*(T(i+1,j)-T(i-1,j))qy(i,j)=kpy*(T(i,j+1)-T(i,j-1))q(i,j)=sqrt(qx(i,j)*qx(i,j)+qy(i,j)*qy(i,j))if(qx(i,j).gt.0.) thenan(i,j)=atan(qy(i,j)/qx(i,j))elsean(i,j)=atan(qy(i,j)/qx(i,j))+piend ifend doend dodo j=2,jmax-1do i=2,imax-1! write(3,333) dx*(i-1),dy*(j-1),an(i,j),q(i,j)write(3,333) dx*(i-1),dy*(j-1),qx(i,j),qy(i,j)end doend do333 format(1x,4(2x,f18.12))End================================================= 例题6.3.2计算程序!!!!xadi.f90!!!!!program xadiuse AVDefuse DFLibparameter(n=19)real aj(n),bj(n),cj(n)integer statusreal T(0:n,0:n),TT(0:n,0:n)real lamda,Tu,Td,Tl,Tr,dx,dy,dt,kaopen(2,file='T3.dat')Tu=100.;Tl=75.;Tr=50.;Td=0.;dx=1.;dy=1.;kmax=10;dt=1.ka=0.835; lamda=ka*dt/(dx*dx)write(*,*) 'lamda=',lamdaT = 0.T(0,:) = Tl; T(n,:) =TrT(:,0) = Td; T(:,n) =TuT(0,0)=0.5*(Td+Tl);T(0,n)=0.5*(Tl+Tu)T(n,n)=0.5*(Tu+Tr);T(n,0)=0.5*(Tr+Td)! 系数矩阵赋值aj(:)=-lamda; ai(:)=lamdabj(:)= 2.*(1.+lamda); bi(:)=2.*(1-lamda)cj(:)=-lamda; ci(:)=lamdacall faglStartWatch(T, status)! 相当于随时间演化do k=1,kmaxdo i=1,n-1do j=1,n-1r(j)=ai(i)*T(i-1,j)+bi(i)*T(i,j)+ci(i)*T(i+1,j)end dor(1)=r(1)-aj(1)*T(i,0)r(n-1)=r(n-1)-cj(n-1)*T(i,n)call tridag(aj,bj,cj,r,u,n-1)do j=1,n-1T(i,j)=u(j)end doend do! 将矩阵T转置计算x方向call reverse(n,T,TT)do i=1,n-1do j=1,n-1r(j)=ai(i)*TT(i-1,j)+bi(i)*TT(i,j)+ci(i)*TT(i+1,j) end dor(1)=r(1)-aj(1)*TT(i,0)r(n-1)=r(n-1)-cj(n-1)*TT(i,n)call tridag(aj,bj,cj,r,u,n-1)do j=1,n-1TT(i,j)=u(j)end doend docall reverse(n,TT,T)call faglUpdate(T, status)call faglShow(T, status)end dopausecall faglClose(T, status)call faglEndWatch(T, status)do j=0,nwrite(2,222) (T(i,j),i=0,n)end do222 format(1x,20(2x,f14.10))endSUBROUTINE tridag(a,b,c,r,u,n)INTEGER n,NMAXREAL a(n),b(n),c(n),r(n),u(n)PARAMETER (NMAX=500)INTEGER jREAL bet,gam(NMAX)if(b(1).eq.0.)pause 'tridag: rewrite equations'bet=b(1)u(1)=r(1)/betdo 11 j=2,ngam(j)=c(j-1)/betbet=b(j)-a(j)*gam(j)if(bet.eq.0.)pause 'tridag failed'u(j)=(r(j)-a(j)*u(j-1))/bet11 continuedo 12 j=n-1,1,-1u(j)=u(j)-gam(j+1)*u(j+1)12 continuereturnENDSUBROUTINE REVERSE(n,T,TT) integer n,i,jreal T(0:n,0:n),TT(0:n,0:n)do i=0,ndo j=0,nTT(i,j)=T(j,i)end doend doreturnend================================================6.4 非线性偏微分方程% gasdynamincs_lw_1.mclc; clear all;xmin=-1.; xmax=1.; nx=101; h=(xmax-xmin)/(nx-1);r=0.9; cad=0.; time=0.; gamma=1.4; bcl=1.; bcr=1.;fprintf(' Space step - %f \n',h); fprintf(' \n');dd(1:nx)=zeros(1,nx); ud(1:nx)=zeros(1,nx); pd(1:nx)=zeros(1,nx);x(1:nx)=xmin+((1:nx)-1)*h;% Test 1te=' ( Test 1 )';rol=1.; ul=0.; pl=1.;ror=0.125; ur=0.; pr=0.1;tp=5.5;% Test 3%te=' ( Test 3 )';%rol=0.1; ul=0.; pl=1.;%ror=1.; ur=0.; pr=100.;%tp=0.05;% Initial conditionsdd(1:(nx-1)/2+1)=rol; ud(1:(nx-1)/2+1)=ul; pd(1:(nx-1)/2+1)=pl;dd((nx-1)/2+2:nx)=ror;ud((nx-1)/2+2:nx)=ur; pd((nx-1)/2+2:nx)=pr;[d,u,p,e,time]=lw_gasdynamics(dd,ud,pd,h,nx,r,cad,tp,gamma,bcl,bcr);% Exact solutionfor n=1:nx[density, velocity, pressure]=riemann(x(n),time,rol,ul,pl,ror,ur,pr,gamma);de(n)=density; ue(n)=velocity; pe(n)=pressure;ee(n)=pressure/((gamma-1.)*density);endfigure(1);plot(x,de,'k-',x,d,'k--');xlabel(' x ');ylabel(' density ');title([' Example 6.1 ',te]);figure(2);plot(x,ue,'k-',x,u,'k--');xlabel(' x ');ylabel(' velocity ');title([' Example 6.1 ',te]);figure(3);plot(x,pe,'k-',x,p,'k--');xlabel(' x ');ylabel(' pressure ');title([' Example 6.1 ',te]);figure(4);plot(x,ee,'k-',x,e,'k--');xlabel(' x ');ylabel(' internal energy ');title([' Example 6.1 ',te]);clear all;% Lax-Wendroff scheme (gasdynamics)function [d,u,p,e,time]=lw_gasdynamics(dd,ud,pd,h,nx,r,cad,tp,gamma,bcl,bcr)sd(1,1:nx)=dd(1:nx);sd(2,1:nx)=dd(1:nx).*ud(1:nx);sd(3,1:nx)=pd(1:nx)/(gamma-1.)+0.5*(dd(1:nx).*ud(1:nx)).*ud(1:nx);si(1:3,1:nx+1)=zeros(3,nx+1); av(1:3,1:nx)=zeros(3,nx);time=0.;while time <= tpsta=max(abs(sd(2,:)./sd(1,:))+...sqrt(gamma*(gamma-1)*(sd(3,:)./sd(1,:)-0.5*(sd(2,:).*sd(2,:))./(sd(1,:).*sd(1,:)))));tau=r*h*sqrt(1.-2.*cad)/sta;time=time+tau; %fprintf(' time - %f \n',time);% first stepif bcl == 0sl1=sd(1,2); sl2=-sd(2,2); sl3=sd(3,2);elsesl1=sd(1,2); sl2=sd(2,2); sl3=sd(3,2);endgl(1)=sl2;gl(2)=(gamma-1.)*sl3+0.5*(3.-gamma)*sl2^2/sl1;gl(3)=sl2*(gamma*sl3-0.5*(gamma-1.)*sl2^2/sl1)/sl1;for n=1:nxif (n == 1)|(n == nx)av(:,n)=[ 0.; 0.; 0.;];elseav(:,n)=cad*(sd(:,n+1)-2.*sd(:,n)+sd(:,n-1));endsr1=sd(1,n); sr2=sd(2,n); sr3=sd(3,n);gr(1)=sr2;gr(2)=(gamma-1.)*sr3+0.5*(3.-gamma)*sr2^2/sr1;gr(3)=sr2*(gamma*sr3-0.5*(gamma-1.)*sr2^2/sr1)/sr1;si(1,n)=0.5*(sl1+sr1)-(gr(1)-gl(1))*tau*0.5/h;si(2,n)=0.5*(sl2+sr2)-(gr(2)-gl(2))*tau*0.5/h;si(3,n)=0.5*(sl3+sr3)-(gr(3)-gl(3))*tau*0.5/h;gl(:)=gr(:);sl1=sr1; sl2=sr2; sl3=sr3;endif bcr == 0sr1=sd(1,nx-1); sr2=-sd(2,nx-1); sr3=sd(3,nx-1);elsesr1=sd(1,nx-1); sr2=sd(2,nx-1); sr3=sd(3,nx-1);endgr(1)=sr2;gr(2)=(gamma-1.)*sr3+0.5*(3.-gamma)*sr2^2/sr1;gr(3)=sr2*(gamma*sr3-0.5*(gamma-1.)*sr2^2/sr1)/sr1;si(1,nx+1)=0.5*(sl1+sr1)-(gr(1)-gl(1))*tau*0.5/h;si(2,nx+1)=0.5*(sl2+sr2)-(gr(2)-gl(2))*tau*0.5/h;si(3,nx+1)=0.5*(sl3+sr3)-(gr(3)-gl(3))*tau*0.5/h;% second stepfl(1)=si(2,1);fl(2)=(gamma-1.)*si(3,1)+0.5*(3.-gamma)*si(2,1)^2/si(1,1);fl(3)=si(2,1)*(gamma*si(3,1)-0.5*(gamma-1.)*si(2,1)^2/si(1,1))/si(1,1);for n=2:nx+1fr(1)=si(2,n);fr(2)=(gamma-1.)*si(3,n)+0.5*(3.-gamma)*si(2,n)^2/si(1,n);fr(3)=si(2,n)*(gamma*si(3,n)-0.5*(gamma-1.)*si(2,n)^2/si(1,n))/si(1,n);su(:,n-1)=sd(:,n-1)-(fr(:)-fl(:))*tau/h+av(:,n-1);fl(:)=fr(:);endsd(:,1:nx)=su(:,1:nx);endd(1:nx)=su(1,1:nx); u(1:nx)=su(2,1:nx)./su(1,1:nx);p(1:nx)=(gamma-1.)*(su(3,1:nx)-0.5*(su(2,1:nx).*su(2,1:nx))./su(1,1:nx));e(1:nx)=(su(3,1:nx)-0.5*(su(2,1:nx).*su(2,1:nx))./su(1,1:nx))./su(1,1:nx);return;% Solves Riemann problem for ideal gas% r1, u1, p1 initial parameters for x<0% r2, u2, p2 initial parameters for x>0% rf, uf, pf solution at the point (x,t)% c1, c2 sound speeds for x<0 and for x>0% s1, sr velocties of the fronts of S(hock)W(ave)s% shl, shr velocties of the fronts of the heads of R(arefaction)Ws% stl, str velocties of the tails of RWsfunction [rf,uf,pf]=riemann(x,t,r1,u1,p1,r2,u2,p2,gamma)g(1)=0.5*(gamma-1.)/gamma; g(2)=0.5*(gamma+1.)/gamma; g(3)=2.*gamma/(gamma-1.); g(4)=2./(gamma-1.); g(5)=2./(gamma+1.); g(6)=(gamma-1.)/(gamma+1.);g(7)=0.5*(gamma-1.); g(8)=1./gamma; g(9)=gamma-1.;s=x/t;c1 = sqrt(p1/(r1*g(8)));c2 = sqrt(p2/(r2*g(8)));du=u2-u1;% Vacuum solutionuvac=g(4)*(c1+c2)-du;if uvac <= 0.disp(' Vacuum generated by given data');return;end% Apply Newton method% Initial guessespv=0.5*(p1+p2)-0.125*du*(r1+r2)*(c1+c2);pmin=min(p1,p2); pmax=max(p1,p2); qrat=pmax/pmin;if ( qrat <= 2. ) & ( pmin <= pv & pv <= pmax )p=max(1.0e-6,pv);elseif pv < pminpnu=c1+c2-g(7)*du;pde=c1/(p1^g(1))+c2/(p2^g(1));p=(pnu/pde)^g(3);elsegel=sqrt((g(5)/r1)/(g(6)*p1+max(1.0e-6,pv)));ger=sqrt((g(5)/r2)/(g(6)*p2+max(1.0e-6,pv)));p=(gel*p1+ger*p2-du)/(gel+ger); p=max(1.0e-6,p);endendp0=p; err=1.;while err > 1.0e-5if p <= p1prat=p/p1; fl=g(4)*c1*(prat^g(1)-1.); ffl=1./(r1*c1*prat^g(2));elsea=g(5)/r1; b=g(6)*p1; qrt=sqrt(a/(b+p));fl=(p-p1)*qrt; ffl=(1.-0.5*(p-p1)/(b+p))*qrt;endif p <= p2prat=p/p2; fr=g(4)*c2*(prat^g(1)-1.); ffr=1./(r2*c2*prat^g(2));elsea=g(5)/r2; b=g(6)*p2; qrt=sqrt(a/(b+p));fr=(p-p2)*qrt; ffr=(1.-0.5*(p-p2)/(b+p))*qrt;endp=p-(fl+fr+du)/(ffl+ffr);err=2.*abs(p-p0)/(p+p0); p0=p;endif p0 < 0.p0=1.0e-6;end% Velocity of CDu0=0.5*(u1+u2+fr-fl);if s <= u0if p0 <= p1shl=u1-c1;if s <= shlrf=r1; uf=u1; pf=p1; return;elsecml=c1*(p0/p1)^g(1); stl=u0-cml;if s > stlrf=r1*(p0/p1)^g(8); uf=u0; pf=p0; return;elseuf=g(5)*(c1+g(7)*u1+s); c=g(5)*(c1+g(7)*(u1-s));rf=r1*(c/c1)^g(4); pf=p1*(c/c1)^g(3);return;endendelsepml=p0/p1; sl=u1-c1*sqrt(g(2)*pml+g(1));if s <= slrf=r1; uf=u1; pf=p1; return;elserf=r1*(pml+g(6))/(pml*g(6)+1.); uf=u0; pf=p0; return;endendelseif p0 > p2pmr=p0/p2; sr=u2+c2*sqrt(g(2)*pmr+g(1));if s >= srrf=r2; uf=u2; pf=p2; return;elserf=r2*(pmr+g(6))/(pmr*g(6)+1.); uf=u0; pf=p0; return;endelseshr=u2+c2;if s >= shrrf=r2; uf=u2; pf=p2; return;elsecmr=c2*(p0/p2)^g(1); str=u0+cmr;if s <= strrf=r2*(p0/p2)^g(8); uf=u0; pf=p0; return;elseuf=g(5)*(-c2+g(7)*u2+s); c=g(5)*(c2-g(7)*(u2-s));rf=r2*(c/c2)^g(4); pf=p2*(c/c2)^g(3);return;endendendendreturn;%%%%%%%%% gasdynamics_Godunov.m%%%%%%%%%%%%%clc; clear all;xmin=-1.; xmax=1.; nx=101; h=(xmax-xmin)/(nx-1);r=0.9; gamma=1.4; bcl=1.; bcr=1.;fprintf('gasdynamics_godunov \n'); fprintf(' Space step - %f \n',h); fprintf(' \n'); dd(1:nx-1)=zeros(1,nx-1); ud(1:nx-1)=zeros(1,nx-1); pd(1:nx-1)=zeros(1,nx-1);x(1:nx)=xmin+((1:nx)-1)*h; xa=xmin+((1:nx-1)-0.5)*h;% Test 1te=' ( Test 1 )';rol=1.; ul=0.; pl=1.;ror=0.125; ur=0.; pr=0.1;tp=15.5;% Test 2%te=' ( Test 2 )';%rol=1.; ul=0.; pl=1000.;%ror=1.; ur=0.; pr=1.;%tp=0.024;% Test 3%te=' ( Test 3 )';%rol=0.1; ul=0.; pl=1.;%ror=1.; ur=0.; pr=100.;%tp=0.05;% Test 4%te=' ( Test 4 )';%rol=5.99924; ul=19.5975; pl=460.894;%ror=5.99242; ur=-6.19633; pr=46.0950;%tp=0.05;% Test 5%te=' ( Test 5 )';%rol=3.86; ul=-0.81; pl=10.33;%ror=1.; ur=-3.44; pr=1.;%tp=0.5;% Initial conditionsdd(1:(nx-1)/2)=rol; ud(1:(nx-1)/2)=ul; pd(1:(nx-1)/2)=pl;dd((nx-1)/2+1:nx-1)=ror;ud((nx-1)/2+1:nx-1)=ur; pd((nx-1)/2+1:nx-1)=pr;[d,u,p,e,time]=godunov_gasdynamics(dd,ud,pd,h,nx,r,tp,gamma,bcl,bcr);% Exact solutionfor n=1:nx[density, velocity, pressure]=riemann(x(n),time,rol,ul,pl,ror,ur,pr,gamma);de(n)=density; ue(n)=velocity; pe(n)=pressure;ee(n)=pressure/((gamma-1.)*density);endfigure(1);plot(x,de,'k-',xa,d,'ko');xlabel(' x ');ylabel(' density ');title([' Example 6.3 ',te]);figure(2);plot(x,ue,'k-',xa,u,'ko');xlabel(' x ');ylabel(' velocity ');figure(3);plot(x,pe,'k-',xa,p,'ko');xlabel(' x ');ylabel(' pressure ');figure(4);plot(x,ee,'k-',xa,e,'ko');xlabel(' x ');ylabel(' internal energy ');clear all;% Method of S. K. Godunovfunction [d,u,p,e,time]=godunov_gasdynamics(dd,ud,pd,h,nx,r,tp,gamma,bcl,bcr)g(1)=0.5*(gamma-1.)/gamma; g(2)=0.5*(gamma+1.)/gamma; g(3)=2.*gamma/(gamma-1.); g(4)=2./(gamma-1.); g(5)=2./(gamma+1.); g(6)=(gamma-1.)/(gamma+1.);g(7)=0.5*(gamma-1.); g(8)=1./gamma; g(9)=gamma-1.;sd(1,1:nx-1)=dd(1:nx-1);sd(2,1:nx-1)=dd(1:nx-1).*ud(1:nx-1);sd(3,1:nx-1)=pd(1:nx-1)/(gamma-1.)+0.5*(dd(1:nx-1).*ud(1:nx-1)).*ud(1:nx-1);time=0.;while time <= tpsta=max(abs(sd(2,:)./sd(1,:))+...sqrt(gamma*(gamma-1)*(sd(3,:)./sd(1,:)-0.5*(sd(2,:).*sd(2,:))./(sd(1,:).*sd(1,:)))));tau=r*h/sta;time=time+tau; %fprintf(' %f \n',time);if bcl == 0[f1,f2,f3]=flux_godunov(sd(1,1),-sd(2,1),sd(3,1),sd(1,1),sd(2,1),sd(3,1),g(:));else[f1,f2,f3]=flux_godunov(sd(1,1),sd(2,1),sd(3,1),sd(1,1),sd(2,1),sd(3,1),g(:));endfleft(1)=f1; fleft(2)=f2; fleft(3)=f3;for n=1:nx-2[f1,f2,f3]=flux_godunov(sd(1,n),sd(2,n),sd(3,n),sd(1,n+1),sd(2,n+1),sd(3,n+1),g(:));fright(1)=f1; fright(2)=f2; fright(3)=f3;su(:,n)=sd(:,n)-(fright(:)-fleft(:))*tau/h;fleft(:)=fright(:);endif bcr == 0[f1,f2,f3]=flux_godunov(sd(1,nx-1),sd(2,nx-1),sd(3,nx-1),sd(1,nx-1),-sd(2,nx-1),...sd(3,nx-1),g(:));else[f1,f2,f3]=flux_godunov(sd(1,nx-1),sd(2,nx-1),sd(3,nx-1),sd(1,nx-1),sd(2,nx-1),...sd(3,nx-1),g(:));endfright(1)=f1; fright(2)=f2; fright(3)=f3;su(:,nx-1)=sd(:,nx-1)-(fright(:)-fleft(:))*tau/h;sd(:,1:nx-1)=su(:,1:nx-1);endd(1:nx-1)=su(1,1:nx-1); u(1:nx-1)=su(2,1:nx-1)./su(1,1:nx-1);p(1:nx-1)=(gamma-1.)*(su(3,1:nx-1)-0.5*(su(2,1:nx-1).*su(2,1:nx-1))./su(1,1:nx-1));e(1:nx-1)=(su(3,1:nx-1)-0.5*(su(2,1:nx-1).*su(2,1:nx-1))./su(1,1:nx-1))./su(1,1:nx-1); return;% Solves Riemann problem for ideal gas% r1, u1, p1 initial parameters for x<0% r2, u2, p2 initial parameters for x>0% rf, uf, pf solution at the point (x,t)% c1, c2 sound speeds for x<0 and for x>0% s1, sr velocties of the fronts of S(hock)W(ave)s% shl, shr velocties of the fronts of the heads of R(arefaction)Ws% stl, str velocties of the tails of RWsfunction [rf,uf,pf]=riemann(x,t,r1,u1,p1,r2,u2,p2,gamma)g(1)=0.5*(gamma-1.)/gamma; g(2)=0.5*(gamma+1.)/gamma; g(3)=2.*gamma/(gamma-1.);g(7)=0.5*(gamma-1.); g(8)=1./gamma; g(9)=gamma-1.;s=x/t;c1 = sqrt(p1/(r1*g(8)));c2 = sqrt(p2/(r2*g(8)));du=u2-u1;% Vacuum solutionuvac=g(4)*(c1+c2)-du;if uvac <= 0.disp(' Vacuum generated by given data');return;end% Apply Newton method% Initial guessespv=0.5*(p1+p2)-0.125*du*(r1+r2)*(c1+c2);pmin=min(p1,p2); pmax=max(p1,p2); qrat=pmax/pmin;if ( qrat <= 2. ) & ( pmin <= pv & pv <= pmax )p=max(1.0e-6,pv);elseif pv < pminpnu=c1+c2-g(7)*du;pde=c1/(p1^g(1))+c2/(p2^g(1));p=(pnu/pde)^g(3);elsegel=sqrt((g(5)/r1)/(g(6)*p1+max(1.0e-6,pv)));ger=sqrt((g(5)/r2)/(g(6)*p2+max(1.0e-6,pv)));p=(gel*p1+ger*p2-du)/(gel+ger); p=max(1.0e-6,p);endendp0=p; err=1.;while err > 1.0e-5if p <= p1prat=p/p1; fl=g(4)*c1*(prat^g(1)-1.); ffl=1./(r1*c1*prat^g(2));elsea=g(5)/r1; b=g(6)*p1; qrt=sqrt(a/(b+p));fl=(p-p1)*qrt; ffl=(1.-0.5*(p-p1)/(b+p))*qrt;endif p <= p2prat=p/p2; fr=g(4)*c2*(prat^g(1)-1.); ffr=1./(r2*c2*prat^g(2));a=g(5)/r2; b=g(6)*p2; qrt=sqrt(a/(b+p));fr=(p-p2)*qrt; ffr=(1.-0.5*(p-p2)/(b+p))*qrt;endp=p-(fl+fr+du)/(ffl+ffr);err=2.*abs(p-p0)/(p+p0); p0=p;endif p0 < 0.p0=1.0e-6;end% Velocity of CDu0=0.5*(u1+u2+fr-fl);if s <= u0if p0 <= p1shl=u1-c1;if s <= shlrf=r1; uf=u1; pf=p1; return;elsecml=c1*(p0/p1)^g(1); stl=u0-cml;if s > stlrf=r1*(p0/p1)^g(8); uf=u0; pf=p0; return;elseuf=g(5)*(c1+g(7)*u1+s); c=g(5)*(c1+g(7)*(u1-s));rf=r1*(c/c1)^g(4); pf=p1*(c/c1)^g(3);return;endendelsepml=p0/p1; sl=u1-c1*sqrt(g(2)*pml+g(1));if s <= slrf=r1; uf=u1; pf=p1; return;elserf=r1*(pml+g(6))/(pml*g(6)+1.); uf=u0; pf=p0; return;endendelseif p0 > p2pmr=p0/p2; sr=u2+c2*sqrt(g(2)*pmr+g(1));if s >= srrf=r2; uf=u2; pf=p2; return;rf=r2*(pmr+g(6))/(pmr*g(6)+1.); uf=u0; pf=p0; return;endelseshr=u2+c2;if s >= shrrf=r2; uf=u2; pf=p2; return;elsecmr=c2*(p0/p2)^g(1); str=u0+cmr;if s <= strrf=r2*(p0/p2)^g(8); uf=u0; pf=p0; return;elseuf=g(5)*(-c2+g(7)*u2+s); c=g(5)*(c2-g(7)*(u2-s));rf=r2*(c/c2)^g(4); pf=p2*(c/c2)^g(3);return;endendendendreturn;% Solves Riemann problem and computes fluxes for method of S. K. Godunov% r1, u1, p1 parameters in left cell% r2, u2, p2 parameters in right cell% rf, uf, pf parameters on the interface% c1, c2 sound speeds in left and right cells% s1, sr velocties of the fronts of S(hock)W(ave)s% shl, shr velocties of the fronts of the heads of R(arefaction)Ws% stl, str velocties of the tails of RWsfunction [f1,f2,f3]=flux_godunov(sl1,sl2,sl3,sr1,sr2,sr3,g)r1=sl1; u1=sl2/r1; p1=(1./g(8)-1.)*(sl3-0.5*sl2*u1);r2=sr1; u2=sr2/r2; p2=(1./g(8)-1.)*(sr3-0.5*sr2*u2);% sound speeds in left and right cellsc1 = sqrt(p1/(r1*g(8)));c2 = sqrt(p2/(r2*g(8)));du=u2-u1;% Vacuum solution。

偏微分方程数值解法试题与答案

偏微分方程数值解法试题与答案

一.填空(1553=⨯分)1.若步长趋于零时,差分方程的截断误差0→lmR ,则差分方程的解lm U 趋近于微分方程的解lm u . 此结论_______(错或对); 2.一阶Sobolev 空间{})(,,),()(21Ω∈''=ΩL f f f y x f H y x关于内积=1),(g f _____________________是Hilbert 空间;3.对非线性(变系数)差分格式,常用 _______系数法讨论差分格式的_______稳定性; 4.写出3x y =在区间]2,1[上的两个一阶广义导数:_________________________________, ________________________________________;5.隐式差分格式关于初值是无条件稳定的. 此结论_______(错或对)。

二.(13分)设有椭圆型方程边值问题用1.0=h 作正方形网格剖分 。

(1)用五点菱形差分格式将微分方程在内点离散化; (2)用截断误差为)(2h O 的差分法将第三边界条件离散化; (3)整理后的差分方程组为 三.(12)给定初值问题xut u ∂∂=∂∂ , ()10,+=x x u 取时间步长1.0=τ,空间步长2.0=h 。

试合理选用一阶偏心差分格式(最简显格式), 并以此格式求出解函数),(t x u 在2.0,2.0=-=t x 处的近似值。

1.所选用的差分格式是: 2.计算所求近似值:四.(12分)试讨论差分方程()ha h a r u u r u u k l k l k l k l ττ+-=-+=++++11,1111逼近微分方程0=∂∂+∂∂xu a t u 的截断误差阶R 。

思路一:将r 带入到原式,展开后可得格式是在点(l+1/2,k+1/2)展开的。

思路二:差分格式的用到的四个点刚好是矩形区域的四个顶点,可由此构造中心点的差分格式。

(完整word版)偏微分方程数值解习题解答案

(完整word版)偏微分方程数值解习题解答案

L试讨论逼近对蘇程詈+若。

的差分沁1)2)q1 二:行口匚1)解:设点为(X ? ,/曲)屮则町=讥心厶)=班勺厶+J + °(工心)(Y )+0(F ).ot所以截断误差为:3E=丄 ------ + ---- 「 T h 啰_喟+竺护一 o (F )T= 0(T + 力”2)解:设点为:(X y ,/林1 ) 3则町=讥勺,_)=以E ,_+1)+ (Y ) +o (巧卩 ot “;:;=班心+1 厶+i )=叽厶+i )+滋( h )+ * 臥工心)(为 2)+o ox (X)d心;=班心亠心)=班心,/+1)+敕:;D (一力)+ 3 役;D(血 2)+0(亥2)«截断误差为:2舟A 1 ” E= ------------ + ------------ — (―+ _) T h dt dx叭:=班%厶+i )+敗?心)(_勿+0 @2)〜dx-(史+空八dt dx 呼1_吋】+竺丛Q —O (X )-(叱 3 +dtdx 22・试用积分插值法推导知铁。

逼近的差分裕式班勺厶叙)一班勺,乩i)+ ——-——£)dtTq2 “-” *\ | (— 4- —)dxdt = | (un t 4- un x)ds = 0* dt & \得-U] /J+U2 r+x^ A-u4 r = 0+JE (j-l? n)F (j,n)G (j^n+l)H (j-l,n+l)^% ~ 的=旳=竹“4 = W/-lMf MTh=h T-T-ll"h + LL r H + ll:4h —LL:N =Op第二章第三章第四章第五章第六章P781.如果①'(0)二0,则称工。

是』(0)的驻点(或稳定:点)-设矩阵A对称(不必正定),求证忑是』(工)的驻点.的充要条件是1心是方程加二&的解B 42・ 试用积分插值法推导知铁。

逼近的差分裕式证: 充分性:①⑻二J 缶)+ 乂(加° -b t ^+—(Ax r x)①'(Ji) = (Ax c - A, x) + A{Ax r x) aEff))S 宀沪若①0)二Q,即(山° 一氛对=0 心怎宀A X Q -h = ()目卩 Ax-b^则帀是方程Ax^b 的解卩 必要性*若心是芳程A^ = b^\解则 Ax a —h - 0 (J 4X 0 — Z?,x) = 0+^◎ (0)=(吐命-b t x) - 0+J所以町是』0)的驻点dpg%3:证明非齐次两点边值间题心現(&)二 e it (E)二 Qu与T 7面的变分间题等价:求血EH 】,认@) = G 使 J(w t ) = min J(y)其中心SiuHU (2)-d』(#) =壬仗站)-(7» —芒⑹戲(D) +而久込叭如(2.13)(提示;先把边值条件齐衩化)+d dxO 字)+梓二/ ax13页证明:令 = w(x) + v(x)其中 w(x) = Q + (x-a)0 w(a) = a yv @) = “v(a) = 0 v(^>) = 0®所以2S = 瞥+qu = j DX DX Pd r /w 血、《, 乂 、 f"丁〔P(T + :F)]+Q(W + V )" ax dx ax* 丫 d z dv. 产 / d dw 、 豪 令 = - — O —) +(?v = /-(- —^> — +^w) = y;^ ax ax dx ax 所以(1)的等价的形式2厶” =一?0 字)= 卩ax axu(a) = a u\b) = 0a其中久=/-(-£■去字+0W )"ax ax 则由定理22知,讥是辺值间题(2)的解的充要条件是 且满定变分方程"ogf)-C/i 小 0 Vve^Pr (Zv> 一 /j )tdx + p @»: (b)f @) ① W = J(u) = J(u.+^)^— a (u^ + 兔,以.+ 无)一(/,功・ +加)[以・(E )+加@)] 2 □2=J(认)+ N[a@・,f)-(/,£)-+乙agd-Qfm 沁卜• Q dx dx 「(加•一/)加x +卩@加:(砂@)-卩@)戊@) Ja(3) => (4)所以可证得• 3必要性:若如 是边值间题(1)的解。

偏微分方程数值解期末试题及参考答案

偏微分方程数值解期末试题及参考答案

《偏微分方程数值解》试卷参考答案与评分标准专业班级信息与计算科学开课系室考试日期 2006.4.14命题教师王子亭偏微分方程数值解试题(06A)参考答案与评分标准信息与计算科学专业一(10分)、设矩阵A 对称正定,定义)(),(),(21)(n R x x b x Ax x J ∈-=,证明下列两个问题等价:(1)求n R x ∈0使 )(min )(0x J x J nRx ∈=;(2)求下列方程组的解:b Ax =解: 设n R x ∈0是)(x J 的最小值点,对于任意的n R x ∈,令),(2),()()()(2000x Ax x b Ax x J x x J λλλλϕ+-+=+=, (3分)因此0=λ是)(λϕ的极小值点,0)0('=ϕ,即对于任意的n R x ∈,0),(0=-x b Ax ,特别取b Ax x -=0,则有0||||),(2000=-=--b Ax b Ax b Ax ,得到b Ax =0. (3分) 反之,若nR x ∈0满足bAx =0,则对于任意的x ,)(),(21)0()1()(00x J x Ax x x J >+==+ϕϕ,因此0x 是)(x J 的最小值点. (4分)评分标准:)(λϕ的表示式3分, 每问3分,推理逻辑性1分二(10分)、 对于两点边值问题:⎪⎩⎪⎨⎧==∈=+-=0)(,0)(),()(b u a u b a x f qu dxdu p dx d Lu 其中]),([,0]),,([,0)(min )(]),,([0min ],[1b a H f q b a C q p x p x p b a C p b a x ∈≥∈>=≥∈∈建立与上述两点边值问题等价的变分问题的两种形式:求泛函极小的Ritz 形式和Galerkin 形式的变分方程。

解: 设}0)()(),,(|{110==∈=b u a u b a H u u H 为求解函数空间,检验函数空间.取),(10b a H v ∈,乘方程两端,积分应用分部积分得到 (3分))().(),(v f fvdx dx quv dxdv dx du pv u a b a ba ==+=⎰⎰,),(10b a H v ∈∀ 即变分问题的Galerkin 形式. (3分)令⎰-+=-=b a dx fu qu dxdup u f u u a u J ])([21),(),(21)(22,则变分问题的Ritz 形式为求),(10*b a H u ∈,使)(min )(1*u J u J H u ∈= (4分)评分标准:空间描述与积分步骤3分,变分方程3分,极小函数及其变分问题4分,三(20分)、对于边值问题⎪⎩⎪⎨⎧=⨯=∈-=∂∂+∂∂∂0|)1,0()1,0(),(,12222G u G y x yux u (1)建立该边值问题的五点差分格式(五点棱形格式又称正五点格式),推导截断误差的阶。

偏微分方程数值解法题解

偏微分方程数值解法题解

偏微分方程数值解法(带程序)例1 求解初边值问题22,(0,1),012,(0,]2(,0)12(1),[,1)2(0,)(1,)0,0u ux t t x x x u x x x u t u t t ⎧⎪⎪⎪⎧⎨⎪⎪⎪⎨⎪⎪⎪⎪⎩⎩∂∂=∈>∂∂∈=-∈==>要求采用树脂格式 111(2)n n n n nj j j j j u u u u u λ++-=+-+,2()tx λ∆=∆,完成下列计算: (1) 取0.1,0.1,x λ∆==分别计算0.01,0.02,0.1,t =时刻的数值解。

(2) 取0.1,0.5,x λ∆==分别计算0.01,0.02,0.1,t =时刻的数值解。

(3) 取0.1, 1.0,x λ∆==分别计算0.01,0.02,0.1,t =时刻的数值解。

并与解析解22()22181(,)sin()sin()2n t n u n x t n x e n ππππ∞-==∑进行比较。

解:程序function A=zhongxinchafen(x,y,la) U=zeros(length(x),length(y)); for i=1:size(x,2)if x(i)>0&x(i)<=0.5 U(i,1)=2*x(i); elseif x(i)>0.5&x(i)<1 U(i,1)=2*(1-x(i)); end endfor j=1:length(y)-1for i=1:length(x)-2U(i+1,j+1)=U(i+1,j)+la*(U(i+2,j)-2*U(i+1,j)+U(i,j)); end endA=U(:,size(U,2))function u=jiexijie1(x,t) for i=1:size(x,2) k=3;a1=(1/(1^2)*sin(1*pi/2)*sin(1*pi*x(i))*exp(-1^2*pi^2*t));a2=a1+(1/(2^2)*sin(2*pi/2)*sin(2*pi*x(i))*exp(-2^2*pi^2*t));while abs(a2-a1)>0.00001a1=a2;a2=a1+(1/(k^2)*sin(k*pi/2)*sin(k*pi*x(i))*exp(-k^2*pi^2*t));k=k+1;endu(i)=8/(pi^2)*a2;endclc; %第1题第1问clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.001:t1];y2=[0:0.001:t2];y3=[0:0.001:t3];la=0.1;subplot(131)A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);hold online(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2)line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3)line(x,A3,'color','r','linestyle',':','linewidth',1.5);line(x,u3,'color','b','linewidth',1); title('例1(1)');subplot(132);line(x,u1,'color','b','linewidth',1);line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解');subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5);line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解');clc; %第1题第2问clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.005:t1];y2=[0:0.005:t2];y3=[0:0.005:t3];la=0.5;subplot(131);A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);hold online(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2)line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3)line(x,A3,'color','r','linestyle',':','linewidth',1.5); line(x,u3,'color','b','linewidth',1);title('例1(2)'); subplot(132);line(x,u1,'color','b','linewidth',1); line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解'); subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5); line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解');clc; %第1题第3问 clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.01:t1];y2=[0:0.01:t2];y3=[0:0.01:t3];la=1.0; subplot(131);A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);hold on line(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2) line(x,A2,'color','r','linestyle',':','linewidth',1.5); line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3) line(x,A3,'color','r','linestyle',':','linewidth',1.5); line(x,u3,'color','b','linewidth',1);title('例1(3)'); subplot(132);line(x,u1,'color','b','linewidth',1); line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解'); subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5); line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解'); 运行结果:表1:取0.1,0.1,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解表2:取0.1,0.5,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解表3:取0.1, 1.0,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解图1:取0.1,0.1,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解图2:取0.1,0.5,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解图3:取0.1, 1.0,x λ∆==0.01,0.02,0.1,t =时刻的解析解与数值解例2 用Crank-Nicolson 格式完成例1的所有任务。

偏微分方程解的几道算例(差分、有限元)-含matlab程序(1)

偏微分方程解的几道算例(差分、有限元)-含matlab程序(1)
A(i,i)=r2; if i>1
A(i-1,i)=-r; A(i,i-1)=-r; end end u=zeros(N+1,M+1); u(N+1,:)=u1; for k=1:N b=u(N+2-k,2:M)+0.02; u(N+1-k,2:M)=inv(A)*b';%求解迭代方程组 end uT=u(1,:);%0.25时刻的解 %精确解与数值解画图 x1=[0,x,1]; plot(x1,uT,'o') hold u_xt = exp (-pi*pi*T)*sin (pi*x1) + x1.*(1 - x1); plot (x1, u_xt, ' r') e=u_xt-uT; 六点格式 function [e]=six(dx,dt,T) %用六点对称格式求解,dx为x方向步长,dt为t方向步长 % e为误差 M=1/dx; N=T/dt; %得到第一层的值 u1=zeros(1,M+1); x=[1:M-1]*dx; u1([2:M])= sin(pi*x)+x.*(1 - x); %网比 r=dt/dx/dx;r2=2+2*r;r3=2-2*r; %构造三对角矩阵A for i=1:M-1 A(i,i)=r2;
0.0070 0.0027
-0.0097 -0.0037
-0.0013 -0.0005
0.0082 0.0000
-0.0114 0.0000
-0.0015 0.0000
0.0087 -0.0120
-0.0016
注:这里的"误差"=精确解-数值解. 2.精确解与数值解结果图像对比
“向前差分格式”:

偏微分方程数值解

偏微分方程数值解

偏微分⽅程数值解中南林业科技⼤学偏微分⽅程数值解法学⽣姓名:学号:学院:专业年级:设计题⽬:⼀维热传导⽅程⼏种差分格式2012年07⽉⼀维热传导⽅程22()u ua f x t x=+ 0t T ≤≤ (0)a > 定解条件:1.初值问题(Cauchy 问题) (,0)()u x x x ?=-∞<<+∞2.初边值问题(混合问题)(,0)()0(0,)(,)00u x x x l u t u l t t T=<<==≤≤物理意义:有限长细杆的温度(两端温度不⼀定为0,⼀般为 (0,)(),(,)()0u t t u l t t t T αβ==≤≤,这⾥取成0为⽅便计算)⽅程中的条件为第⼀边值条件,也可有第⼆、三类边值条件: 102102(0,)()()(0,)(),(,)()()(,)().u t t t u t t xu l t t t u l t t xαααβββ?+=??+=?这⾥的系数,i i αβ应满⾜⼀定的条件(见书)。

它们实际上包含了第⼀、第⼆、第三类边界条件。

假定f ,?在区域上充分光滑,则问题的解存在且唯⼀。

现考虑边值问题的差分格式。

对区域进⾏分割:{0;0}G x l t T =≤≤≤≤⽤平⾏直线族0,1,,0,1,,j k x x jh j N t t k k Mτ======分割G ,(,)j k x t 为节点,记为(,)j k ,h 称为空间步长,τ称为时间步长。

记{(,)(,)}{(,)(,)}h h G j k j k G G j k j k G =∈=∈⽤k j u 表⽰定义在⽹点(,)j k x t 的⽹函数,0j N ≤≤,0k M ≤≤。

⽤不同的差商代替⽅程中的偏微商,可得差分格式。

⼀.向前差分格式(古典显格式)1112002()(),01,,1,1,,1k k k k k j j j j j j j j k k N jj j u u u u u a f f f x h u x u u j N k M τ??++---+=+======-=-两τ,记2a r hτ=(称为⽹⽐)则上式可写成便于计算的形式:(1k +层在左边,k 层在右边)111(2)0,1,,1k k k k k j j j j j ju u r u u u f k M τ++-=+-++=-取000j jkkN u u u===,依次可算出各层上的值k j u 。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档