⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 burgers_main.m

📁 有关the method of line即MOL算法的matlab代码
💻 M
字号:
%...
%... Burgers equation
%...
%... Authors: A. Vande Wouwer, P. Saucez, W.E. Schiesser (2003)
%...
%... The well known Burgers equation:
%...
%... x  = -(0.5x^2)  + mu*x   = -x*x  + mu*x   
%...  t            z       zz       z       zz
%...
%...
%... where
%...
%...  x      dependent variable
%...
%...  t       time
%...
%...  z       space
%...
%...  mu      diffusion coefficient
%...
%...
%... an exact solution is given by
%...
%... x(z,t) = burgers_exact(z,t)
%...
%... the boundary conditions (BCs) for Burgers' equation are taken as
%...
%... x(z=z0,t) = burgers_exact(z0,t)     (Dirichlet BCs)
%...
%... x(z=zL,t) = burgers_exact(zL,t)               
%...
%... where
%...
%...  zL      spatial domain
%...
%... the initial condition (IC) for Burgers' equations are taken as
%...
%... x(z,t=0) = burgers_exact(z,0)
%...
%... the following code computes a solution to Burgers' equation
%...
     close all
     clear all
%...
%... start a stopwatch timer
     tic
%...
%... set global variables
     global mu;
     global z0 zL n D1 D2;
%...
%... spatial grid
     z0=0.0;
     zL=1.0;
     n=201;
     dz=(zL-z0)/(n-1);
     z=[z0:dz:zL]';
%...
%... model parameter
     mu=0.001;
%...
%... initial conditions
     for i=1:n,
       x(i) = burgers_exact(z(i),0);
     end;
%...
%... select finite difference (FD) approximation of the spatial
%... derivative
%...
%      method = 'centered'          %... three point centered approximation
%...
%      method = 'upwind'           %... two point upwind approximation
%...
      method = 'biased_upwind'    %... five point, biased upwind approximation
%...
     switch method    
%...
%... three point centered approximation
       case('centered')
           D1=three_point_centered_uni_D1(z0,zL,n);
%... two point upwind approximation
       case('upwind')
           v = 1;
           D1=two_point_upwind_uni_D1(z0,zL,n,v);
%... five point, biased upwind approximation
       case('biased_upwind')
           v = 1;
           D1=five_point_biased_upwind_uni_D1(z0,zL,n,v);
%...
     end
%...
%... differentiation matrix (diffusive term - stagewise differentiation)
%     D2=three_point_centered_uni_D1(z0,zL,n);
      D2=five_point_centered_uni_D1(z0,zL,n);
%...  
%... call to ODE solver 
%...
     t=[0:0.1:1];
     options = odeset('RelTol',1e-3,'AbsTol',1e-3,'Stats','on');
%...     
     [tout, yout] = ode15s('burgers_pde',t,x,options);
     plot(z,yout,'k');
     xlabel('z');
     ylabel('x(z,t)');
     title('Burgers equation')
     hold on
%...     
     for k=1:length(tout),
         for i=1:n,
             yexact(i) = burgers_exact(z(i),tout(k));
         end;
         plot(z,yexact,':k')
     end;
%...
%... read the stopwatch timer
     tcpu=toc;

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -