yuna
yuna

Reputation: 51

Deriving the gradient of a potential in MATLAB using symbolic toolbox?

I want to compute the gradient of the electrostatic potential of combination of 4 charges located at (1,1,0), (1,-1,0), (-1,1,0) and (-1,-1,0). How can I use the symbolic toolbox in MATLAB to achieve this?

Upvotes: 0

Views: 1009

Answers (1)

abcd
abcd

Reputation: 42225

My electromagnetics is rusty, but your question has a simple analytical solution.

The electric potential is:

enter image description here

and this is what it looks like on the plane z=0

enter image description here

Now the gradient is

enter image description here

and noting that

enter image description here

you can easily apply the above to all the terms in the equation of the gradient to get a closed form solution that can be easily plotted.


In MATLAB:

Here's an example that shows you how to perform the above partial differentiation in MATLAB. You can then build upon this to derive the full solution. I'll leave that upto you.

syms x y z x0 y0 z0
diff(1/sqrt((x-x0)^2+(y-y0)^2+(z-z0)^2),x)

ans = 

-(x - x0)/((x - x0)^2 + (y - y0)^2 + (z - z0)^2)^(3/2)

Upvotes: 2

Related Questions