How do you obtain the jacobian of a symbolic function w.r.t. another symbolic function?

28 visualizaciones (últimos 30 días)
How do you obtain the jacobian of a symbolic function with respect to another symbolic function?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 2 de Sept. de 2021
Editada: MathWorks Support Team el 8 de Oct. de 2021
It is not possible to calculate the jacobian of a symbolic function w.r.t. another symbolic function directly. According to the "jacobian" documentation page here:
the second parameter of the Jacobian command is expected to be either a scalar or a vector of symbolic variables. Therefore it is not possible to directly take the Jacobian of a symbolic function w.r.t. another symbolic function. For example:
>> syms t a(t) x(t)>> jacobian(a(t)*x(t), x)
Error using sym/jacobian (line 44)
Second argument must be a vector of variables.
As you can see, "x" is a symbolic function rather than a symbolic variable and results in an error during jacobian calculation mentioned above. 
As a workaround,  you will have to:
1. Perform a substitution of all symbolic functions by symbolic variables,
2. Calculate the Jacobian w.r.t to the symbolic variables
3. Perform a substitution of the Jacobian with all symbolic variables being replaced by the symbolic functions
As a more comprehensive example, consider the jacobian of:
a(t) * x(t)^2 , w.r.t x(t)
You can calculate the jacobian w.r.t x(t) using the following commands
>> syms t a(t) x(t) x_var
>> substituted = subs(a(t)*x(t)^2, x, x_var);
>> jac = jacobian(substituted, [x_var]);
>> subs(jac, x_var, x)
ans = 2*a(t)*x(t)
More information on 'subs' can be found here:
Note that in the general case, this kind of substitution into variables and manipulating the variables and substituting back, is not valid. It is only valid if the functions involved are independent of each other, but in the general case you cannot know that to be true.
  1 comentario
Walter Roberson
Walter Roberson el 27 de Mayo de 2020
Note that in the general case, this kind of substituation into variables and manipulating the variables and substituting back, is not valid. It is only valid if the functions involved are independent of each other, but in the general case you cannot know that to be true.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by