Reputation: 840
I am using virtual potential fields to control the movement of a group of robots in a 2D environment, their position is given by a matrix of x and y coordinates. The virtual potential fields depend on a number of variables, one of them is the inter-robot distance. A short (heavily simplified) example of my code is given below.
x = sym('x',[4 2]); % four robots with x and y coordinates
xd = sym('xd',[1 2]); % a single destination
F = sym(ones(4,1)); % one potential function for each robot
for i=1:size(x,1)
for j=1:size(x,1)
if i~=j
F(i) = F(i)/norm(x(i,:)-x(j,:))^2; % infinite potential when any two robots collide
end
end
F(i) = F(i) * norm(x(i,:)-xd)^2; % add an attraction force to the goal
end
So now that I have created symbolic expressions for the potential fields, I need to find their derivative so I can apply steepest descent. Now I'm wondering: does it make any difference whether I use the function gradient
or diff
to obtain the derivative with respect to the position? To clarify: for robot i
I want to take the derivative with respect to xi_1
and xi_2
.
Upvotes: 0
Views: 418
Reputation: 18484
Your question, as stated, is bordering on mathematics rather than programming. The gradient is just the generalization of the derivative to multiple dimensions. Yes, for movement in a 2-D plane, it would make sense to use sym/gradient
. As the documentation states, if you specify just a scalar for the second argument, sym/gradient
becomes equivalent to sym/diff
. To properly calculate your 2-D gradient, the second argument must be a two-element vector, e.g., [xi_1 xi_2]
.
Upvotes: 1