【发布时间】:2016-05-21 14:24:31
【问题描述】:
我正在使用ode45 在 Matlab 中求解/绘制二阶微分方程。我的tspan 是从 0 到 0.25。但是接近零的初始条件定义不明确(斜率趋于无穷大,复数值)。 0.25 附近的条件定义明确(斜率和值均为零)。
问题:
我可以反转
tspan,并使用“最终条件”作为初始条件吗?嗯,我知道我能做到(见下面的代码),我得到的情节看起来像我所期望的那样,但一般来说这是一个有效的事情吗?在这种情况下我很幸运吗?
ode45提供数值解,并不精确。反转tspan后可能会出现更大的错误吗?
这是我的代码,应该独立运行:
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 ];
【问题讨论】:
标签: matlab differential-equations numerical-integration ode45