Is there any way to get a partial derivative of a state variable with respect to a parameter value of a model component?
For example, if I work with this model.
Is there a way to get the value of the partial derivative of theta_dot of the elbow with respect to the mass of the lower arm 'm' at a certain state?
Partial Derivative of a state variable with respect to a parameter value of a model component
- Nat Wannawas
- Posts: 2
- Joined: Fri Apr 12, 2019 1:41 pm
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Partial Derivative of a state variable with respect to a parameter value of a model component
OpenSim does not export symbolic expressions. However, you could approximate partial(variable)/partial(parameter) numerically by increasing/decreasing the parameter value, calculating the variable value with OpenSim in each case, and computing a central difference. It would be quite slow if you were to use this strategy at each time step of a simulation since changing a model parameter (like mass) requires you to call initSystem() which is computationally expensive. Instead, you could create two models, one with mass = m+delta and one with mass = m-delta. At each time step, set the states of these two models to be the same (presumably, you have already generated these states over time), compute theta_dot from each model, and then compute the central difference.
- Nat Wannawas
- Posts: 2
- Joined: Fri Apr 12, 2019 1:41 pm
Re: Partial Derivative of a state variable with respect to a parameter value of a model component
Very clear and helpful answer. Thank you so much.