フィルターのクリア

potential() compute scalar potential from gradient vector field; Error using sym/potential Second argument must be a vector of variables.

2 ビュー (過去 30 日間)
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.

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 31 日
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.
  1 件のコメント
Philipp Bisignano
Philipp Bisignano 2022 年 5 月 31 日
x = sym('x', [1 n]);
y = sym('y', [1 m]);
for j = 1:m
Rho_sym(j) = potential(dRho_sym(j,:), x, y(j) );
end
Like this it is compiling. But I'm getting one single value per iteration,
which is function of single entries x1, x2, ..., y1, y2, .. of x and y.
And it takes plenty of computation time.
Could I match the vector x = [x1, x2, ...] and y to my vectors X and Y?
Somehow x1 = X(1), ... ? Would that make any sense to you?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by