potential() compute scalar potential from gradient vector field; Error using sym/potential Second argument must be a vector of variables.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Philipp Bisignano
le 31 Mai 2022
Commenté : Philipp Bisignano
le 31 Mai 2022
I have a matrix dRho which is a (density) gradient vector field. I want to compute the scalar potential (the density) Rho by means of the matlab-function potential(V,X,Y).
X and Y are my cartesian coordinate vectors:
[m, n] = size(dRho); [1, n] = size(X); [m, 1] = size(Y);
As the function potential() deals with symbolic variables, I convert my quantities to symbolic matrix/vectors with the sym() function, 'f' for floating point precision. (According to numeric to symbolic conversion https://ch.mathworks.com/help/symbolic/numeric-to-symbolic-conversion-1.html#buyp69j-1)
dRho_sym = sym(dRho, 'f');
X_sym = sym(X, 'f');
Y_sym = sym(Y, 'f');
Then I'm trying to compute the potential for each row of my matrix wrt to X_sym, using the respective y value (Y_sym(j)) as base point for the integration, as suggested in the description:
"potential(V,X,Y) computes the potential of vector field V with respect to X using Y as base point for the integration".
for j = 1:m
Rho = potential( dRho_sym(j,:), X_sym, Y_sym(j));
end
I'm getting this error:
Error using sym/potential
Second argument must be a vector of variables.
Are the symbolic numbers not understood as symbolic variables?
Or do I mess up something with the dimensions?
This is a more detailed description in the potential() function:
% P = POTENTIAL(V,X,Y) computes the potential of vector field V with
% respect to X using Y as base point for the integration. If Y is not a
% scalar, then Y must be of the same dimension as V and X. If Y is
% scalar, then Y is expanded into a vector of the same size as X with
% all components equal to Y.
%
% Examples:
% syms x y z; potential([x y z*exp(z)], [x y z])
% returns x^2/2 + y^2/2 + exp(z)*(z - 1).
%
% syms x0 y0 z0; potential([x y z*exp(z)], [x y z], [x0 y0 z0])
% returns x^2/2 - x0^2/2 + y^2/2 - y0^2/2 + exp(z)*(z - 1) -
% exp(z0)*(z0 - 1)
%
% potential([x y z*exp(z)], [x y z], [1,1,1])
% returns x^2/2 + y^2/2 + exp(z)*(z - 1) - 1
%
% potential([x y z*exp(z)], [x y z], 1)
% returns x^2/2 + y^2/2 + exp(z)*(z - 1) - 1
%
% potential([y -x], [x y])
% returns NaN since the potential does not exist.
I will be very gratefull for any help! Also suggestions about how to compute the scalar potential of a gradient vector field by other means are welcome.
0 commentaires
Réponse acceptée
Walter Roberson
le 31 Mai 2022
No, the second parameter must be a vector of symbolic names.
When you do not have a starting point, each term in V is integrated with respect to the corresponding variable in the second parameter, and all of the integrals are added.
But you cannot integrate anything with respect to a number, so what you are trying to do cannot work.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra 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!