None Reading_17

Challenge

In this reading, your challenge is to understand how and when to model systems that have more than one independent energy storage process or element.

What does this mean? Consider the following electrical circuit:

image-3.png

Let's imagine that you were interested in the voltage $V_{3g}$ as our dependent variable. Scoping the system and applying conservation of energy to each element, each loop, and node 2 results in the following "menu" of equations for the system:

node

$i_1 = i_2+i_3$ (1)

loop

$V_{1g} = V_{12}+V_{2g}$ (2)

$V_{2g} = V_{23}+V_{3g}$ (3)

$V_{1g} = V_{12}+V_{23}+V_{3g}$ (4)

element

$i_2 = C_1\dot{V}_{2g}$ (5)

$i_3 = C_2\dot{V}_{3g}$ (6)

$V_{12} = i_1R_1$ (7)

$V_{23} = i_3R_2$ (8)

Now, using the tools you have built throughout this course, you know that both $C_1$ and $C_2$ store energy. In fact, you specifically know that $E_{C1}=\frac{1}{2}C_1 V_{2g}^2$ and $E_{C2}=\frac{1}{2}C_2 V_{3g}^2$. You might expect, as was the case in Reading 9, that you could end up somehow writing the energy stored in $C_1$ using voltage $V_3$ so that you could get an equation for your model that looks like:

$$\dot{V}_{3g} = \square V_{3g} + \square V_{s}$$

Or maybe as in Reading 15, where one wheel of the truck was considered the "input" and thus its stored energy was irrelevant, perhaps the voltage in $C_1$ is fully dictated by the voltage source $V_s$. Unfortunately, neither of these helpful simplifications is possible.

Following the idea that we want to eliminate all variables except for our dependent variable ${V}_3$, its derivative(s), and our independent variables (including the source voltage $V_s$), we begin to make substitutions, letting the process show us what we need to do to construct our model.

First, let's begin with the node equation (1), substituting in the two capacitor equations (5),(6) for the currents $i_1$ and $i_3$, along with the resistor equation (7) to replace $i_1$ with voltages and resistances. That leads to the following:

$$\frac{1}{R_1}(V_s-V_{2g}) = C_1 \dot{V}_{2g} + C_2 \dot{V}_{3g}$$

This now has our output derivative $\dot{V}_{3g}$ and our input $V_s$ in it... however, we still need to eliminate the variable $V_{2g}$ and its derivative from the equation. To do this, we have access to the loop equation (4), which reads $V_{2g} = V_{23} + V_{3g}$. We could attempt to use this, along with equation (8) for resistor 2, to get an equation for $V_{2g}$, allowing us to substitute in and eliminate $V_{2}$ from our model. That looks like this:

$$V_{2g} = i_3R_2 + V_{3g}$$

We can then replace $i_3$ using equation (6) for $C_2$:

$$V_{2g} = R_2C_2\dot{V}_{3g} + V_{3g}$$

Great... that leads to the following updated model:

$$\frac{1}{R_1}(V_s-R_2C_2\dot{V}_{3g} + V_{3g}) = C_1 \dot{V}_{2g} + C_2 \dot{V}_{3g}$$

But the problem is that $\dot{V}_{2g}$ is still in our model!! To get rid of this, and replace it with only $V_{3g}$ and/or $V_s$ terms, we have to take the derivative of our equation for $V_{2g}$. This leads to the following expression for $\dot{V}_{2g}$:

$$\dot{V}_{2g} = R_2C_2\ddot{V}_{3g} + \dot{V}_{3g}$$

Making this substitution into our original model, we find that we have the second derivative of our output in the model! Our model ends up looking like the following:

$$\frac{1}{R_1}(V_s-R_2C_2\dot{V}_{3g} + V_{3g}) = C_1 ( R_2C_2\ddot{V}_{3g} + \dot{V}_{3g}) + C_2 \dot{V}_{3g}$$

This could be rearranged and rewritten so as to solve for the second derivative of our output:

$$\ddot{V}_{3g} = \frac{1}{R_1C_1R_2C_2}(V_s - (R_1C_1+R_2C_2)\dot{V}_{3g} -V_{3g})$$

