gpt4 book ai didi

matlab - 使用 ODE45 查找函数的最大值

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:54 26 4
gpt4 key购买 nike

我试图在 MATLAB 的微分方程组中找到其中一个方程的位置。我正在尝试使用 odeset 的事件属性。如何在我的函数中挑选出特定的方程?

options = odeset('Events',@event);
[t x tm xm ie] = ode45(@Lorenz,[0 200],I,options);


function X = Lorenz(t,x)
r = 15;
sigma = 10;
b = 8/3;
X(1,1) = sigma*(x(2,1)-x(1,1));
X(2,1) = r*(x(1,1)) - x(2,1) -x(1,1)*x(3,1);
X(3,1) = x(1,1)*x(2,1) - b*x(3,1);
end

function [value,isterminal,direction] = event(t,x)
value = Lorenz(t,x); %I can't specify X(3,1) here
isterminal = 0;
direction = -1;
end

特别是当 X(3,1) = 0 时,我尝试记录。

谢谢

最佳答案

基本上,查看 documentation ,如果您有兴趣查看何时 x(3) = 0,那么您需要重写您的事件函数:

function [value,isterminal,direction] = event(t,x)
value = x(3); %I can't specify X(3,1) here --> why not?? Lorenz(t,x) is going to return the differential. That's not what you want
isterminal = 0;
direction = 0; %The desired directionality should be "Detect all zero crossings"
end

现在我不知道你是怎么定义I

[t x tm xm ie] = ode45(@Lorenz,[0 200],I,options);

但是方程的解在几个点附近非常稳定,如果 x(3) 在零时刻为负,您可能只会看到一个零交叉点。

[t x tm xm ie] = ode45(@khal,[0 5],[10 -1 -20],options);
tm =

0.1085

enter image description here

关于matlab - 使用 ODE45 查找函数的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16598558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com