计算匿名函数的雅可比行列式 - MATLAB

发布于 2025-01-11 07:46:19 字数 1420 浏览 0 评论 0原文

我正在尝试在 Matlab 中求解非线性颂歌系统,如下所示。

editparams %parameters
Tend = 50;
Nt = 100;


% Define RHS functions

RHS = @(t,x) ModelRHS(t,x,param); %anonymous function defining the set of equations

%Execution-----------------------------------------------------------------
x0 =[0.04;0.75;0.85]; %Initial condition

t = linspace(0,Tend,Nt); %TSPAN
[t x] = ode45(RHS, t, x0);

现在,我需要找到系统的稳定状态,我正在尝试为此创建一个函数。我想我应该使用雅可比行列式来计算稳态。我的方程位于一个匿名函数中,在下面的代码中定义为 f 。但是,我意识到 jacobian 不适用于匿名函数(或者可能有一种方法可以处理匿名函数)。所以我想我应该将匿名函数转换为符号函数并尝试一下。但 我仍然很难完成这项工作。所以非常感谢任何帮助!

function SS = SteadyState(param, E)

f = @(t,x)ModelRHS(t,x,param,E); %set of odes

SymbolicSystem = sym(f); %trying to make the anonymous function symbolic

SymbolicJacobian = jacobian(SymbolicSystem',x); %jacobian 
Jacob = matlabFunction(SymbolicJacobian,x);

end

另外,如果除了找到雅可比行列式之外还有其他方法,也请告诉我。 我尝试使用“fsolve”来计算稳态,如下所示:

f = @(t,x)ModelRHS(t,x,param);
x0 =[0.04;0.75;0.85]';

options = optimoptions('fsolve','Display','iter'); % Option to display output
SS = fsolve(f,x0,options); % Call solver

但它返回了一个错误

    Not enough input arguments.

Error in @(t,x)ModelRHS(t,x,param)

Error in fsolve (line 242)
            fuser = feval(funfcn{3},x,varargin{:});

Caused by:
    Failure in initial objective function evaluation. FSOLVE cannot continue.

I'm trying to solve a system of non linear odes in Matlab as follows.

editparams %parameters
Tend = 50;
Nt = 100;


% Define RHS functions

RHS = @(t,x) ModelRHS(t,x,param); %anonymous function defining the set of equations

%Execution-----------------------------------------------------------------
x0 =[0.04;0.75;0.85]; %Initial condition

t = linspace(0,Tend,Nt); %TSPAN
[t x] = ode45(RHS, t, x0);

Now, I need to find the steady state of the system and I'm trying to create a function for this. I thought I'd calculate the steady state using the Jacobian. My equations are in an anonymous function which is defined as f in the code below. However, I realised that jacobian does not work for anonymous functions (or may be there is a way to do with anonymous functions) . so I thought I would convert the anonymous function to a symbolic function and try it. But
i still have a difficulty in getting that done. So any help is really appreciated!

function SS = SteadyState(param, E)

f = @(t,x)ModelRHS(t,x,param,E); %set of odes

SymbolicSystem = sym(f); %trying to make the anonymous function symbolic

SymbolicJacobian = jacobian(SymbolicSystem',x); %jacobian 
Jacob = matlabFunction(SymbolicJacobian,x);

end

Also if there is any other way apart from finding the Jacobian, kindly let me know about that too.
I tried using 'fsolve' to calculate the steady-state as follows:

f = @(t,x)ModelRHS(t,x,param);
x0 =[0.04;0.75;0.85]';

options = optimoptions('fsolve','Display','iter'); % Option to display output
SS = fsolve(f,x0,options); % Call solver

but it returned an error

    Not enough input arguments.

Error in @(t,x)ModelRHS(t,x,param)

Error in fsolve (line 242)
            fuser = feval(funfcn{3},x,varargin{:});

Caused by:
    Failure in initial objective function evaluation. FSOLVE cannot continue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文