This does satisfy our original requirements... sort of. It only contains dependent and independent variables, so in theory it is a suitable model, but the fact that it contains a second derivative as well as a first derivative and the output itself is different than what we've dealt with in the past.

Challenge Questions:

We've never seen this before, so this strange-looking model presents new questions:

  1. How can we recognize systems that will need a second (or third, fourth, fifth) derivative in order to complete a model?
  2. What is/are the proper form(s) for a higher-order (2 derivatives or more) differential equation model and how can we assess its internal validity?
  3. How can we simulate systems represented by higher-order differential equations?

In the following sections, we will address these questions. We saw that in this example, we needed two derivatives. This is because each of our capacitors stored energy independently, meaning that we had to mathematically account for energy changing in each one (even though we ended up eliminating $V_{2g}$ from our final model, since it was not our chosen dependent variable). We could not eliminate the effects of $C_2$ storing energy or combine those effects with the energy storage in $C_1$.

To recognize systems that need more than one derivative, we first need to understand what it means to have more than one independent energy storing element in our system scope.

Independent Energy Storage Elements and System Order

In a lumped-element model of an engineering system (such as those we have been building, where each element in the system scope either stores or dissipates energy), the number of significant, independent energy storage elements is equal to the number of derivatives required to model the system. The number of derivatives needed to represent a system's behavior is often called the system's "order."

For example, a single differential equation representing a model of a system that has 3 significant, independent energy storing elements would need to have a triple derivative of the dependent variable, a double derivative of the dependent variable, and a single derivative of the dependent variable in the equation in order to fully describe the system behavior. This is because each derivative is a representation of how the energy in the total system (consisting of 3 energy storage elements) can change. A single differential equation representing a system's dynamic behavior is often called an input-output model, because the single differential equation represents a relationship between the system's input (source of power from outside of the system scope) and its output (our dependent variable).

Representing your model as a single differential equation is not the only option. If your model is represented not as a single input-output differential equation but as a list of coupled first-order differential equations in State Space Form, the number of coupled, first-order differential equations you need to represent the model is equal to the number of independent energy storing elements in your scope.

Dependence and Independence of Energy Storage Elements

Two energy storing elements in a system model are independent of one another if the energy stored in one element cannot be directly written simply as a scaled version of the energy in another.

Two or more elements are dependent when Their energy storage equations can be directly related by a constant scale factor.

This often occurs if the two elements are directly in series (where the T-type variable is common between them but the A-type drop across each is different) or directly in parallel (where the A-type drop between them is common but the T-type variable in each is different) in an equivalent circuit representation, and in some cases when two energy storing elements are connected by a transducer with no dissipative elements in between them.

Consider the following two systems, (a) and (b):

image-2.png

System (a)

In system (a), it is possible to write the energy stored in the mass as $E_m = \frac{1}{2} mv^2$, and the energy stored in the rotational inertia $J$ as $E_J = \frac{1}{2} J \Omega^2$. Because the two elements seem to store energy using different across-type variables $v$ and $\Omega$, it may be tempting to say that the two are independent. However, Because the mass and inertia are connected by a pulley, which we might assume has no slip at the contact point, we could write that $v = \Omega r$, which means that we could write that $E_m = \frac{r^2}{2} m \Omega^2$. This would allow us to write the energy in $m$ as a function of the energy in $J$ using a common power variable, and then write one energy equation in terms of the other. In this case, we can do this by solving each energy storage equation for $\Omega^2$, obtaining:

$$\Omega^2 = \frac{2}{J}E_J = \frac{2}{mr^2}E_m$$

This means we could write the energy in the mass as a function of the energy in the inertia and parameters only, or vice versa. Each is simply a scaled version of the other. See that we could rewrite the above as:

$$E_J = \frac{J}{mr^2} E_m$$

Note that $\frac{J}{mr^2}$ is a simple, unitless, constant scale factor relating the energy in the mass to the energy in the rotating inertia.

Thus, the mass and the inertia are not independent.

In an equivalent circuit representation of system (a), we would draw a transducer linking $J$ to $m$. This means that connecting two energy storing elements directly with a transducer does not necessarily make them independent. In particular, the pulley transducer in system (a) relate velocity (A-type) to angular velocity (A-type), and both a mass and a rotational inertia store energy in their A-type power variable. This is what allowed us to write the relationship between the two energy equations. Some transducer configurations will not satisfy these conditions, so care must be taken when applying the test for independence to a system.

