The electrical potential energy of an object can be calculated in MATLAB using the following formula:
U = (k*q1*q2) / r
where U is the electrical potential energy in Joules, k is Coulomb's constant (910^9 Nm^2/C^2), q1 and q2 are the charges of the interacting objects in Coulombs and r is the distance between the objects in meters.
Here's the MATLAB code to calculate the electrical potential energy of an object:
main.m316 chars14 lines
In this example, the electrical potential energy is calculated for two objects with charges of 1 microCoulomb and 2 microCoulombs separated by a distance of 1 centimeter.
gistlibby LogSnag