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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Laura
le 27 Mai 2015
Réponse apportée : Walter Roberson
le 27 Mai 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 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!