如何求解具有z(inf)
等边界条件的2 nd 阶微分方程?
2(x+0.1)·z'' + 2.355·z' - 0.71·z = 0
z(0) = 1
z(inf) = 0
z'(0) = -4.805
我无法理解在z(inf)
函数中使用边界值ode45()
的位置。
我在以下条件[z(0) z'(0) z(inf)]
中使用,但这并不能提供准确的输出。
function [T, Y]=test()
% some random x function
x = @(t) t;
t=[0 :.01 :7];
% integrate numerically
[T, Y] = ode45(@linearized, t, [1 -4.805 0]);
% plot the result
plot(T, Y(:,1))
% linearized ode
function dy = linearized(t,y)
dy = zeros(3,1);
dy(1) = y(2);
dy(2) = y(3);
dy(3) = (-2.355*y(2)+0.71*y(1))/((2*x(t))+0.2);
end
end
请帮我解决这个微分方程。
答案 0 :(得分:1)
你手上似乎有一个相当高级的问题,但对MATLAB和/或ODE理论知之甚少。如果你愿意,我很乐意解释更多,但这应该是聊天(我会邀请你)或通过个人电子邮件(我的姓氏来自Google DOT com最受欢迎的邮件服务)< / p>
现在您已经澄清了一些事情并解释了整个问题,事情变得更加清晰,我能够找到合理的解决方案。我认为以下内容至少是您需要做的总体方向:
function [tSpan, Y2, Y3] = test
%%# Parameters
%# Time parameters
tMax = 1e3;
tSpan = 0 : 0.01 : 7;
%# Initial values
y02 = [1 -4.805]; %# second-order ODE
y03 = [0 0 4.8403]; %# third-order ODE
%# Optimization options
opts = optimset(...
'display', 'off',...
'TolFun' , 1e-5,...
'TolX' , 1e-5);
%%# Main procedure
%# Find X so that z2(t,X) -> 0 for t -> inf
sol2 = fminsearch(@obj2, 0.9879680932400429, opts);
%# Plug this solution into the original
%# NOTE: we need dense output, which is done via deval()
Z = ode45(@(t,y) linearized2(t,y,sol2), [0 tMax], y02);
%# plot the result
Y2 = deval(Z,tSpan,1);
plot(tSpan, Y2, 'b');
%# Find X so that z3(t,X) -> 1 for t -> inf
sol3 = fminsearch(@obj3, 1.215435887288112, opts);
%# Plug this solution into the original
[~, Y3] = ode45(@(t,y) linearized3(t,y,sol3), tSpan, y03);
%# plot the result
hold on, plot(tSpan, Y3(:,1), 'r');
%# Finish plots
legend('Second order ODE', 'Third order ODE')
xlabel('T [s]')
ylabel('Function value [-]');
%%# Helper functions
%# Function to optimize X for the second-order ODE
function val = obj2(X)
[~, y] = ode45(@(t,y) linearized2(t,y,X), [0 tMax], y02);
val = abs(y(end,1));
end
%# linearized second-order ODE with parameter X
function dy = linearized2(t,y,X)
dy = [
y(2)
(-2.355*y(2) + 0.71*y(1))/2/(X*t + 0.1)
];
end
%# Function to optimize X for the third-order ODE
function val = obj3(X3)
[~, y] = ode45(@(t,y) linearized3(t,y,X3), [0 tMax], y03);
val = abs(y(end,2) - 1);
end
%# linearized third-order ODE with parameters X and Z
function dy = linearized3(t,y,X)
zt = deval(Z, t, 1);
dy = [
y(2)
y(3)
(-1 -0.1*zt + y(2) -2.5*y(3))/2/(X*t + 0.1)
];
end
end
答案 1 :(得分:0)
正如我在上面的评论中所说,我认为你混淆了几件事。我怀疑这是要求的:
function [T,Y] = test
tMax = 1e3;
function val = obj(X)
[~, y] = ode45(@(t,y) linearized(t,y,X), [0 tMax], [1 -4.805]);
val = abs(y(end,1));
end
% linearized ode with parameter X
function dy = linearized(t,y,X)
dy = [
y(2)
(-2.355*y(2) + 0.71*y(1))/2/(X*t + 0.1)
];
end
% Find X so that z(t,X) -> 0 for t -> inf
sol = fminsearch(@obj, 0.9879);
% Plug this ssolution into the original
[T, Y] = ode45(@(t,y) linearized(t,y,sol), [0 tMax], [1 -4.805]);
% plot the result
plot(T, Y(:,1));
end
但我不能让tMax
超过1000秒再收敛。您可能会遇到ode45
能力w.r.t的限制。准确度(切换到ode113
),或者您的初始值不够准确等等。