用MATLAB求解刚性的耦合偏微分方程

时间:2017-11-05 09:41:57

标签: matlab

我想求解一阶的耦合偏微分方程,它们具有刚性。我已经在MATLAB中编码来解决这个问题,我使用了Method of line将PDE转换为ODE,并且我使用了beam和warmings(二阶迎风)方法来区分空间导数。离散化方法是消除振荡的总变差减小(TVD)。但是,使用TVD和ode15s求解器来整合合成的僵硬颂歌,结果曲线是振荡的(不是平滑的)。我该怎么做才能消除这种振荡并获得正确的结果。

我已附上我的MATLAB代码..请查看并提出一些改进建议。

∂y(1)/∂t=-0.1 ∂y(1)/∂x + (0.5*e^(15*(y(2)⁄(1+y(2))))*(1- y(1))

∂y(2)/∂t=-0.1 ∂y(2)/∂x - (0.4*e^(15*(y(2)⁄(1+y(2))))*(1- y(1))-0.4

Initial condition:  at  t = 0         y(1)= y(2)=0
Boundary condition:               y(1)= y(2) = 0              at   x=0

我已附上我的MATLAB代码..请查看并提出一些改进建议。

function brussode(N)

if nargin<1
    N = 149;
end

tspan = [0 10];
m = 0.00035
t = (1:N)/(N+1)*m;
y0 = [repmat(0,1,N); repmat(0,1,N)];
p = 0.5
q = 0.4

options = odeset('Vectorized','on','JPattern',jpattern(N));

[t,y] = ode15s(@f,tspan,y0,options);

a = size(y,2)
u = y(:,1:2:end);
x = (1:N)/(N+1);
figure;
%surf(x,t(end,:),u);
plot(x,u(end,:))
xlabel('space');
ylabel('solution');
zlabel('solution u');

%--------------------------------------------------------------
%Nested function -- N is provided by the outer function.
%
    function dydt = f(t,y)
        %Derivative function

        dydt = zeros(2*N,size(y,2));    %preallocate dy/dt

        x = (1:N)/(N+1);
        % Evaluate the 2 components of the function at one edge of the grid
        % (with edge conditions).
        i = 1;
        %y(1,:) = 0;
        %y(2,:) = 0;
        dydt(i,:) = -0.1*(N+1)*(y(i+2,:)-0)+ (0.01/2)*m*((N+1).^3)*(y(i+2,:)-0) + p*exp(15*(0/(1+0)))*(1-0);
        dydt(i+1,:) = -0.1*(N+1)*(y(i+3,:)-0)+ (0.01/2)*m*((N+1).^3)*(y(i+3,:)-0) - q*exp(15*(0/(1+0)))*(1-0)+0.25;


        i = 3;
        %y(1,:) = 0;
        %y(2,:) = 0;
        dydt(i,:) = -0.1*(N+1)*(y(i+2,:)-y(i,:)) + (0.01/2)*m*((N+1).^3)*(y(i+3,:)-y(i,:)) + p*exp(15*(y(i+1,:)/(1+y(i+1,:))))*(1-y(i,:));
        dydt(i+1,:) = -0.1*(N+1)*(y(i+3,:)-y(i+1,:)) + (0.01/2)*m*((N+1).^3)*(y(i+3,:)-y(i,:)) - q*exp(15*(y(i+1,:)/(1+y(i+1,:))))*(1-y(i,:))+0.25;


        %Evaluate the 2 components of the function at all interior grid
        %points.
        i = 5:2:2*N;
        %y(1,:) = 0;
       % y(2,:) = 0;
        dydt(i,:) = (-0.1/2)*(N+1)*(3*y(i,:)-4*y(i-2,:)+y(i-4,:)) +(0.01/2)*m*((N+1).^3)*(y(i,:)-2*y(i-2,:)+y(i-4,:))+ p*exp(15*(y(i+1,:)/(1+y(i+1,:))))*(1-y(i,:));
        dydt(i+1,:) = (-0.1/2)*(N+1)*(3*y(i+1,:)-4*y(i-1,:)+y(i-3,:))+(0.01/2)*m*((N+1).^3)*(y(i+1,:)-2*y(i-1,:)+y(i-3,:)) - q*exp(15*(y(i+1,:)/(1+y(i+1,:))))*(1-y(i,:))+0.25;


    end
%-------------------------------------------------------------

end  %brussode

%-------------------------------------------------------------
% Subfunction -- the sparsity pattern
%

function S = jpattern(N)
% Jacobian sparsity patter
B = ones(2*N,5);
B(2:2:2*N,2) = zeros(N,1);
B(1:2:2*N-1,4) = zeros(N,1);
S = spdiags(B,-2:2,2*N,2*N);
end
%-------------------------------------------------------------

0 个答案:

没有答案