System (b)

In system (b), note that the connector pipe between the two tanks, both of which store energy in pressure, is assumed to have no significant resistance. With this assumption, it is easy to see that the pressures at the bottom of each tank will be the same. That means that we could define $P_{2a} = P_{3a} = P_{ta}$. Then, we could write $E_{C1} = \frac{1}{2}C_1 P_{ta}^2$ and $E_{C2} = \frac{1}{2} C_2 P_{ta}^2$. Solving for $P_{ta}^2$ in each equation would again allow us to write $E_{C1}$ as a function only of system properties and $E_{C2}$:

$$E_2 = \frac{C1}{C2}E_1$$

$\frac{C1}{C2}$ is a unitless constant scale factor. Thus the two tanks are not independent..

Drawing an equivalent circuit for this system would show that the two "capacitors" are in parallel with one another, meaning that the voltage drop across each is common, but the current through each is not. In fact, energy storing elements in an equivalent circuit that are either directly in series (where two elements share a common T-type variable) or directly in parallel (where two elements share a common A-type drop) are not independent of one another.

Functionally, dependent elements end up becoming "lumped" into one effective source of energy storage in our model.

In contrast with systems (a) and (b), consider system (c) below:

image-2.png

System (c)

For system (c), we could write the energy stored in $J_1$ as $E_{J1} = \frac{1}{2} J \Omega_1^2$ and $E_{J2} = \frac{1}{2}J_2 \Omega_2^2$.

Unlike in Systems (a) and (b), the two inertias do not move together, and there is no way to know what the value of $\Omega_2$ is just by knowing $\Omega_1$, because there is a damper in between them that dissipates a variable amount of energy depending on the difference between the two angular velocities. $\Omega_2$ is not equal to $\Omega_1$ and they can not be related with a simple constant.

Because $J_1$ stores energy in the power variable $\Omega_1$, and $J_2$ stores energy in the power variable $\Omega_2$, and because we cannot relate those two angular velocities directly without building our full model inclusive of the dissipative element $b$, the two inertias are independent. This means that a model of this system would need to include two derivatives in input-output form, or consist of two first-order differential equations in state-space form. These two "forms" for differential equation models are explored more thoroughly below.

Input-Output Differential Equation Models

An input-output differential equation model is a single differential equation represents a relationship between the system's input (source of power from outside of the system scope) and its output (our dependent variable). Generally speaking, this type of model can be written as:

$$ \frac{d^n y}{dt^n} = f\left(y,\frac{dy}{dt},\frac{d^2 y}{dt^2},\cdots,\frac{d^{n-1} y}{dt^{n-1}},u,\frac{du}{dt},\frac{d^2 u}{dt^2},\cdots,\frac{d^{m-1} u}{dt^{m-1}}, \frac{d^{m} u}{dt^{m}}\right)$$

Don't let the notation scare you. This just means that the highest derivative of our output $y$ is a function of or depends on the output and its derivatives (up to a highest order $n-1$, along with the input and any of its derivatives that are relevant (up to a highest order $m$). You have already been doing this all semester! Your models have mostly been in the form:

$$ \frac{dy}{dt} = \square y + \square u$$

Which is an input-output model as defined above!! As you can see, the equation above is an input-output differential equation with $n=1$ and $m=0$, where the first derivative of our dependent variable $y$ is a function of $y$ itself, and our input $u$ . The "order" of a differential equation is equal to $n$, the number of derivatives of the output (dependent variable) $y$ present in the equation.

Building Input-Output differential equation models

Deriving input-output models for "higher-order" systems is done using our disciplined process from Reading 15. There are essentially no modifications to this process for finding input-output models for systems with an order higher than 1. As you work through the algebraic reduction of your model from the "menu" of elemental, node, and loop equations, expect to take the derivative of one or more intermediate equations as you strive to eliminate unknowns.

Internal Validity of Input-Output Differential Equation Models

