Symbolic Functions of Symbolic Vectors
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a function
where x and y are both vectors of an arbitrary length. The function d is a small part which appears many times in a larger function and I'd like to be able to have the derivatives of d show up as
as opposed to the behavior that occurs if I fully define
. However, if I try to do this with something like:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282926/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282931/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282971/image.png)
syms d(x,y) real
syms x y real [1 4]
I'll end up with vectors:
x = [x1, x2, x3, x4]
y = [y1, y2, y3, y4]
Which means that if I take the Jacobian of this function I get:
jacobian(d,x) = [0,0,0,0]
As opposed to something like:
jacobian(d,x) = [diff(d,x1), diff(d,x2), ....]
Which is my desired behavior.
Additionally, if I use syntax like:
syms x [1 4]
syms d(x) [1 4] matrix keepargs
jacobian(d,x)
I get the error:
Incorrect number or types of inputs or outputs for function 'jacobian'.
And if I use the syntax:
syms x [1 4] matrix
syms d(x) [1 4] matrix keepargs
diff(d,x)
I get the output:
diff(d(x), x)
Calling Jacobian gives the same error as before and attempting to differentiate w/r.t. any of the variables within symmatrix x throws an error saying it isn't a recognized variable.
Does anyone know how to get that behavior? In this case would I need to explicitly define something like
?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282961/image.png)
I'm working on r2023a right now if that helps.
0 commentaires
Réponse acceptée
Raghvi
le 14 Fév 2023
I understand that you are trying to figure out the partial derivatives of your function using the “Jacobian” function, and your desired output is jacobian(d,x) = [diff(d,x1), diff(d,x2), ....]
The following piece of code worked for me:
>> syms x y [1 4] real
>> d(x,y)= sqrt((x-x0).^2 + (y-y0).^2);
>> jacobian(d,x)
For more information on Jacobian, you can refer to the documentation:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Assumptions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!