Borrar filtros
Borrar filtros

How to find gradient of a vector field in matlab symbolic

10 visualizaciones (últimos 30 días)
Chandan
Chandan el 12 de Dic. de 2023
Respondida: Chandan el 13 de Dic. de 2023
I am trying to find gradient of a vector field in matlab symbolic , whose output will be matrix but it am getting error
  2 comentarios
KSSV
KSSV el 12 de Dic. de 2023
Copy your code here. Don't attach it as an screen shot/ image.
Chandan
Chandan el 12 de Dic. de 2023
clc ; clear all
syms x y z
syms u(x,y,z) v(x,y,z) w(x,y,z)
V = [u v w];
S = [x y z];
gradient(u,S)
ans(x, y, z) = 
gradient(V,S) % How to take gradient of vector field
Error using sym/gradient
Invalid argument at position 1. Argument must be scalar or a symbolic function with scalar formula.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Dic. de 2023
Movida: Walter Roberson el 12 de Dic. de 2023
The fundamental problem you are having is that gradient does not accept a vector the first parameter.
syms x y z
syms u(x,y,z) v(x,y,z) w(x,y,z)
V = [u(x,y,z) v(x,y,z) w(x,y,z)];
S = [x y z];
temp = arrayfun(@(EXPR) gradient(EXPR,S), V, 'uniform', 0);
result(x,y,z) = [temp{:}]
result(x, y, z) = 

Más respuestas (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 12 de Dic. de 2023
If you assign an expression for V, you will get this:
clc ; clearvars
syms x y z
syms u(x,y,z) v(x,y,z) w(x,y,z)
V(x,y,z) = 2*u+3*v-w % Some e.g. expression
V(x, y, z) = 
S = [x y z];
du = gradient(u,S)
du(x, y, z) = 
dV = gradient(V,S)
dV(x, y, z) = 
% OR simply
dV= gradient(V,[x,y,z])
dV(x, y, z) = 
  1 comentario
Dyuman Joshi
Dyuman Joshi el 12 de Dic. de 2023
V is not a combination of u, v and w, but an array with u, v and w as elements.

Iniciar sesión para comentar.


Chandan
Chandan el 13 de Dic. de 2023
% thanks for answer. It worked with the Jacobian too.
clc; clearvars;
syms x y z
syms u(x, y, z) v(x, y,z) w(x,y,z)
V = [u v w];
S = [x y z];
jacobian(V,S)
ans(x, y, z) = 

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by