Borrar filtros
Borrar filtros

Symbolic Functions of Symbolic Vectors

1 visualización (últimos 30 días)
Alex B
Alex B el 3 de Feb. de 2023
Respondida: Raghvi el 14 de Feb. de 2023
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:
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 ?
I'm working on r2023a right now if that helps.

Respuesta aceptada

Raghvi
Raghvi el 14 de Feb. de 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:

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by