So far in this course, we have been assessing internal validity using the following tools:

  1. Check that the form of the model is appropriate given our system scope.
  2. Check the signs of all terms in the differential equation to ensure that the system reaches a steady state (dependent variable reaches a constant value as $t\rightarrow \infty$).
  3. Compute the model's steady state value by setting derivatives of the dependent variable equal to 0 to confirm that it meets expectations.
  4. Check the units of each term in the model.

For question 1, we have been asking "Is my model a differential equation, and should it be?" Recall that it "should be" if the system stores energy. The same reasoning applies for higher-order input-output differential equation models. You can further confirm that the number of derivatives in your model is equal to the number of independent energy storing elements in your scope.

For question 2, things get a little more complicated for systems where $n>1$. For systems with $n=2$, we can still check whether the model reaches a steady state by ensuring that all terms multiplied by our dependent variable $y$ on the right-hand side are $<0$, which tells us that the system's energy will decrease more rapidly as the dependent variable (and its first derivative) increase. HOWEVER, the situation is much more complicated for systems where $n>2$, and we do not have (and will not learn) the tools for checking the stability of systems with order greater than 2 in this course. You will learn these tools in your differential equations course.

For question 3, our process is to perform dimensional analysis on each term in your differential equation to confirm that both sides of the equals sign have the same units, and that terms that are added or subtracted have consistent units as well.

Differential Equation Models in "State Space" Form

Sometimes, building a model of a differential equation model that has an order of 2 or higher in input-output form is algebraically difficult and cumbersome. Luckily, there is a simpler way to represent a differential equation model that may represent a system with multiple independent energy storing elements. It is called a "state space" model.

The term "state space" comes from the fact that the model fully describes the system's energetic "state," or the total energy inside the system. If we pick multiple dependent variables rather than one, and that set of dependent variables can fully describe the system's total energy, then we can write a list of coupled differential equations that represent our system. While the study of state space systems is often reserved for late undergraduate or even graduate study, the concept is fairly simple.

Assume we have a list of $n$ dependent variables for our system because our system has $n$ independent energy storing elements. Let's make their names general to avoid putting ourselves in a box and call these $x_1$, $x_2$, $x_3\ldots,x_n$. Most of the time, these will be either T-type or A-type power variables in a physical system. Let's also assume that, together, these variables fully describes the system's energy storage. Lastly, we will assume that our system has a single external source of power that is described by a known input $u$.

We can then manipulate our system's element, loop, and node equations to get the following list of first order differential equations that describe our system's behavior:

