MATLAB Examples

# Compute Operating Point from State Specifications at Command Line

This example shows how to compute a steady-state operating point by specifying known state values and constraints.

```mdl = 'scdspeed'; open_system(mdl) ```

Create a default operating point specification for the model.

```opspec = operspec(mdl) ```
``` Operating point specification for the Model scdspeed. (Time-Varying Components Evaluated at time t=0) States: ---------- (1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar spec: dx = 0, initial guess: 0.543 (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s spec: dx = 0, initial guess: 209 Inputs: ---------- (1.) scdspeed/Throttle perturbation initial guess: 0 Outputs: None ---------- ```

By default, both states are specified to be at equilibrium, as shown by the dx = 0 specification. Both states are also specified as unknown values; that is, their steady-state values are calculated during trimming, with an initial guess defined in the specification.

Change the second state, the engine angular velocity, to be a known value, and view the updated state specifications.

```opspec.States(2).Known = 1; opspec.States ```
```(1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar spec: dx = 0, initial guess: 0.543 (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s spec: dx = 0, x: 209 ```

The value defined in the second state specification is now the known state value and not an initial guess.

Find an operating point that meets these specifications.

```op1 = findop(mdl,opspec); ```
``` Operating point search report: --------------------------------- Operating point search report for the Model scdspeed. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- (1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar x: 0.544 dx: 2.03e-13 (0) (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s x: 209 dx: -4.57e-13 (0) Inputs: ---------- (1.) scdspeed/Throttle perturbation u: 0.00501 [-Inf Inf] Outputs: None ---------- ```

The operating point search report shows that the specifications were met successfully, and that both states are at steady state as expected (dx = 0).

You can also specify bounds for model states during trimming. For example, modify the operating point specifications to trim the second state to a known value of 180, while constraining the first state to be between 0.5 and 0.7.

```opspec.States(2).x = 180; opspec.States(1).Min = 0.5; opspec.States(1).Max = 0.7; ```

Find the operating point that meets these specifications.

```op2 = findop(mdl,opspec); ```
``` Operating point search report: --------------------------------- Operating point search report for the Model scdspeed. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- (1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar x: 0.57 dx: 2.47e-10 (0) (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s x: 180 dx: 2.03e-13 (0) Inputs: ---------- (1.) scdspeed/Throttle perturbation u: -0.881 [-Inf Inf] Outputs: None ---------- ```

The operating point search report shows that the specifications were met successfully, and that the first state is within the specified bounds.

Finally, you can also constrain the derivatives of states that are not at steady state. Using such constraints, you can trim derivatives to known nonzero values or specify derivative tolerances for states that cannot reach steady state.

For example, suppose that you want to find the operating condition at which the engine angular velocity is 180 rad/s and the angular acceleration is 50 rad/s^2. To do so, disable the SteadyState specification for that state, and set both state derivative bounds to the same target value.

```opspec.States(2).SteadyState = 0; opspec.States(2).dxMin = 50; opspec.States(2).dxMax = 50; ```

The updated state specifications show the new state derivative constraints.

```opspec.States ```
```(1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar spec: dx = 0, initial guess: 0.543 (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s spec: 50 <= dx <= 50, x: 180 ```

Find an operating point that meets these updated specifications.

```op3 = findop(mdl,opspec); ```
``` Operating point search report: --------------------------------- Operating point search report for the Model scdspeed. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------- (1.) scdspeed/Throttle & Manifold/Intake Manifold/p0 = 0.543 bar x: 0.666 dx: 2.01e-08 (0) (2.) scdspeed/Vehicle Dynamics/w = T//J w0 = 209 rad//s x: 180 dx: 50 [50, 50] Inputs: ---------- (1.) scdspeed/Throttle perturbation u: 0.163 [-Inf Inf] Outputs: None ---------- ```