# Permanent Magnet Attached to Iron Wall

This example shows how to model the forces acting on a magnet that is attached to an iron wall. You can define the interaction between the magnetic and translational motion domains using a Permanent Magnet block and a Reluctance Force Actuator block.

### Model Overview

A Reluctance Force Actuator block models the interaction between a permanent magnet and an iron wall by generating reluctance and translational force according to the size of the gap between magnet's poles and the wall. The Force Input subsystem applies force on the magnet.

```myModel = "PermanentMagnetOnWall"; open_system(myModel); ```

### Simulate Model and Plot Results

When you start the simulation, the magnet touches the wall. The Force Input block gradually increases the force on the magnet so the magnet detaches from the wall. After, the force on the magnet exceeds the critical force, the Force Input Block stops raising the applied force to prevent the magnet from moving too far from the wall. At the simulation time of 3 seconds, the Force Input block stops applying the external force causing the magnet to reattach to the wall.

```sim(myModel); time = PermanentMagnetOnWallSimlog.Reluctance_Force_Actuator.x.series.time; position = PermanentMagnetOnWallSimlog.Reluctance_Force_Actuator.x.series.values; velocity = PermanentMagnetOnWallSimlog.Mass.v.series.values; totalForce = PermanentMagnetOnWallSimlog.Mass.f.series.values; appliedForce = -PermanentMagnetOnWallSimlog.Load_Force.f.series.values; ```

Animate the movement of the magnet and plot velocity, total and applied force

```frames = PermanentMagnetOnWallAnimate(time, position, velocity, totalForce, appliedForce); hFig1 = figure(Name="PermanentMagnetOnWallFigure"); movie(hFig1, frames, 1, 20); ```

### Change Magnet Parametrization

Some manufacturers define the magnetization curve using the remanent flux density and coercivity of the magnet.

```% Change the parametrization type: set_param(myModel+"/Permanent Magnet", "remanent_field_parameters", "2"); ```

The default parameters are bR = 0.1 T and muR = 1.05. The equivalent coercivity is approximately:

```coercivityEquivalent = 7.5788e4; set_param(myModel+"/Permanent Magnet", "hC", "coercivityEquivalent"); ```
```sim(myModel); time = PermanentMagnetOnWallSimlog.Reluctance_Force_Actuator.x.series.time; position = PermanentMagnetOnWallSimlog.Reluctance_Force_Actuator.x.series.values; velocity = PermanentMagnetOnWallSimlog.Mass.v.series.values; totalForce = PermanentMagnetOnWallSimlog.Mass.f.series.values; appliedForce = -PermanentMagnetOnWallSimlog.Load_Force.f.series.values; ```

Animate the movement of the reparameterized magnet and plot velocity, total and applied force. The magnet now moves too far from the wall and can not reattach because of the small error introduced in the approximation of the coercivity.

```frames = PermanentMagnetOnWallAnimate(time, position, velocity, totalForce, appliedForce); hFig2 = figure(Name="PermanentMagnetOnWallFigure"); movie(hFig2, frames, 1, 20); ```