$$ \left\{ \begin{matrix} \frac{dx_1}{dt} &=& f(x_1,x_2,\ldots,x_n,u) \\ \frac{dx_2}{dt} &=& f(x_1,x_2,\ldots,x_n,u) \\ \vdots &=& \vdots \\ \frac{dx_n}{dt} &=& f(x_1,x_2,\ldots,x_n,u) \end{matrix} \right. $$

To read this, a few clarifications will be helpful. What this list says is that the first derivative of each of our states $x_1,x_2,\ldots,x_n$ MAY DEPEND on any or all of the other system states, and/or the input $u$. It does not state that each equation MUST depend on all of these. Any dependence between one state derivative equation and the other system states is called "coupling." This list is a list of coupled first-order differential equations. Later in your career, you may see this written compactly in vector form:

$$\frac{d\vec{x}}{dt} = f(\vec{x},u)$$

Which saves a bit of writing if we just consider the "state vector" $\vec{x}$ to contain all of our system's states. A state space model is, in its most general form, a "vector differential equation," which unlocks a whole set of analysis tools that are unfortunately beyond the scope of this course. For now, we will continue to need to simulate our model numerically to investigate its behavior.

This concept may seem a little more complicated than input-output form at first glance, but building a state space model is really in many ways easier than building an input-output model. Note that technically, all of the first-order models you built this year are already in state space form, just with $n=1$.

Choosing state variables for a state space model

You may be wondering how to know what to choose as your set of dependent variables in a state space model. When you take differential equations, and possibly a higher-level systems course, you will likely learn that there is no one answer to this question. State space models are not unique, and any set of variables that can, in its whole, describe the system's current total stored energy is acceptable.

However, for this course, we will simplify our lives and stick with one approach, which is to choose a state variable that describes the energy storage in each independent energy storing element in your system. For an electrical system, you might choose to use the voltage across each independent capacitor, since they store energy as $E_c = \frac{1}{2}CV_{12}^2$. For a fluid system, you might do the same but with pressures across each fluid capacitor. For a mechanical system, you might choose the velocity or angular velocity of a mass or rotational inertia respectively, since $E_m = \frac{1}{2}mv^2$ and $E_J = \frac{1}{2}J\Omega^2$.

Reducing a "menu" of element, node, and loop equations to a suitable state space model

To build a state space model, first analyze the system's components individually, and analyze how power flows within the system boundaries using loop and node equations.

Then, you would do well to begin by solving each independent energy storage element's equation for the derivative of its power variable. This is a great first step because the power variable for each energy storage element is probably one of your "state variables!"

If you follow the two steps above, you already have your "state space form" started. Then, using substitution, eliminate all unknowns by substitution.

TIP: If you have a few "dependent" energy storage elements in your system, try to eliminate the "extra" power variables associated with these early on. An example would be a system with a rack-and-pinion gear: your "state" for that part of the system might be velocity, so you'd want to eliminate angular velocity early on to help with algebra.

Internal Validity for State Space Differential Equation Models

We will use the same steps here as we used above for input-output models. However, determining whether our system will reach a steady state is possibly even more difficult for a state space model of higher order. This is because of the coupling between the equations. Steps 2 and 3 are thus much more difficult, and you are not expected to be able to perform this step for higher-order models in ES103.

Example: Model Construction in State Space Form

To show how simple it is to obtain a state space model, let's revisit our example from the top of the notebook. The "menu" of equations is reproduced here.

node

$i_1 = i_2+i_3$ (1)

loop

$V_{1g} = V_{12}+V_{2g}$ (2)

$V_{2g} = V_{23}+V_{3g}$ (3)

$V_{1g} = V_{12}+V_{23}+V_{3g}$ (4)

element

$i_2 = C_1\dot{V}_{2g}$ (5)

$i_3 = C_2\dot{V}_{3g}$ (6)

$V_{12} = i_1R_1$ (7)

$V_{23} = i_3R_2$ (8)

As the advice in the preceding section suggests, let's begin by choosing the following list of state variables. We can write this list as a "state vector" $\vec{x}$ to keep track of it:

$$\vec{x} = [V_{2g},V_{3g}]$$

We chose these because $V_{2g}$ describes the amount of energy stored in $C_1$ $(E_{C1}=\frac{1}{2}C_2V_{2g}^2)$ and $V_{3g}$ describes the amount of energy stored in $C_2$ $(E_{C2}=\frac{1}{2}C_2V_{3g}^2)$. This means that we are looking for the following form when our model is complete:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& f(V_{2g},V_{3g},V_{in}) \\ \dot{V}_{3g} &=& f(V_{2g},V_{3g},V_{in}) \end{matrix} \right.$$

Note that our input $u$ in this model will be the input voltage $V_{in}$. Now, following the advice in the preceding section, we can use equations (5) and (6) and solve them for the derivatives of $\dot{V}_{2g}$ and $\dot{V}_{3g}$, respectively. These become:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} i_2 \\ \dot{V}_{3g} &=& \frac{1}{C_2} i_3 \end{matrix}\right.$$

Now, we just have to eliminate unknowns $i_1$ and $i_2$, replacing them so that they only contain independent and dependent variables. For $i_3$, the game is easily won. We can substitute equation (8) in after solving it for $i_3$, and substituting $V_{23}=V_{2g}-V_{3g}$, which yields:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} i_2 \\ \dot{V}_{3g} &=& \frac{1}{R_2 C_2} \left(V_{2g}-V_{3g}\right) \end{matrix}\right.$$

Notice that our second equation now only contains independent and dependent variables. For the first equation, we can solve the node equation (1) for $i_2$, and then replace $V_{12}$ with $V_{1g}-V_{2g}$. Subbing this into our model, we see that:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} \left(\frac{1}{R_1}\left(V_{1g}-V_{2g}\right) -i_3\right) \\ \dot{V}_{3g} &=& \frac{1}{R_2 C_2} \left(V_{2g}-V_{3g}\right) \end{matrix}\right.$$

