Matlab:微分方程(ode45):我可以反转tspan以获得更好的初始条件吗?

时间:2016-02-11 00:27:52

标签: matlab differential-equations numerical-integration ode45

我使用ode45在Matlab中求解/绘制二阶微分方程。我的tspan是0到0.25。但接近于零的初始条件是不明确的(斜率变为无穷大,复数值)。 0.25附近的条件定义明确(斜率和值均为零)。

问题:

  1. 我可以撤消tspan,并使用"最终条件"作为初始条件?

  2. 嗯,我知道我可以做到(见下面的代码),我得到一个看起来像我期望的情节,但这一般是有效的吗?我在这一案中幸运吗?

  3. ode45提供了数值解,并不准确。逆转tspan后我可能会出现更大的错误吗?

  4. 这是我的代码,它应该独立运行:

    function ReverseTspan()
    % solve diff-eq backward from tspan end to tspan start using ode45()
    %  - Good initial conditions at the end, but not start.
    %  - Is this a valid thing to do?
    
    % clean slate
    clc; clear all; close all;
    
    % tspan - reversed!
    R = 0.25:-0.001:0;
    
    % initial values
    hinits=[0.0000001;0]; 
    
    % solve
    [R,v] = ode45(@equ7,R,hinits);
    
    % strip imaginary values (can't plot 'em)
    v(find(real(v)~=v)) = NaN;
    
    % plot first column 
    plot(R,v(:,1)); 
    
    
    function vprime = equ7(R,v);
    % Solve second order non-linear differential equation 7:
    %   v''(R) + 2/R*v'(R) = K_plus/(R^2)*( v^(-1/2) - lamda_plus*(1-v)^(-1/2)
    %
    % Matlab ode45 only likes first derivatives, so let:  
    %    v_1(R) = v(R)
    %    v_2(R) = v'(R)
    %
    % And create a system of first order diff eqs:
    %    v_1'(R) = v_2(R)
    %    v_2'(R) = -2/R*v_2(R) + K_plus/(R^2)*( v_1(R)^(-1/2) - lamda_plus*(1-v_1(R))^(-1/2)
    %
    % Constant Parameters:
    K_plus = 0.0859;
    lambda_plus = 3.7;
    
    % Build result in pieces for easier debugging of problematic terms
    int1 = 1 - v(1);
    int2 = int1^(-1/2);
    int3 = v(1)^(-1/2);
    int4 = K_plus/(R^2);
    vprime2 = -2/R*v(2);
    vprime2 = vprime2 + int4*( int3 - lambda_plus*(int2) );
    vprime=[v(2); vprime2 ];
    

1 个答案:

答案 0 :(得分:0)

从数字上讲,你永远无法使用该ODE开始(或获得)R=0。在您的初始条件之后,NaN将返回第一步,从而破坏未来的任何结果。有可能重新调整你的系统以摆脱奇点,但这是一个数学问题。如果指定有效的初始条件(满足您的ODE),您也可以尝试在大于零的时间开始集成。

  
      
  1. 我可以撤销tspan,并使用“最终条件”作为初始条件吗?
  2.   

是。这是一个标准程序。特别是,它经常被用来寻找不稳定的流形和不稳定的平衡。

  
      
  1. 嗯,我知道我可以做到(见下面的代码),我得到一个看起来像我期望的情节,但这一般是有效的吗?我在这一案中幸运吗?
  2.   

很难概括所有可能的系统。由于稳定性或数字错误的原因,有可能出现这种情况。

  
      
  1. ode45提供了数值解,并不准确。在撤消tspan后,我可能会出现更大的错误吗?
  2.   

我不明白为什么它必然会更大,但这又取决于所使用的系统和求解器。尝试使用其他解算器(例如,ode15sode113)和/或通过absolute and relative tolerances更改odeset

相关问题