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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Laura
el 27 de Mayo de 2015
Respondida: Walter Roberson
el 27 de Mayo de 2015
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Mayo de 2015
Jacob = matlabFunction(SymJacob, 'vars', [x, y, z]);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!