Then, recognizing that $V_{1g}=V_{in}$ and also that via equation (7) that $i_1 = \frac{V_{in}-V_2}{R_1}$, we can re-use the steps above that told us that $i_3 = \frac{1}{R_2}\left(V_{2g}-V_{3g}\right)$ to get the following:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} \left(\frac{1}{R_1}\left(V_{in}-V_{2g}\right) -\frac{1}{R_2}\left(V_{2g}-V_{3g}\right)\right) \\ \dot{V}_{3g} &=& \frac{1}{R_2 C_2} \left(V_{2g}-V_{3g}\right) \end{matrix}\right.$$

Technically, this model is complete and only includes independent and dependent variables. However, we can clean it up a bit! We could group terms in the first equation to get:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} \left(\frac{1}{R_1}V_{in} -V_{2g}\left(\frac{1}{R_1}+\frac{1}{R_2}\right) + \frac{1}{R_2}V_{3g}\right) \\ \dot{V}_{3g} &=& \frac{1}{R_2 C_2} \left(V_{2g}-V_{3g}\right) \end{matrix}\right.$$

This was arguably fewer steps than the input-output model above. Each equation is also simpler! However, note that not all terms multiplied by a state in each equation are negative!! This is what I mean when I say that state space models can be more difficult to evaluate for stability without more advanced mathematical (matrix) tools that you will learn in later courses. Still, the state space model has advantages in simplicity and readability when you compare it to an input-output model that has multiple derivatives of one dependent variable.

Now that we have some idea of when our algebraic manipulations will lead us to a model that has more than one derivative, and we have discussed two different forms for models of higher-order systems, we need to discuss how we could possibly simulate these models using Euler integration.

Simulating Second Order Differential Equations in Input-Output Form Using Euler Integration

To simulate a second order differential equation using Euler integration, consider how we thought of Euler integration in Reading 6. Computing the integral of a function was visualized as a process of repeated linear extrapolation over small timesteps.

If we consider a system model that is a second order input-output differential equation that takes the form:

$$\ddot{y} = f(\dot{y},y,u)$$

where $u$ is our system's input (source of power from outside of our scope), $y$ is our system's output (dependent variable), and "$f$" represents our model equation relating $\ddot{y}$ to $\dot{y}$ and $y$ and $u$, numerically integrating our function for $\ddot{y}$ could be used to produce an estimate of $\dot{y}$. Then, numerically integrating $\dot{y}$ one more time could be used to produce an estimate of $y$.

This process of integrating $\ddot{y}$ once, then another time, to produce our final estimate of our model's output is attractive, and could be represented by the figure below, in which $\ddot{y}(k-1)$ is used to extrapolate an estimate for $\dot{y}$, and $\dot{y}(k-1)$ is used to extrapolate an estimate for $y(k)$.

image-2.png

The difficulty with this approach is that $\ddot{y}$ depends on our last estimate of $\dot{y}$, $\dot{y}(k-1)$ as well as our last estimate of $y$, $y(k-1)$ and our last input $u(k-1)$. This means that the two integration operations have to occur in the same loop. The structure of such a loop can be summarized as follows, where yd represents $\dot{y}$ and ydd represents $\ddot{y}$:

for k=2:length(t)
    % compute second derivative of output based on model equation, represented here by "f."
    ydd(k-1) = f(yd(k-1),y(k-1),u(k-1));
    % now extrapolate once to get our new estimate of the first derivative of y
    yd(k) = yd(k-1) + (t(k)-t(k-1))*ydd(k-1);
    % now extrapolate a second time to get our new estimate of y itself.
    y(k) = y(k-1) + (t(k)-t(k-1))*yd(k-1);
end

Notice that we are are not using the new estimate of $\dot{y}$ in the second integration! See the figure above to see why-- we are calculating the slope of each function one timestep behind where we would like to predict to.

Also note that for this approach to work, an initial condition for $y$ is needed along with an initial condition for $\dot{y}$ so that the values y(1) and yd(1) are known, and can be used as the starting point for extrapolation on the first iteration of the loop.

Extending the integration methodology above to include systems with even higher order derivatives also works, as long as the model equation is solved for the highest derivative. Then, the loop structure presented above can be modified to perform as many sequential integrations as is necessary.

Example

