# Electric dipole moment, field and torque in JavaScript

An electric dipole is +q and −q separated by 2a. Its dipole moment is p = q × 2a. Here are the formulas as code. (I build [PractiSci](https://www.practisci.in), where the dipole in a field is a free virtual lab.)

## Dipole moment

```js
const p = (q, twoA) => q * twoA;
const pm = p(2e-6, 0.04);
console.log(pm); // 8e-8 C m
```

## Field on the axis and the equatorial line (r much larger than a)

```js
const k = 9e9;
const axial = (p, r) => (2 * k * p) / r ** 3;
const equatorial = (p, r) => (k * p) / r ** 3;
console.log(axial(8e-8, 0.5), equatorial(8e-8, 0.5)); // 11520, 5760 N/C
```

The axial field is twice the equatorial one, and the equatorial field points opposite to p.

## Torque and potential energy

```js
const torque = (p, E, deg) => p * E * Math.sin((deg * Math.PI) / 180);
const U = (p, E, deg) => -p * E * Math.cos((deg * Math.PI) / 180);
console.log(torque(8e-8, 2e5, 30)); // 0.008 N m
```

## FAQ

### Is there a net force in a uniform field?
No. Net force is zero; only a torque acts.

### How does the dipole field fall?
As 1/r³, faster than a single charge's 1/r².

### Where can I try it?
The free [dipole in a field lab](https://www.practisci.in/labs/12-1-dipole-in-field) lets you change charge, separation and angle. More are in the [Class 12 physics practicals](https://www.practisci.in/practicals/class-12-physics).

