How to Covert a Symbolic Jacobian to a Numerical Matrix that can be Used by ODE15s-- the Jacobian Contains Fewer Variables than the Original System

11 ビュー (過去 30 日間)
I am currently working with a system of 27 ODE's. I am attempting to solve the system using ode15s and because of the nature of this problem I need to include the precalculated Jacobian.
I have written a MATLAB function to calculate the symbolic Jacobian of the system, but am having trouble with the conversion of the symbolic matrix into a numeric structure that can be used by ode15s.
The problem I am having is that although the original system contains 27 state variables, the Jacobian only contains 8. Thus I cannot input a vector of the dependent variables into the Jacobian as is necessary for ode15s.
Here is a minimal code that describes what I am trying to do:
function Jacob = Jacobian
syms x y z
w = [x, y, z];
wp(1) = 2*x + y + z;
wp(2) = x^2 -4*y;
wp(3) = z^3 -x;
SymJacob = jacobian(wp',w);
Jacob = matlabFunction(SymJacob);
end
If I call this in the command window using
>> J = Jacobian
The output is:
@(x,z)reshape([2.0,conj(x).*2.0,-1.0,1.0,-4.0,0.0,1.0,0.0,conj(z).^2.*3.0],[3,3])
i.e. the Jacobian is a function of x and z but not y.
I need to somehow make the Jacobian a function of y so that I can input the entire vector of variables (J(x,y,z)).
Any help would be greatly appreciated!
Laura

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 27 日
Jacob = matlabFunction(SymJacob, 'vars', [x, y, z]);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by