This approach is applied to our example in the code cell below. As a reminder, our input-output model for this notebook's example was:

$$\ddot{V}_{3g} = \frac{1}{R_1C_1R_2C_2}(V_s - (R_1C_1+R_2C_2)\dot{V}_{3g} -V_{3g})$$
In [1]:
clear all
%create a time vector
t =0:.1:20;

%set up independent variables
R1 = 1000;
R2 = 15000;
C1 = 470e-6;
C2 = 330e-6;
%input voltage
Vs = 5;
%initialize V3 and its derivative... both of which we need to keep track of.
V3d = zeros(size(t));
V3 = zeros(size(t));
for k=2:length(t)
    % compute second derivative of output based on model equation.
    V3dd = 1/(R1*C1*R2*C2)*(Vs - (R1*C1+R2*C2)*V3d(k-1)-V3(k-1));
    % now extrapolate once to get our new estimate of the first derivative of V3
    V3d(k) = V3d(k-1) + (t(k)-t(k-1))*V3dd;
    % now extrapolate a second time to get our new estimate of y itself.
    V3(k) = V3(k-1) + (t(k)-t(k-1))*V3d(k-1);
end

%plot results
figure
plot(t,V3,'k')
xlabel('Time (s)')
ylabel('Voltage V3')

Simulating Higher-Order Differential Equation Models In State Space Form Using Euler Integration

As we did above for input-output systems, we will need to extrapolate more than one time in each "loop" of our Euler integration code. This is because we will need to compute one derivative for each state variable at each timestep, and update all of the state variables before moving on, because of the coupling between the list of first-order differential equations in our model. This is fairly simple, and can be done very easily for systems of very high order (for an input-output model, this would be much harder). Code that implements this can be put in a for-loop as follows:

for k=2:length(t)
    % compute the derivative of each state based on model equations.
    x1d(k-1) = f(x1(k-1),x2(k-1),...,xn(k-1),u(k-1));
    x1d(k-1) = f(x1(k-1),x2(k-1),...,xn(k-1),u(k-1));
    ... %could be many of these... then the last one xn:
    xnd(k-1) = f(x1(k-1),x2(k-1),...,xn(k-1),u(k-1));
    % now extrapolate once for each state to get our new estimates.
    x1(k) = x1(k-1) + (t(k)-t(k-1))*x1d(k-1);
    x2(k) = x2(k-1) + (t(k)-t(k-1))*x2d(k-1);
    ... %repeat for as many states as you have
    xn(k) = xn(k-1) + (t(k)-t(k-1))*xnd(k-1);
end

Example

Below, you will find an implementation of this idea for our example's state space model. As a reminder, our final state-space model was:

