Wire deflection under magnetic force; kinetic energy red, spring energy blue.
Simulation not started.
A straight conductor carrying current through a magnetic field experiences a force described by the Lorentz law. When the wire is free to move, this force can set it into motion. Our simulator transforms the algebraic expression into a dynamic mass–spring system so you can watch the deflection evolve. The current flows along the wire of length ; a uniform magnetic field of magnitude makes an angle with the wire. The resulting force direction follows the right-hand rule and is perpendicular to both the current and field. To illustrate motion within the plane of the screen, we choose the magnetic field to point into the page so that the force acts upward when current runs to the right.
Inputs are constrained to SI units: amperes for current, meters for length, tesla for field, kilograms for mass, newtons per meter for spring stiffness, and newton-seconds per meter for viscous damping. The wire is modeled as a rigid bar attached to a horizontal spring that allows only vertical motion. The angle is measured between the current direction and magnetic field; by keeping the field perpendicular to the screen, varying is equivalent to rotating the wire within the plane. A positive angle yields a force out of the page; to keep the visualization two-dimensional, we project that force onto the upward direction. Though simplified, this arrangement captures the essential dependence on .
The net vertical force on the mass attached to the wire combines magnetic, spring, and damping contributions:
Rearranging gives the familiar second-order ordinary differential equation for a damped driven harmonic oscillator:
The right-hand side is a constant drive term. Our numerical solution uses a fourth-order Runge–Kutta algorithm to update position and velocity . Kinetic energy is and spring potential energy is . We plot both energies and total mechanical energy to monitor dissipation.
RK4 advances the state vector (, ) with timestep . At each step the algorithm evaluates the acceleration function four times:
Input validation clamps between 0.001 s and 0.05 s to preserve stability. If invalid numbers appear (NaN or infinite), the script halts and reports an error via the live region.
Suppose a 0.2 m wire of mass 0.05 kg carries 10 A through a 0.5 T field at 90°. The magnetic force is N upward. With spring constant 5 N/m and damping 0.1 N·s/m, the wire accelerates until the spring force balances the magnetic drive at a static displacement of 0.2 m. Running the animation reveals a transient oscillation that decays as damping removes energy. The CSV file logs time, displacement, velocity, and energies, enabling verification: the static displacement matches .
Changing parameters highlights physical trends. The table compares the peak displacement and settling time for three cases with all else equal:
Case | Peak y (m) | Settling time (s) |
---|---|---|
Baseline (I=10 A) | 0.23 | 2.5 |
Higher current (I=15 A) | 0.35 | 3.0 |
Stiffer spring (k=10 N/m) | 0.12 | 1.8 |
The canvas shows a horizontal wire (gray rectangle) anchored to a spring on the left. Blue X symbols represent the magnetic field directed into the screen. When the simulation runs, a red dot marks the wire's center moving up or down. A green arrow indicates the magnetic force. The energy bar below the canvas depicts kinetic energy in red and spring potential in blue; gray indicates total mechanical energy. Keyboard focus on the canvas allows pressing the spacebar to toggle play/pause. Screen-reader users receive updates through the summary region describing time, displacement, velocity, and energies.
The model assumes the wire remains rigid and the magnetic field uniform. Real motors involve distributed coils and spatially varying fields requiring integration along the wire. Induced currents, heating, and nonlinear magnetic materials are ignored. We restrict motion to one dimension; in reality, the force vector may point out of the plane, necessitating 3‑D visualization. Despite simplifications, the simulator conveys the essential relationship between current, field, and mechanical response. Extensions could include rotating loops, AC driving currents, or coupling multiple wire segments.
Background on the Lorentz force and applications can be found in standard texts such as D. J. Griffiths, Introduction to Electrodynamics. For more dynamical systems, explore the mass–spring simulator, the RC circuit transient tool, or the double-slit wave animation.