用Matlab中的Newton-Raphson方法求解Burger方程

时间:2016-05-10 21:02:52

标签: matlab pde

我在Mathlab中使用Newton-Raphson方法求解Burger方程。 有关问题的描述,请参阅1

我的问题是以下代码找到解决方案的时间 $ t = 1 $,但此时不连续性发展,然后波动 向前移动(像步进功能),但这段代码不会产生 在$ t = 1 $之后的正确解决方案。

任何改进代码的建议或意见。

这是我正在使用的Matlab代码

function BurgerFSolve2
clc; clear;
% define a 1D mesh
a = -1; b = 3; Nx = 100;
x = linspace(a,b,Nx);
dx = (b-a)/Nx;
J = length(x); 

% Iinitial condition
p_init = zeros(size(x));
p_init(x<=0) = 1;
p_init(x>0 & x<1)= 1-x(x>0 & x<1);

% storing results
P = zeros(length(p_init),3001);
P(:,1) = p_init; 
% Boundary condition
pL = 1; pR = 0;  

% solver
dt = 0.001;
t = 0;
T = zeros(1,3001);
c = dt/dx;
for i = 1:3000
    t = t+dt;
    T(i+1) = t;

    options=optimset('Display','iter');   % Option to display output
    p = fsolve(@(p) myfun1(p, pL, pR, c, J, P(:,i)), p_init, ...
    options);         
    % Call solver 
    P(:,i+1) = p;
    p_init = p;

    figure(1);
    plot(x, p, '-o'); 
    title(['t= ' num2str(t) ' s']);
    drawnow;
end
end 

function F = myfun1(p, pL, pR, c, J, p_Old) 
% Rewrite the equation in the form F(x) = 0
F(1) = p(1) + c*(p(1)^2 - p(1)*pL) - p_Old(1);
for i=2:J-1 
    F(i) = p(i) + c*(p(i)^2 - p(i-1)*p(i)) - p_Old(i);
end
F(J) = p(J)  + c*(p(J)^2 - p(J-1)*p(J)) - p_Old(J);
end

0 个答案:

没有答案