# Jacobian of a state matrix over time using jacobianest

5 views (last 30 days)
Shelley Snider on 20 Jun 2021
Edited: Matt J on 20 Jun 2021
I'm using the DERIVESTsuite toolbox to find the jacobian with respect to a state array over time. I have a function with inputs
1. `x`- state array (n x m). Where n is the number of states and m is the number of time nodes.
2. `u`- control vector (1 x m)
3. `t`- time vector (1 x m)
4. `constants`- structure of constants
I currently have my code looping through each time node to give me an nxn matrix for each time node.:
for i = length(t):-1:1 % Jacobian of state vector at each node
A(:,:,i) = jacobianest(@(x) eom(x,u(i),t(i),constants),x(:,i));
end
Is there a way to do this without looping through each time node? I know that the following code gives me a matrix A which is (n*m x n*m).
A = jacobianest(@(x) F(x,u,t,constants),x);
Can I extract what I'm looking for from this or is there a better way to use jacobianest?

Matt J on 20 Jun 2021
Edited: Matt J on 20 Jun 2021
I don't think there is anything sub-optimal about the way you're using jacobianest now. In fact, by keeping the loop external to jacobianest, you have the possibility of using a parfor loop, which might speed things up. I'm assuming you wouldn't consider going inside jacobianest.m and changing the for-loops there to parfor loops.

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by