Hi Jose,
As of MATLAB R2024a, there is no direct functionality for treating a dependent variable or symbol as constant while performing an operation w.r.t. the associated dependent variables, like differentiation. However, a workaround for such a scenario could be initializing another symbol, which could then be treated as a constant in the expression, depending on the use case:
% Define symbolic variables
syms x y z z_d
% Define relations between variables
z = x + y;
% Define an example expression taking constant or independent variable z_d
expr = z_d*x*y;
% Differentiate express w.r.t. required symbol
const_expr = diff(expr, x)
While declaring an expression, z_d and z can be used depending on whether z has to be treated as a constant or variable respectively and later subs function could be used to interchange the symbols for the other case.
% Substitute dependent variable z instead of independent symbol z_d
var_expr = subs(const_expr, z_d, z)
% Perform some operation
...
% Simplify resulting expression to required number of steps
simple_expr = simplify(var_expr, 'Steps', 2)
This will allow you to interchangeably use constant or variable z in an expression and perform subsequent operations.
For further information regarding defining symbols and expressions or differentiation, you can refer to the Symbolic Math Toolbox documentations:
Hope this helps!