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.
Click to copy this expression
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.
Click to copy this expression
Both the length l and the gravitational constant g have units:
Click to copy this expression
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.
Click to copy this expression
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.
Click to copy this expression
5. Plot the solve block solution.
Click to copy this expression
6. Construct a solve block to find when Ɵ is at its minimum given a guess value of t=5 s.
Click to copy this expression
The units of the guess value must be compatible with the definition of the function to minimize.
7. Construct a solve block to find when Ɵ is at its maximum given a guess value of t=2 s and a constraint of t<4 s.
Click to copy this expression
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.
Click to copy this expression
Click to copy this expression
9. Show the maxima and minima points on the original plot. Use vertical markers to show where these two points intersect the time axis.
Click to copy this expression