Example 6.8
Burgers Equations
Contents
Initialization
close all; clear N f dX X dt t x D l j u N = 32; f = @(x) 10*sin(x); dX = 2*pi/N; X = [0:dX:2*pi-dX]'; dt = 0.005; t = 0; x = [0:0.01:2*pi]; plot(x,f(x),'k','LineWidth',2); hold on;
![](ch6ex8_01.png)
Create Differentiation matrix :
D = zeros(N,N); for l = [1:N] for j = [1:N] if l~=j D(l,j) = 0.5*(-1)^(l-j)/tan(pi*(l-j)/N); end; end; end;
Iterate and plot :
u = f(X); for t = [dt:dt:1] u = u + dt*(D*D*u - diag(u)*D*u); switch t case .1 plot(X,u,'ko'); case .2 plot(X,u,'kx'); case .4 disp('here') plot(X,u,'k*'); case .6 plot(X,u,'ks'); end; end; legend('t=0','t=0.1','t=0.2','t=0.4','t=0.6')
here
![](ch6ex8_02.png)