Subs function doesn't fully replace the values

3 visualizaciones (últimos 30 días)
I'm testing the subs function and I was wondering why when I use a sin or cos, I don't get the numeric value and instead get this longer version. Also, will it keep getting bigger and bigger if I keep working with that matrix? Here's the code I'm using:
syms X Y Z W
q = [X, Y, Z, W];
q_1 = [1, 2, 3, 4];
phi = [(2*X-W)^2 X^2-2*Y Y*sin(Z)];
J = jacobian(phi,q);
disp(J);
J_1 = J;
J_1 = subs(J, q, q_1);
disp(J_1);
And here it is what is shown in the displays:
[8*X - 4*W, 0, 0, 2*W - 4*X]
[ 2*X, -2, 0, 0]
[ 0, sin(Z), Y*cos(Z), 0]
[-8, 0, 0, 4]
[ 2, -2, 0, 0]
[ 0, sin(3), 2*cos(3), 0]

Respuesta aceptada

VBBV
VBBV el 16 de Abr. de 2024
syms X Y Z W
q = [X, Y, Z, W];
q_1 = [1, 2, 3, 4];
phi = [(2*X-W)^2 X^2-2*Y Y*sin(Z)];
J = jacobian(phi,q);
disp(J);
J_1 = J;
J_1 = subs(J, q, q_1);
disp(double(J_1));
-8.0000 0 0 4.0000 2.0000 -2.0000 0 0 0 0.1411 -1.9800 0
  2 comentarios
VBBV
VBBV el 16 de Abr. de 2024
Editada: VBBV el 16 de Abr. de 2024
Use double for numeric (float) values
Roberto Toledo Fdez-Cañaveral
Roberto Toledo Fdez-Cañaveral el 17 de Abr. de 2024
Thank you for the quick answer! I appreciate it!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by