Solve Blocks > Example: Adding Units to Solve Blocks
Example: Adding Units to Solve Blocks
You can add units to solve blocks. You must ensure that the units are compatible with one another throughout your calculations.
1. Define the length of a pendulum.
2. Insert a solve block, define a differential equation for the problem, and use the odesolve function to solve the equation. Angle Ɵ is the angle between the vertical and the pendulum.
Both the length l and the gravitational constant g have units:
However, the initial conditions and the terminal point do not have units. As a result, the error about unit compatibility appears.
3. Add compatible units to all solve block components.
4. Define a range of values over which to plot the solve block solution. You must use the step range operator when you define ranges with units.
5. Plot the solve block solution.
6. Construct a solve block, and then use the minimize function to find when Ɵ is at its minimum given a guess value of t=5 s.
The units of the guess value must be compatible with the definition of the function to minimize.
7. Construct a solve block, and then use the maximize function to find when Ɵ is at its maximum given a guess value of t=2 s and a constraint of t<4 s.
8. Use the SIUnitsOf function to strip the unit from the maxima and minima points. This is required in order to use the unitless vertical markers.
9. Show the maxima and minima points on the original plot. Use vertical markers to show where these two points intersect the time axis.