Page 1 of 1

Partial Derivative of a state variable with respect to a parameter value of a model component

Posted: Wed Feb 24, 2021 1:23 pm
by wnat
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?
Image

Re: Partial Derivative of a state variable with respect to a parameter value of a model component

Posted: Wed Feb 24, 2021 5:32 pm
by tkuchida
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.

Re: Partial Derivative of a state variable with respect to a parameter value of a model component

Posted: Thu Feb 25, 2021 4:22 am
by wnat
Very clear and helpful answer. Thank you so much.