2
$\begingroup$

I am trying to solve and plot a vector which is equal to (xi,yi)+gradientf(xi,yi). I solve for the gradient by finding the derivative. I am struggling with how to write/get the function to take in my list of "pnts1" one at a time into the equation listed above. I guess my main problem is getting mathematica to pick up each point as an xi,yi value.

f[x_, y_] = x + x/(x^2 + y^2);
h = D[x + x/(x^2 + y^2), x];
w = D[x + x/(x^2 + y^2), y]
gradientf = (1 - (2 x^2)/(x^2 + y^2)^2 + 1/(x^2 + y^2), -((
2 x y)/(x^2 + y^2)^2));
pnts1 = {{-1.8, 0.2}, {-1.8, 0.4}, {-1.8, 0.6}, {-1.8, 0.8}, {-1.8, 
1.}, {-1.8, 1.2}, {-1.8, 1.4}, {-1.8, 1.6}, {-1.8, 1.8}, {-1.8, 
2.}, {-1.6, 0.2}, {-1.6, 0.4}, {-1.6, 0.6}, {-1.6, 0.8}, {-1.6, 
1.}, {-1.6, 1.2}, {-1.6, 1.4}, {-1.6, 1.6}, {-1.6, 1.8}, {-1.6, 
2.}, {-1.4, 0.2}, {-1.4, 0.4}, {-1.4, 0.6}, {-1.4, 0.8}, {-1.4, 
1.}, {-1.4, 1.2}, {-1.4, 1.4}, {-1.4, 1.6}, {-1.4, 1.8}, {-1.4, 
2.}, {-1.2, 0.2}, {-1.2, 0.4}, {-1.2, 0.6}, {-1.2, 0.8}, {-1.2, 
1.}, {-1.2, 1.2}, {-1.2, 1.4}, {-1.2, 1.6}, {-1.2, 1.8}, {-1.2, 
2.}, {-1., 0.2}, {-1., 0.4}, {-1., 0.6}, {-1., 0.8}, {-1., 
1.}, {-1., 1.2}, {-1., 1.4}, {-1., 1.6}, {-1., 1.8}, {-1., 
2.}, {-0.8, 0.6}, {-0.8, 0.8}, {-0.8, 1.}, {-0.8, 1.2}, {-0.8, 
1.4}, {-0.8, 1.6}, {-0.8, 1.8}, {-0.8, 2.}, {-0.6, 0.8}, {-0.6, 
1.}, {-0.6, 1.2}, {-0.6, 1.4}, {-0.6, 1.6}, {-0.6, 1.8}, {-0.6, 
2.}, {-0.4, 1.}, {-0.4, 1.2}, {-0.4, 1.4}, {-0.4, 1.6}, {-0.4, 
1.8}, {-0.4, 2.}, {-0.2, 1.}, {-0.2, 1.2}, {-0.2, 1.4}, {-0.2, 
1.6}, {-0.2, 1.8}, {-0.2, 2.}, {0., 1.}, {0., 1.2}, {0., 1.4}, {0.,
1.6}, {0., 1.8}, {0., 2.}, {0.2, 1.}, {0.2, 1.2}, {0.2, 
1.4}, {0.2, 1.6}, {0.2, 1.8}, {0.2, 2.}, {0.4, 1.}, {0.4, 
1.2}, {0.4, 1.4}, {0.4, 1.6}, {0.4, 1.8}, {0.4, 2.}, {0.6, 
0.8}, {0.6, 1.}, {0.6, 1.2}, {0.6, 1.4}, {0.6, 1.6}, {0.6, 
1.8}, {0.6, 2.}, {0.8, 0.6}, {0.8, 0.8}, {0.8, 1.}, {0.8, 
1.2}, {0.8, 1.4}, {0.8, 1.6}, {0.8, 1.8}, {0.8, 2.}, {1., 
0.2}, {1., 0.4}, {1., 0.6}, {1., 0.8}, {1., 1.}, {1., 1.2}, {1., 
1.4}, {1., 1.6}, {1., 1.8}, {1., 2.}, {1.2, 0.2}, {1.2, 0.4}, {1.2,
0.6}, {1.2, 0.8}, {1.2, 1.}, {1.2, 1.2}, {1.2, 1.4}, {1.2, 
1.6}, {1.2, 1.8}, {1.2, 2.}, {1.4, 0.2}, {1.4, 0.4}, {1.4, 
0.6}, {1.4, 0.8}, {1.4, 1.}, {1.4, 1.2}, {1.4, 1.4}, {1.4, 
1.6}, {1.4, 1.8}, {1.4, 2.}, {1.6, 0.2}, {1.6, 0.4}, {1.6, 
0.6}, {1.6, 0.8}, {1.6, 1.}, {1.6, 1.2}, {1.6, 1.4}, {1.6, 
1.6}, {1.6, 1.8}, {1.6, 2.}, {1.8, 0.2}, {1.8, 0.4}, {1.8, 
0.6}, {1.8, 0.8}, {1.8, 1.}, {1.8, 1.2}, {1.8, 1.4}, {1.8, 
1.6}, {1.8, 1.8}, {1.8, 2.}, {2., 0.2}, {2., 0.4}, {2., 0.6}, {2., 
0.8}, {2., 1.}, {2., 1.2}, {2., 1.4}, {2., 1.6}, {2., 1.8}, {2., 
2.}}
vector = (x, y) + gradientf;
$\endgroup$
5
$\begingroup$
f[x_, y_] = x + x/(x^2 + y^2);
gradientf[x_, y_] = D[f[x, y], {{x, y}}]

{1 - (2 x^2)/(x^2 + y^2)^2 + 1/(x^2 + y^2), -((2 x y)/(x^2 + y^2)^2)}

Applying this to your points:

vector = pnts1 + gradientf @@@ pnts1
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.