$$\left\{ \begin{matrix} \dot{V}_{2g} &=& \frac{1}{C_1} \left(\frac{1}{R_1}V_{in} - V_{2g}\left(\frac{1}{R_1}+\frac{1}{R_2}\right) + \frac{1}{R_2}V_{3g}\right) \\ \dot{V}_{3g} &=& \frac{1}{R_2 C_2} \left(V_{2g}-V_{3g}\right) \end{matrix}\right.$$
In [2]:
clear all
%create a time vector
t =0:.1:20;

%set up independent variables
R1 = 1000;
R2 = 15000;
C1 = 470e-6;
C2 = 330e-6;
%input voltage
Vin = 5;
%initialize V3 and its derivative... both of which we need to keep track of.
V2 = zeros(size(t));
V3 = zeros(size(t));
for k=2:length(t)
    % compute derivative of each state based on our model. Each state's derivative depends on old values of each state.
    V2d = 1/C1*(1/R1*Vin - V2(k-1)*(1/R1+1/R2)+1/R2*V3(k-1));
    V3d = 1/(C2*R2)*(V2(k-1)-V3(k-1));
    % now extrapolate once to get our new estimate of each state
    V2(k) = V2(k-1) + (t(k)-t(k-1))*V2d;
    V3(k) = V3(k-1) + (t(k)-t(k-1))*V3d;
end

%plot results
figure
plot(t,V3,'k',t,V2,'b')
legend('V_3','V_2')
xlabel('Time (s)')
ylabel('Voltage V3')

Notice here that we get estimates for both states without any extra work. This is cool, because we can see the differences in how the capacitor C1 charges vs. how the capacitor C2 charges. You'll also notice that our plot for V3 looks EXACTLY THE SAME as it did for our input-output model, which is good news! The two models are equivalent-- they're just in different forms!!

Scoping tips and disciplined process modifications for higher-order systems

Now that we've seen how you can build and evaluate models for systems with more than one independent energy storage element, you may notice that we haven't talked much about scoping these systems. In general, this is because the process is the same as it always has been!

However, a couple of tips may help you get even more out of your scoping process when higher-order systems are involved.

  • Draw your system boundary as before in an overall energetic diagram. Show power flow into and out of the system. Indicate inside of the energetic diagram how you are splitting your system up into elements. Generally, "idealized sources" should go outside of your system scope. Clearly indicate which independent variable(s) is/are your system's input(s).
  • Including an equivalent circuit in your scoping process is a good idea! Label this equivalent circuit so that writing your elemental, node, and loop equations later is easy.
  • Separate your system's elements into a list of energy storage and energy dissipation elements to help determine system order, or separate them graphically in your system-level energetic diagram.
  • Count and indicate the number of independent energy storing elements in your system. If you are not sure what elements are independent, use their energy storage equations to check!
  • Indicate whether you intend to build an input-output or a state-space model for the system. Write down a general form you'd expect your final model to take so that your algebra stays focused when the time comes.
  • Form a list of your independent and dependent variables. If you are building a state space model, it is especially important to carefully choose your system's states based on how the energy storage elements store their energy.

Now, let's use everything we know to build and validate a model for an electrical circuit with two independent energy-storing elements.

Assignment

In this assignment, you will build a model for the following electrical circuit. In practice, a circuit like this one could be used to filter a time-varying voltage source $V_s$ (perhaps it comes from a sensor on a robot, or the output of an instrument). An analogous mechanical system might represent two masses connected by a damper to one another, with damping between ground and the second mass. In a fluid system, a similar network might represent a chemical mixing plant used to create a food or drug product, where two tanks are connected by a valve.

In this particular incarnation, we will literally model a simple electrical circuit built on a breadboard, with voltages measured by an Arduino microcontroller. The actual, physical setup is shown below:

image.png

A circuit diagram representing how the various components are connected is shown below:

image-2.png

What you know

In this system, the following components were used:

  • For $R_1$, a $1k\Omega$ resistor was used.
  • For $R_2$, a $15k\Omega$ resistor was used.
  • For $R_3$, a $1M\Omega$ resistor was used.
  • For $C_1$, a $470 \mu F$ capacitor was used.
  • for $C_2$, a $330 \mu F$ capacitor was used.
  • The system was subjected to a constant voltage input $V_s$ was a constant $5.00V$ starting at $t=0$.

Deliverable: Scope and construct a model for the system in input-output form

In the markdown cell below, construct a model that considers the voltage across $C_2$ to be the model's output. Your model should be a second-order differential equation that is solved for the second derivative of the output voltage.

YOUR ANSWER HERE

Deliverable: Evaluate your model

Using the data file reading17data_C2.txt in which columns are time and voltage across $C_2$, confirm that your model produces a reasonable voltage estimate.

Develop your Euler simulation below for your model in input-output form. On a single plot, compare your Euler simulation with the data.

In [3]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

Deliverable: Construct a model for the system (using the same scope) in state space form

Starting with the same "menu" of equations, choose a set of states and build a model for the system in state space form.

YOUR ANSWER HERE

Deliverable: Evaluate your state space model

Simulate your model in state space form. On a single plot, compare your Euler simulation with the data.

In [4]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

Deliverable: Discussion

Given what you see in your Euler code vs. your block diagram simulation results, comment on the accuracy of your model. No model is perfect, so use the evaluation tools you have to determine whether the model parameters could be improved, whether your model equation is a likely source of error, or whether your Euler integration code is suspect.

Also comment on the differences in shape you notice between this plot and the similar, first-order plots we have seen for other models this semester.

YOUR ANSWER HERE

Deliverable: Discussion

Which form do you prefer to work with and why? There is no right answer here! Just explain which form, for you, feels more intuitive, and explain.

YOUR ANSWER HERE