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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by