everything is the same modeling engineered systems

82
Everything is the Same: Modeling Engineered Systems Lecture Notes Todd D. Murphey c Todd D. Murphey

Upload: yashar2500

Post on 15-Apr-2017

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Everything is the Same Modeling Engineered Systems

Everything is the Same: Modeling Engineered SystemsLecture Notes

Todd D. Murphey

c©Todd D. Murphey

Page 2: Everything is the Same Modeling Engineered Systems

ContentsCalculus Review ii

1 Everything Is The Same 2

2 Modeling Components 5

3 Newton’s Laws 9

4 Euler Integration 13

5 Exponential Solutions 16

6 Superposition 20

7 Newton’s Laws with Mass 23

8 Newton’s Laws with Several Masses 25

9 Imaginary Numbers and Euler’s Formula 28

10 Imaginary Numbers Continued 30

11 Vector and Matrix Representations 34

12 Vector Solutions to Ordinary Differential Equations 38

13 Chemical Diffusion and Fick’s Law 42

14 The Diffusion Equation with No Accumulation 44

15 The Diffusion Equation with Accumulation 47

16 Time-Varying Diffusion 50

17 The Convolution Equation 53

18 Modeling Electrical Components 57

19 Kirchhoff’s Laws 60

20 Kirchhoff’s Laws with Inductors 63

21 Vector and Matrix Representations in Kirchhoff’s Laws 66

22 Mechanical/Electrical Analogies 69

23 Interpretation of Mathematical Expressions as Physical Systems 72

Page 3: Everything is the Same Modeling Engineered Systems

24 Everything Is The Same—Almost 75

i

Page 4: Everything is the Same Modeling Engineered Systems

Calculus ReviewThere are not that many things you need to remember from calculus, but the few that you do needare extremely important. These notes are intended to serve as a reminder of what you learned incalculus, and I will reference these facts during the rest of the class.

Derivatives, Derivative Notation, and Integrals

First, you have to know what a derivative of a function with respect to a scalar is. For instance, ifI have a function f(x)—where x is an unknown number—the derivative of f(x) with respect to xis defined to be

d

dxf(x) =

df

dx(x) =

df(x)

dx= lim

dx→0

f(x+ dx)− f(x)dx

.

This definition says that if I change x by a small amount dx, then the value of the function willchange as well, and the amount of that change is encoded by the derivative if dx is small enough.

Other notation for the derivative of f(x) with respect to x includes dfdx(x) and df(x)

dx—these are

just notational choices; the limit above is the actual definition. Another notation that I will use onetime during the class is the “prime” notation

d

dxf(x) = f ′(x).

Most of the time we will be taking derivatives of a function with respect to time t. In this case,special notation is sometimes used, called “dot” notation. If I have a variable y that is a functionof t (that is, it is of the form y(t)), then I can write the first derivative of y with respect to t as

d

dty = y.

Moreover, I can write the second derivative of y with respect to t as

d2

dt2y = y.

This notation is very common in engineering. Lastly, if I differentiate a function with respect tomultiple variables, I will need to be able to identify the variable in question. Let’s say I havef(x, y) and I want to take the derivative with respect to x and the derivative with respect to y, thenI use the partial derivative notation ∂

∂xf(x, y)

∂yf(x, y)

to represent those derivatives.Integrals are simply “the opposite” of differentiation. If d

dxg(x) = f(x), then

∫f(x) = g(x).

ii

Page 5: Everything is the Same Modeling Engineered Systems

Examples

If n is an integer (n = 1, 2, 3, . . .) and h is a scalar parameter (it is a number), then

d

dttn = ntn−1

d

dtsin(ωt) = ω cos(ωt)

d

dtcos(ωt) = −ω sin(ωt)

d

dteht = heht

If x(t) represents the position of an object as a function of time. Its first derivative is velocity

v(t) =d

dtx(t) = x(t) = x.

Its second derivative is acceleration

a(t) = v(t) = v = x(t) = x.

Product Rule, Chain Rule, and Leibniz Rule

There are three rules you need to remember from calculus. One of them is product rule: that if fand g are both functions of x, then the derivative of the product f(x)g(x) is equal to

d

dx(f(x)g(x)) =

(d

dxf(x)

)g(x) + f(x)

(d

dxg(x)

).

The chain rule says that if one composes f(y) and g(x) (i.e., has the function h(x) = f(g(x))),then the derivative is:

d

dxf(g(x)) =

d

dyf(g(x))

(d

dxg(x)

).

This is often very confusing because it isn’t clear what “y” is. The key is that g(x) must have itsoutput be the same type of variable as y is—so if g(x) is a number, then y must be a number and ifg(x) is a vector, then y is a vector.

Lastly, Leibniz rule will play a role at one particular point. People are often a bit scared byLeibniz rule, but it is tremendously useful. Let’s say that f(t) is actually a function that involvesan integral. For example

f(t) =

∫ t

0

sin(τ)dτ

is a function that involves an integral. For any given t, this function will return a number, and thatmeans that you can differentiate with respect to t. Leibniz rule tells us that the derivative can befound by:

d

dt

∫ t

0

h(τ)dτ = h(t).

This says that the derivative of this integral is equal to the function being integrated at the time t.

iii

Page 6: Everything is the Same Modeling Engineered Systems

Examples

d

dxsin(ωx) = ω cos(ωx)

d

dt

∫ t

0

sin(τ)dτ = sin(t)

Taylor Series

Yes, Taylor series are really, really important! The Taylor series of a function f(x) is anapproximation of the function f at a value of x that only involves derivatives of f evaluated at thatvalue of x (in this case x = 0).

f(x) = f(0)+

(d

dxf(x)

)x+

1

2!

(d2

dx2f(x)

)x2+

1

3!

(d3

dx3f(x)

)x3+· · ·+ 1

n!

(dn

dxnf(x)

)xn+· · ·

Examples of Taylor series that are particularly relevant to this class are derivatives of eht, sin(ωt),and cos(ωt).

eht = 1 + ht+1

2!h2t2 +

1

3!h3t3 +

1

4!h4t4 +

1

5!h5t5 +

1

6!h6t6 · · ·

sin(ωt) = ωt− 1

3!ω3t3 +

1

5!ω5t5 + · · ·

cos(ωt) = 1− 1

2!ω2t2 +

1

4!ω4t4 − 1

6!ω6t6 + · · ·

Other Useful Facts

Lastly, here are some facts worth knowing:

1. ea+b = eaeb

2. If we have three coefficients α, β, and γ, then

αh2 + βh+ γ = 0

implies that

h =−β ±

√β2 − 4αγ

2α.

This is called the quadratic formula.

3. The imaginary numbers involve j =√−1.

1

Page 7: Everything is the Same Modeling Engineered Systems

1 Everything Is The SameWelcome to my Coursera class Everything is the Same: Modeling Engineered Systems. I hope youare looking forward to the class!1

One of the most fundamental goals of this class is to train you to synthesize different aspects ofengineering skills. In particular, good engineers typically employ a combination of Analytical Rea-soning, Computational Skills, and Physical Knowledge to solve problems. The more critical theengineering problem is—such as making sure that the power grid does not experience failures—themore important it becomes to combine these skills rather than just using one.

By Analytical Reasoning, I mean the ability to write down mathematical expressions that rep-resent a physical system. By Computational Skills, I’m referring to the ability to use a computer toeither evaluate or predict characteristics of a model that are too challenging to solve analytically.And by Physical Knowledge—possibly the most important of the three—I mean the crucial abilityof an engineer to think critically about analysis and computations in the context of real, physicalknowledge about the world. This last piece can only come from experience, so in this class I’mgoing to rely on examples that you either already have experience with or examples that you caneasily reproduce on your own.

For those of you that saw the promotional video for this class, you saw the examples of thepower grid (a snapshot of which is in Fig.1) and the biomechanics of the hand.

Figure 1: A snapshot of the powergrid animation from the class promotional video.

Both of these examples are, of course, very complex to understand. Using physics-based mod-eling, we can use analysis to come up with a model of the hand and we can use computations tomake predictions using that model, seen on the left in Fig. 2.

But what happens when we compute something that doesn’t make sense, like on the right ofFig. 2? When I look at this numerical simulation of the hand, I certainly don’t think that I everwant my hand to behave that way!

The reason we know that there is something wrong is because of our physical experience—wesimply know that a real hand doesn’t behave the way this movie suggests, despite the fact that theanalysis and computation was all done carefully. This physical knowledge tells us that there is

1If you are reading these notes after listening to the first lecture, you will notice that the class notes nearly perfectlyfollow the online lectures—this is intentional! However, these class notes will have many additional footnotes, likethis one, to explain and/or clarify concepts as we go.

2

Page 8: Everything is the Same Modeling Engineered Systems

Figure 2: A simulation of the hand from the class promotional video. The simulation on the leftlooks plausible, but the simulation on the right doe not!

something wrong with either our analysis or our computations or possibly both, and synthesizingphysical knowledge into our engineering judgement is a critical aspect of engineering safe, reliablesystems.

One of the challenging things about physical knowledge is that we all have different experi-ences, so learning together is critical. Because of that, I really encourage you all to participate inonline discussions and—if at all possible. This social aspect of learning is, I think, critical to be-coming fluent in modeling engineered systems and, simultaneously, thinking critically about thatmodeling process.

In this class, you will learn different aspects of engineering modeling techniques. You willlearn Analytical Reasoning, including the importance of linear models, that differential equationsare nearly universal in engineering models, and that mathematical analysis of those models canboth help you understand systems better and make your life quite a bit easier. To be prepared forthis analytical part of the class, you should have had some pre-calculus; in particular, you shouldknow that position and velocity are related by the time derivative—that the velocity v is the timederivative of the position x.2 Aside from that, you really only need to be prepared to do somealgebra.

You will learn Computational Skills, including numerical integration methods that you willimplement in either MATLAB or Python and the use of vector representations—these also makeyour life quite a bit easier. You don’t need any experience with programming for this part of theclass, but you will need to either purchase a MATLAB license or download Python, which is free.We will provide short MATLAB tutorials to help you get started and provide sample MATLABcode to guide you through the class.

Lastly, you will learn Physical Knowledge, which will help you internalize when you can usethe mathematical modeling tools we are learning, when you cannot, and improve your engineeringjudgment as a result. Whatever experience you already have will prepare you for this part of theclass.

Throughout the class, you will test the development of these skills by trying out the exercisesdirectly following the lectures and the homework. These will help you investigate the material inmore depth and solidify the material presented in the lectures.

2If you haven’t already, you should look at the calculus review we have posted to make sure you are familiar withthe ideas that are there.

3

Page 9: Everything is the Same Modeling Engineered Systems

Combining analytical reasoning, computational reasoning, and physical reasoning is an essen-tial part of being an engineer, and I hope that as you take this class you learn how to synthesizethese skills for your future as engineers.

4

Page 10: Everything is the Same Modeling Engineered Systems

2 Modeling ComponentsLast time I mentioned that Analytical Reasoning, Computational Skills, and Physical Knowledgeare all critical components of an engineer’s judgment. Building those skills starts with understand-ing how to model components of a physical system.3

Figure 3: Force is related to position or velocity through a constitutive law, often a linear constitu-tive law for engineered systems.

Today we are going to investigate how we model components of a mechanical system. In gen-eral, we use what are called constitutive laws to model individual components. These constitutivelaws relate variables of interest, like position x and velocity v—the derivative of position with re-spect to time—to forces. For instance, a plot of a constitutive law might look like the one in Fig. 3,where the force F is on the vertical axis and the variable x or v is on the horizontal axis. If youthink of pulling on a spring—like the slinky I showed in lecture—the spring only exerts a force if

3You will notice that there are lots of footnotes in these lectures notes. The reason for so many footnotes is that Iwant the main text of the lecture notes to perfectly track the online lectures, so that it is easier to find the relevant placethat you have questions about. As questions come up, I will add footnotes explaining small points or add sections atthe end of each lecture explaining bigger points.

5

Page 11: Everything is the Same Modeling Engineered Systems

it is either compressed or extended away from its natural length, so if the amount of extension isexactly zero, we expect the force to be zero. That’s why this curve goes through the origin. If wepull on a spring extending it some set amount, then the amount of force we will feel will be nonzeroand might be up and to the right. Now the thing to hope for is that if we draw a line between theorigin and that point, we get a prediction of how much force we should feel for any given amountof extension of the spring. A relationship that has a line relating the two variables is called a linearrelationship. A linear relationship is a lot to hope for, and in general natural systems do not behavethat way.

But engineered systems have some engineer’s brain involved, and that engineer’s brain knowsthat we would prefer the relationship to be a line. That’s why engineered systems typically doend up with constitutive laws that can be described by a nice line like this. By the way, that’s alsowhy this class is about modeling engineered systems; only engineered systems—systems that havebeen designed by someone—actually behave this way.

Figure 4: This course will focus on the 3 types of elements shown in the diagram–springs, masses,and dampers

Mechanical diagrams play a critical role in how we set up models of mechanical systems,and in this class we are going to always assume that we have three types of components—springs,dampers, and masses. We will always use the three symbols in Fig. 4 to represent the three types ofidealized components. We will always use the same sign conventions as well. Whenever a spring,like the slinky from lecture, is in extension, its position xs is defined to be positive. Whenever adamper, like the syringe I showed in lecture, is in extension, its velocity vd is defined to be positive.

Moreover, the relationship between force and position of a spring is always a line representedby the constitutive law Fs = kxs (where the positive number k is called the spring constant).The the relationship between force and velocity of damper is also always a line represented by theconstitutive law Fd = bvd (where the positive number b is called the damping constant). Hence,the force of a spring being positive means that the position must be positive and the spring must bein extension. The force of a damper being positive means that the velocity of the damper must bepositive and the damper must be extending.

Fs > 0⇒ xs > 0 Fd > 0⇒ vd > 0

Example: With these sign conventions in mind, we can combine elements into combinationsof elements, in this case a spring and a damper in parallel. Note that the spring and damper, bothconnected to a wall on the left, must move in unison—the only allowed motion is horizonal motion.No matter how many elements are in parallel with each other, they must move just to the left or theright—they cannot move up and down in the diagram.

6

Page 12: Everything is the Same Modeling Engineered Systems

Figure 5: A spring-damper system with an external force. You will see this more than you wouldprobably prefer by the end of the class.

That implies that the end of the spring is attached to the end of the damper, which implies arelationship between the position of the spring xs and the velocity of the damper vd. In particular,the time derivative of the position of the spring must be equal to the velocity of the damper.

Lastly, you should know that we always define positive acceleration of a mass to be to the rightand external forces are always positive if the force is acting to the right—that is, the force wouldcause a positive acceleration of a mass.

Figure 6: A spring with an external force. If the force changes instantaneously, so does the positionof the spring. This is unintuitive because this is an ideal spring.

Example: Now, sometimes our understanding of a physical system will not be well aligned withour understanding of idealized elements. As an example, consider this very simple system in Fig. 6that consists of a spring with no mass and an external force. When the spring is in extension, theforce is defined to be positive, and when the external force is positive, it is pulling the spring intoextension. What does our constitutive law say about what happens if Fext starts out at zero andthen suddenly becomes positive? Specifically, what if Fext = 0N until t = 1 and then becomesFext = 1N?

While the external force is zero, the force on the spring is zero and its position is zero. Hope-fully this makes sense because the spring will only be extended or compressed if something isforcing it to be. However, if we make the force jump up to one Newton, the position of the springwill instantaneously jump as well. That probably seems unintuitive, but that’s because real springshave ideal spring properties plus damping properties and mass properties! Keeping in mind thedifference between these idealized elements and the real physical objects they represent, is one ofthe key skills you will develop over the course of this class; this difference forces us to bridge thegap between Analytical Reasoning and Physical Knowledge.

What should you remember from today? Keep in mind that constitutive laws are linear be-

7

Page 13: Everything is the Same Modeling Engineered Systems

cause we engineer systems to make them linear, that sign conventions matter, and that idealizedmechanical elements can have unintuitive behavior.Example: As another example, think about Fig. 5 for a moment, with Fext = 0. Which of the twoplots below is even plausible?

The one on the left implies that, as a function of time, xs gets smaller and smaller, very slowly.The one on the right implies that, as a function of time, xs gets bigger and bigger, very quickly.Therefore the one on the right doesn’t really make sense for a physical system, but the one on theleft does.

8

Page 14: Everything is the Same Modeling Engineered Systems

3 Newton’s LawsLast time we learned how constitutive laws relate forces to variables describing components, butwhat principles do we use to combine those constitutive laws into models of mechanical systems?Newton’s laws4 provide the basis for everything we do. You probably know Newton’s laws already:they say that the sum of the forces at a point must be equal to the mass of that point times itsacceleration. ∑

F = ma (1)

Something we often do not acknowledge is that Newton’s laws are really only interesting ordeep if there are multiple forces involved—that is, the statement that F = ma is not all thatinteresting because of course the second derivative of position must be equal to something.5 Butthe sum of forces being equal to mass times acceleration is very deep, because that means therecan be multiple components that all interact with each other through this magical relationship!

Figure 7: A spring with an external force equal to zero.

As an example, let’s go back to our spring and damper system where we assume that theexternal force is equal to zero. This spring-damper system could represent a shock absorber on avehicle that has a load of an external force on it or a bungee cord like the one I showed in lecturethat I can stretch by pulling on the end with an external force. Newton’s laws tell us that the sumof forces at the point where the spring and the damper meet must be equal to the mass times theacceleration of that point.

A positive external force will cause the point mass to accelerate to the right. On the otherhand, a positive spring force—indicating that the spring is in extension—will accelerate the pointto the left.6 Similarly, a positive damping force would act to the left. Hence, the sign conventionswe chose for the individual mechanical elements have consequences for the signs in Newton’sequations

Fext − Fs − Fd = ma = 0

and I strongly recommend that you get in the habit of making sure that you think about the physicalmeaning of each force as you incorporate it into Newton’s laws.7 Now, if we assume that the

4It is pretty amazing the Newton’s laws have held up as well as they have—Newton’s laws lasted as the only realcandidate for macroscopic physical law until Euler and then eventually Einstein.

5I think this confused me as an undergraduate for at least two years!6Note that this is only true because the spring is on the left. If it were on the right, then a positive spring force

would accelerate the point mass to the right, in the positive direction.7The generalization of keeping track of sign conventions in this way is called a free body diagram. For us, free

body diagrams are unnecessarily complicated and don’t really help very much, but as soon as you are trying to add upforces acting on a body in three dimensions they become really useful.

9

Page 15: Everything is the Same Modeling Engineered Systems

external force is zero and that the mass of the point is zero, we are left with a much simplerexpression of Newton’s laws −Fs − Fd = 0.

If we use the constitutive laws from Lecture 2 that relate the spring force to the spring positionand the damper force to the damper velocity,

Fs = kxs Fd = bvd

and substitute these constitutive relations into Newton’s laws, we get an equation involving xs andvd.

−Fs − Fd = 0

⇒ −kxs − bvd = 0

If we additionally keep in mind that the time derivative of the position of spring is equal to thevelocity of the damper (i.e., xs = vd), we get a simple equation involving only the position of thespring.

−kxs − bxs = 0

Now, if we define x to be the position of the spring (just dropping the “s”), we get

−kx− bx = 0

and if we then solve for x (remembering that the “dot” notion is the same as ddtx), we get what is

called an ordinary differential equation or ODE for short.

x = −kbx x = f(x)

This ODE says that the “derivative of the position is equal to the negative spring constant dividedby the damping constant multiplied by the position”.8

Note that this means that the derivative of the variable x is equal to a function of the variable x.This is the form of an ODE—it is always the derivative of “something” being equal to a functionof that “something”.

d

dt(something) = f(something) (2)

In this case, that “something” is the position x and f(x) is equal to −kbx. In general the “some-

thing” is called the state of the ODE.States of mechanical systems do not have to be positions—later we will also use velocity of

masses as states. Engineers get good at choosing the state of an ODE with experience, and youwill get good at this as well.

In principle, an ODE can be very complex. For instance, it could look something like

x = tanh−1(x2)

which is clearly a huge mess! But for us we will always focus on what are called linear, constantcoefficient, first-order ordinary differential equations. Linear means that the dependence of a state

8As you get accustomed to looking at ODEs, it can be very, very helpful to say what the ODE means out loud. If Iam looking at an equation I find confusing, I still do this.

10

Page 16: Everything is the Same Modeling Engineered Systems

velocity on a state is always a line. Constant coefficient means that the slope of that line is alwaysconstant. First order means that there is only one time derivative. That is, we should only see onedot over x rather than two.

Let’s finish with another example and go back to the model of the spring and damper, but nowallow the external force to be nonzero. This would be like we take the bungee cord from lectureand pull on it with a constant force.

Now we have the external force in the equation but the mass is still zero. If we replace the springand damper forces by their constitutive laws, we can solve for an ordinary differential equation thatnow includes the external force.

0 = Fext − Fs − Fd⇒ 0 = Fext − kx− bx

⇒ x = −kbx+

Fextb

It is worth thinking about this differential equation and what it means. It says that if the position ofthe spring starts out less than zero, making the left hand term greater than zero, and if the externalforce is greater than zero, then the velocity of the position of the spring must be positive. If theposition of the spring is positive and the external force is negative, then the velocity of the springmust be negative.

But if both position and force are positive, we don’t know which direction the spring willmove—it depends on the magnitudes of the external force, the spring constant k, and the dampingconstant b.

The most important thing from today to remember is that Newton’s laws lead to ordinary dif-ferential equations and that if the constitutive laws are linear, you should expect a linear, constantcoefficient differential equation.Example: Suppose one just has a damper (no spring and no mass) and applies a force to it—whathappens?

The diagram might look like the one above. Applying force balance to this example leadsto a potentially surprising outcome. We know that the damper force is defined to be Fd = bvd,where vd is the velocity of the damper. Hence, Fd > 0 when the damper is extending and Fd < 0when the damper is compressing. Moreover, if we write force balance at the drawn node, we getFext − Fd = 0, so vd = 1

bFext. This means that if one applies Fext = 1N of force to a damper, it

will extend at a constant rate forever, until Fext changes.

11

Page 17: Everything is the Same Modeling Engineered Systems

State Choices and Sign ConventionsSomething that can be very annoying about all of this is how arbitrary the state choices and signconventions seem. Let me discuss first what it means to have a sign convention and then discuss—separately—why we choose states and signs the way we do.

First, it is worth admitting that conventions are arbitrary. Everything in this class could be doneunder a different set of conventions, and one could make everything work out. For instance, wewill always choose the position of a spring to be a state, and we will always choose the position tobe positive if the spring is in extension and negative if the spring is in compression. This choiceis largely to make the constitutive laws work out nicely. If the spring transitions from extension tocompression, we would like the force generated by the spring to change sign as well, so choosingthe position x to be positive in extension and negative in compression allows us to use a constitutivelaw of the form F = kx.

Of course, we could make other choices. We could choose x to be the distance between theends of the spring, but that would mean that the constitutive law would be F = k(x− L)—so thatwhenever the spring is extended beyond its natural length L we get a positive force and wheneverit is compressed we get a negative force. But this convention means we have to know L! So really,the convention we use is to make book keeping easier. It also turns out that with our choice ofstate, we will always get a linear ordinary differential equation, whereas if we use this one we geta form of ordinary differential equation that is harder to work with. The choice of state is largelyto make our lives a bit easier, but in this class I am making the choice for us.

Choice of sign convention for forces works similarly. Here, it is worth noting that the “springforce” is not the same thing as the Newtonian force. Newtonian forces are defined as positive if theforce is to the right and negative if the force is to the left. Spring forces are positive if the springis in extension and negative if the spring is in compression. Spring forces are defined the way theyare to enable the use of F = kx as the constitutive law, but Newtonian forces are defined the waythey are so that we can use

∑F = ma. That means we will have to convert between them when

we are solving problems.

12

Page 18: Everything is the Same Modeling Engineered Systems

4 Euler IntegrationLast time we learned that Newton’s second law leads to a differential equation. If we have adifferential equation, how should we numerically approximate its solution?

To answer this question, let’s go back to our example of the spring and damper, which I’m sureyou are getting sick of by now.9 The differential equation, as I’m sure you remember, is

x = −kbx = f(x) x(t) = −k

bx(t) = f(x(t))

where I’m going to rewrite the differential equation to keep in mind that the position of the spring,denoted by x, specifically depends on time—the position is allowed to change as a function oftime.

Moreover, I’m going to refer to the right hand side of the differential equation as f(x(t)). If wenow look at the left hand side, we see the derivative of x(t) with respect to t, which by definitionis equal to

x(t) := limdt→0

x(t+ dt)− x(t)dt

= f(x(t)) (3)

(where := is the notation used to say that the left hand side is defined to be the right hand side).This says that “the derivative of x is equal to the limit as dt goes to zero of x(t + dt) minus x(t)divided by dt”. So far I haven’t changed anything—this is still a differential equation and it is stillequal to f(x(t)).

However, if I do not take the limit, and instead simply say that dt is some rather small number—where I’m not going to say exactly what I mean by “small”—we get an expression that onlyapproximates x and is therefore approximately equal to f(x(t)).

x(t+ dt)− x(t)dt

≈ f(x(t)) (4)

If I rearrange this approximate equation, I get that x(t+ dt) is approximately equal to x(t) plus dttimes f(x(t)).

x(t+ dt) ≈ x(t) + dtf(x(t))

This formula, called Euler integration, means that if we know x at some time t, we can approximatex at t+ dt. This also means that you should expect to need to know x at some time in order to getthe algorithm started.

Euler integration is the easiest method for numerically approximating a solution to an ordinarydifferential equation, but there are certainly other options. You will see in homework that some-times Euler integration doesn’t do a very good job, but if you make dt small enough, you willalways end up approximating the limit in the definition of the time derivative well enough to giveyou a decent approximation of the solution to the ODE.Example: To practically see how Euler integration works, let’s look at the spring/damper systemagain. Assume that we start out with x at time t = 0 equal to 0.5, k = 1, and b = 1, dt = 0.1.Then x(0) is, of course, equal to 0.5. What is x(0.1) approximately equal to? Well, using Euler

9I really am sure you are getting sick of this by this point, and you are probably wondering how “everything is thesame” if we are only looking at one example. I promise, using just one example for a bit will help to make sure we geteverything straight from the start and I promise that you will be looking at more exciting examples soon!

13

Page 19: Everything is the Same Modeling Engineered Systems

integration we know that x(0.1) is approximately equal to x(0) plus dt times −kbx(0). Once we

know that, we can approximately x(0.2) by taking x(0.1) and adding dt times −kbx(0.1) to it.

x = −kbx x(0) = 0.5 dt = 0.1 k = 1 b = 1

x(0) = 0.5

x(0.1) ≈ x(0) + dt−kbx(0) = 0.5 + 0.1(−0.5) = 0.45

x(0.2) ≈ x(0.1) + dt−kbx(0.1) = 0.45 + 0.1(−0.45) = 0.405

x(0.3) ≈ x(0.2) + dt−kbx(0.2) = 0.405 + 0.1(−0.405) = 0.3645

... and so on . . .

We could continue this process for x(0.3), x(0.4), x(0.5), and so on. In case you haven’tguessed, this process could get really annoying over time, so this is why we will have a computerdo it.Example: Let’s look at two pieces of code, one in MATLAB and one in Python, since thoseare the two choices you all have to use. Both pieces of code implement Euler integration for thespring-damper system.

Figure 8: Euler integration code in MATLAB (left) and Python (right)

Note that at the top of the code we declare the initial conditions to be x(0) = 0.5, that dt = 0.1,that k = 1 and b = 1. Then we create an array to store all the variables for all time. Then a loopexecutes Euler integration and stores the values in the array. After exiting the loop, we plot the

14

Page 20: Everything is the Same Modeling Engineered Systems

results. You will do code very similar to this in your homework assignment, so looking at thisexample several times will be helpful!

What should you remember from today? Euler integration provides a means for you to approx-imate the solution to an ordinary differential equation and it doesn’t matter whether the differentialequation is linear or not!Example: Let’s do another example of Euler integration. Let’s say that x = −2x and x0 = 1.Moreover, let’s assume we are going to use a dt of 0.1. How can we approximate x(0.1)?

x(t+ dt) ≈ x(t) + dtf(x(t))

x(0.1) ≈ x(0) + 0.1f(x(0))

= 1 + 0.1(−2 · 1)= 0.8.

So x(0.1) is approximately 0.8.

15

Page 21: Everything is the Same Modeling Engineered Systems

5 Exponential SolutionsLast time we learned that Euler integration allows one to approximately solve a ordinary differen-tial equation. What do we do if we have an ordinary differential equation that we want to solveexactly? For general f(x) in x = f(x), we cannot expect an exact solution, but for linear, constantcoefficient, first-order ODEs we can.

Having a good guess matters a lot, and for us that guess will always be the exponential solution

x(t) = ehtx0 (5)

where h is an unknown parameter.This says that we expect a solution to an ordinary differential equation to be an exponential

times the initial condition x0—which is x(t) at time t = 0 (which we assume to be the initialtime10). Notice that if h > 0, this solution will blow up and go to infinity if x0 6= 0. If h < 0, thenit will go to zero. This observation is a good way to have some physical intuition about what theexponential function means and if it makes any sense.

What does it mean to “solve” a differential equation, anyhow? We didn’t really get into thisquestion in the last lecture, but it is helpful to think of x as the time derivative

x(t) = f(x(t)) meansd

dtx(t) = f(x(t))

so that you see that we are really saying that x “solves” the differential equation if plugging it intothe left hand side—that is, taking its time derivative—is the same as plugging it into the right handside—that is, evaluating f at x(t) for all time.

Figure 9: Spring-damper system with an external force that is zero.

Example: To see how this works, let’s assume that our spring-damper system has an exponentialsolution and plug into the differential equation to find the value of h. If we plug into to both sides,we get

x = −kbx

⇒ d

dtx(t) = f(x(t))

⇒ d

dtehtx0 = −

k

behtx0

10One can do all of the notation so that the initial time is t0, but it makes it a little annoying to look at and annoyingfor me to write in lectures, so we will assume that t0 = 0. However, if we were not working with constant coefficientODEs, we would have to be more careful about specifying the initial time.

16

Page 22: Everything is the Same Modeling Engineered Systems

Taking the derivative of the exponential drops the h down, and since we know that the exponentialis never zero we can divide by both sides.

hehtx0 = −k

behtx0

⇒ h = −kb

This means that h is equal to −kb

(assuming x0 6= 0)! So we know that the solution is

x(t) = e−kbtx0.

If we now specify that k = 1, b = 1, x = 0.5 then we see that

k = 1 b = 1 x0 = 0.5 ⇒ x(t) = e−t · 0.5

Note that this behavior is somewhat unintuitive. It says that if I extend the spring-damper systemby 0.5 units, then I will see it move forever, which of course a real system will never do. Thisis largely because damping tends to be nonlinear at very low velocity—suggesting we can neverfully believe our analytical models or computational models—but this solution x(t) = e−

kbtx0 will

capture the behavior of many spring-damper systems.

Figure 10: Two simulations at dt = X and dt = Y as well as the analytical solution for x = −xwith an initial condition of 0.5.

We can now compare the results of the analytical solution to the results of Euler integration—an example is in Fig. 10. At large dt the approximation to the solution is not very close to theanalytical solution but at small dt it is. This means that you have to use your judgement whenchoosing the dt for your simulation.

Today we learned about exponential solutions to ordinary differential equations. Exponentialsolutions are valid for any linear, constant coefficient first-order differential equation where theexternal force is zero, and we will be talking about them occassionally for the rest of the class.

17

Page 23: Everything is the Same Modeling Engineered Systems

For now, keep in mind that an analytic solution exists for many engineered systems that you willencounter and certainly all the ones we will see during the rest of this class.Example: Let’s find the analytic solution of x = 2x with x(0) = 1, and use it to find the exactvalue of x(0.1). We know the solution is of the form of an exponential ertA, where r and A areconstants. Plugging into the differential equation, we get rertA = 2ertA, which implies that r = 2.Setting t = 0 implies that A = 1. So the solution is x(t) = e2t, which implies that x(0.1) = e0.2.

18

Page 24: Everything is the Same Modeling Engineered Systems

What Does The Word Linear Mean?The word “linear” in “linear, constant coefficient, first-order ODEs” can cause a lot of confusion.In many respects, that is because the word “linear” has two primary uses. One use is descriptive—so that when we see an equation of a particular form, we know what to call it. The other use isbased on properties that we might want. I want to describe what I mean in a context that is a bitsimpler than ODEs, and instead focus on algebraic equations. I will come back to ODEs with asimilar discussion of linearity after the next section on superposition.

Look, for a moment, at the following equations.

y =1

2x

y =1

2x+ 1

Here both x and y are variables, and the graph relating them is shown in this picture.

In both cases y is related to x through a constant of proportionality 12. Now, let’s assume that

we have four choices of x values we are interested in—x1, x2, x3, and x4. Each of these maps to ay value—y1, y2, y3, and y4. Lastly, assume that we know that x3 = 2x1 and x4 = x1 + x2. Whatmight we hope? It would be helpful if knowing y1 and y2 helped predict y3 and y4. Specifically,we might hope that y3 = 2y1 and y4 = y1+ y2. In general, this relationship does not hold, even fory = 1

2x+ 1.

An equation with a mapping between y and x that satisfies both the scaling property11 and theadditive property12 is linear. It happens that all equations of the form y = ax are linear in thissense, but other types of relationships are linear as well. However, relationships like y = 1

2x + 1

are not linear, because the 1 added to the equation makes the properties disappear (y = 12x + 1 is

called linear affine).All of this may sound very academic when talking about a relationship between y and x, but if y

and x are vectors, or curves, or—as in the next section—solutions to ODEs, suddenly scaling andadditive properties can matter a lot, both in terms of conceptually understanding and concretelydoing calculations.

11Formally, that if y = g(x), then ay = g(ax).12Formally, that if y1 = g(x1) and y2 = g(x2), then y1 + y2 = g(x1 + x2).

19

Page 25: Everything is the Same Modeling Engineered Systems

6 SuperpositionWhy do we bother being so careful to design systems to have constitutive laws that are linear?It is a reasonable question, particularly considering that we just learned in Lecture 4 that Eulerintegration allows us to approximate solutions to ordinary differential equations whether they arelinear or not—as long as dt is small enough. Maybe having an exact, analytical solution isn’t worththe trouble! The real value of linear constitutive laws comes from the fact that we get to use whatis called the principle of superposition.

The key thing about linear constitutive laws and the resulting linear ODEs is that if I giveyou two solutions—regardless of how I obtained them—you can get a whole bunch of potentialsolutions from those two. We know that Euler integration requires having an intitial condition toget started, but superposition allows us to solve for everything we need without worrying about theinitial condition until the end, after we have done most of the calculations. This ends up being areally powerful idea.Example: Starting with our favorite example, the spring-damper system, with k = 2 and b = 1.

x = −kbx x1(0) = 1 x2(0) = −2 k = 2 b = 1

let’s say we have two solutions, x1(t) and x2(t). How can we even have two solutions? Well,every initial condition gives us a different time evolution, so every initial conditions correspondsto a different solution to the differential equation. In this case, we might have x1(0) = 1 andx2(0) = −2. From this, using the fact that the solution for each initial condition is exponential, wecan conclude that

x1(t) = e−2t x2(t) = −2e−2t

x1 is an exponential and x2 is an exponential.13

Now let’s assume that α and β are constant numbers—that is, they are numbers like 1 or 1/2or π or, later, we will even allow these numbers to be imaginary numbers.14 Then the principle ofsuperposition tells us that if α and β are numbers, and if x1(t) and x2(t) are both solutions to thesame linear, constant coefficient, first order ordinary differential equation, then:

1. x(t) = x1(t) + x2(t) is a solution as well;

2. x(t) = αx1(t) is a solution for any choice of number α;

3. x(t) = βx2(t) is a solution for any choice of number β;

4. and that if we combine these into a single expression, that

x(t) = αx1(t) + βx2(t) (6)

is a solution.13Note that in this expression of the solutions, x2(t) is multiplied by −2 because the initial condition for x2 is −2.14Remember from the calculus review that the imaginary numbers involve j =

√−1.

20

Page 26: Everything is the Same Modeling Engineered Systems

That means that if I give you two solutions, you can generate a whole bunch of other solutionswith them! Let’s say that x = ax and we had two solutions x1(t) and x2(t) and defined x(t) =αx1(t) + βx2(t). Then

d

dtx(t) =

d

dt(αx1(t) + βx2(t)) = αx1 + βx2 = αax1 + βax2 = a(x(t))

so x(t) really is a solution to the differential equation.Let’s look at our specific example. We have the two solutions I just mentioned

x1(t) = e−2t x2(t) = −2e−2t

and if we add them together we get the sum of the two solutions. Now let’s check that these twosolutions added together really are a solution to the differential equation. We do this by taking theresulting sum

x(t) = x1(t) + x2(t) = e−2t +(−2e−2t

)and substituting it into the differential equation

d

dtx(t) =

d

dt

(e−2t − 2e−2t

)= −2e−2t + 4e−2t = −2

(e−2t − 2e−2t

)= −k

bx(t)

and we find that we still get that ddt

of x(t) is equal to −kb

times x(t), so x(t) = x1 + x2 is indeeda solution to the differential equation. We can do the same thing with x(t) = αx1(t) where α = 3and find that this also solves the differential equation. That is,

x(t) = αx1(t)⇒ x(t) = 3e−2t

and we can take this and substitute it into the differential equation

d

dtx(t) =

d

dt

(3e−2t

)= −6e−2t = −2(3e−2t) = −2x(t) = −k

bx(t).

What should you remember from today? Remember that when you have a linear constitutivelaw, and the resulting linear, constant coefficient ordinary differential equation, you get to usesolutions you have already computed to find new solutions. Why would you need to do this? Youmight have already calculated the solution for one initial condition, and then someone tells youthat the original initial condition was wrong and you need to do it again for a new initial condition.If you can write the new initial condition as a function of adding and scaling initial conditions forwhich you have already computed solutions, superposition allows you to use those solutions for thenew initial condition. For a simple system, you would probably just calculate the whole solutionagain, but as systems get more complex—if there were thousands or millions of spring-dampercomponents all connected together—recomputing the solution might take a very long time.

21

Page 27: Everything is the Same Modeling Engineered Systems

What Does The Word Linear Mean for Ordinary DifferentialEquations?At the end of Lecture 5, I talked about linearity in the context of algebraic equations. What shouldlinearity mean in the context of ordinary differential equations? Just as in the case of algebraicequations, we want the word linear to imply a property rather than only be used a description ofthe form of the equation.

Look, for a moment, at the following equations.

x =1

2x

x =1

2x+ 1

Here x(t) is a solution to the ODE. In both cases x is related to x through a constant of proportion-ality 1

2. Now, let’s assume that for a particular initial condition x1 we have solved this ODE and

obtained x1(t) that has x1(0) = x1. Moreover, let’s assume we have done so for an initial conditionx2 as well. What if we now have a new initial condition x3 = 2x1 or x4 = x1 + x2? We would likethe resulting solution to the ODE to be x3(t) = 2x1(t) and x4(t) = x1(t) + x2(t). This linearityproperty in the context of ODEs is exactly the property of superposition. Moreover, notice that itdoes not hold for x = 1

2x+1, so in general we do not call x = 1

2x+1 a linear differential equation.

Instead, we call it a linear affine ordinary differential equation, and we will see later in the classhow to work with equations like these.

22

Page 28: Everything is the Same Modeling Engineered Systems

7 Newton’s Laws with MassPreviously, we learned about Newton’s laws in Lecture 3, but in the absence of mass. Today weare going to look at what happens when the mass at a point is nonzero. That is, we are going tolook at ∑

F = ma

wherem 6= 0. Remember that here F are the forces acting on a point, always defined to be positiveif the force would cause a positive acceleration. The variable a is the acceleration—the second timederivative of the position of the point, defined to be positive if the acceleration is to the right. Theacceleration a is also the first time derivative of the velocity vm of the point. Lastly, remember thatvm of the mass is always assumed to be measured relative to what is called an inertial referenceframe. In the case of the spring-mass-damper system the inertial reference frame is the wall—thatis, we measure velocities with respect to the wall.

Figure 11: A system with a spring and damper in parallel, attached to a mass with an externalforce.

This diagram could represent a lot of things, like the shocks on a car or bicycle, or even theslinky I showed in lecture, where the bottom of the slinky is connected together so that we thinkof the bottom of the slinky as having a fixed mass. If I hold the slinky horizontally, then the forcedue to gravity has no effect on the linear motion, but if I hold it vertically, then gravity introducesan external force on the system. The slinky is a good example to keep in mind because the modelwe choose to use really depends on what behavior we are trying to model; if the slinky oscillateswith only one frequency of oscillation, the model that we get from just a spring, damper, and masswill do a good job. If, however, we create extra oscillations, like I did in lecture, we might havemore trouble with such a simple model. Hence, your engineering judgment matters—you cannotjust blindly write down a model and expect it to be valid.

Let’s look at a model of a mass with a spring and damper. The sum of the forces are equal tothe mass times acceleration.

Fext − Fs − Fd = ma = mxs

We already know from Lecture 3 that vd is equal to xs, giving

Fext − kxs − b vd︸︷︷︸xs

= ma = mxs

so if we solve for xs we get

xs = −k

mxs −

b

mxs +

Fextm

23

Page 29: Everything is the Same Modeling Engineered Systems

which is a linear, constant coefficient, second-order ordinary differential equation in the positionof the spring xs. We know that we need a first-order ODE if we are going to use Euler integrationfrom Lecture 4 and the analytic solutions from Lecture 5, so we need to convert this system to afirst-order ODE.

To do so, it is helpful to note that the equation

xs = f(xs, xs)

can be rewritten asd

dt(xs) = f(xs, xs)

where now we have written ddt

in two different ways. The nice thing is that we can recognize xs asvm, so we are going to relabel xs as v.

Now we have the differential equation

v = f(xs, v) = −k

mxs −

b

mv +

Fextm

xs = v

where xs = v comes from the relabeling we just did. This exercise of converting from a second-order differential equation to a first-order differential equation is something you will do a lot as anengineer. It is worth practicing.

What should you remember from today. First, that Newton’s equations allow you to incorporatemass into a linear constant coefficient ordinary differential equation; second, hopefully the slinkyconvinced you that when you have mass you should expect the possibility of oscillation; and third,that ODEs have to be converted into first-order differential equations, which will mean increasingthe number of differential equations.Example: Consider the following mechanical diagram.

What does force balance say about this system? It says that the sum of the forces is equal tomass times acceleration, so we get

F3 + F4 − F1 − F2 = mvm

where vm is the velocity of the mass. Note the negative signs in front of F1 and F2, both of whichare defined to be positive whenever the spring is extension or the damper is extending; in the forcebalance equation these forces must have a negative sign in front of them since the force acting onthe mass is to the left whenever F1 and F2 are positive.

24

Page 30: Everything is the Same Modeling Engineered Systems

8 Newton’s Laws with Several MassesLast time we learned that Newton’s laws with mass lead to second-order ODEs that we convertinto first-order ODEs with multiple equations. What if we want to go backwards from a first-orderODE with multiple equations to a second-order ODE? Using the same example as before, we have

Figure 12: A system with a spring and damper in parallel, attached to a mass with an externalforce.

equations of the form

x = v

v = f(x, v)

and since we can take the top equation and take the time derivative of both sides, we know that

x = v ⇒ x = v ⇒ x = f(x, x)

which implies that x = f(x, x), which is the equation we started with before. This procedure ofgoing back and forth between first-order and second-order ODEs is confusing primarily because itis so simple—it is just a relabeling trick that you have to get used to.

As an example, consider

y = z

z = ay + bz.

The same trick as before gives us

y = z ⇒ y = z ⇒ y = ay + by.

Last time I talked about Newton’s Laws with mass, but how do we model several masses? Forinstance, let’s say that we have a slinky, but with both the end and the middle bound so that it islike two masses—this is what I showed you in the lecture. Let’s say we have a two mass and threespring system like the one seen in Fig. 13. Newton’s laws tell us that the sum of forces at eachmass must be equal to the mass times the acceleration of each mass, where acceleration is definedto be positive if the mass is moving to the right and the velocity of each mass is measured relativeto the left wall. ∑

F = m2a2∑

F = m4a4

Also note that the springs positions are not independent of each other. If the distance between thewalls is L, then the sum of the spring positions needs to be equal to L.

x1 + x3 + x5 = L

25

Page 31: Everything is the Same Modeling Engineered Systems

Figure 13: Two masses and three springs

Now, I’m going to choose the states of my ODE to be

states: x1, v2, x3, and v4.

You could make other choices, like replacing x3 with x5.Note that

a2 = v2

a4 = v4

x5 = L− x1 − x3v4 = x1 + x3 ⇒ x3 = v4 − v2

Note that the acceleration of each mass is equal to the time derivative of the velocity of that mass,and that because v4 is measured relative to the left wall, it is equal to the sum of the x1 and x3,which implies that x3 = v4 − v2. Plugging in constitutive laws for Newton’s equations gives us

m2v2 = −k1x1 + k3x3

m4v4 = −k3x3 + k5x5

⇒ m4v4 = −k3x3 + k5(L− x1 − x3)

To make things simpler, let’s set all the spring constants to be the same k and set the masses equalto 1. If we rearrange this we get a linear, constant coefficient, first-order differential equation withfour equations—one for each state!

x1 = v2

v2 = −kx1 + kx3

x3 = v4 − v2v4 = −kx3 + k(L− x1 − x3)

That is, we have an equation that is of the form ddt(something) = f(something)—just like

I mentioned in the first lecture on Newton’s laws–but the something has four variables instead ofjust one. If we made a mistake and made a bad choice of state, we would not be able to get anODE with these four variables as the state. As you might guess, if we had lots of masses we wouldend up with lots of equations and lots of states, which might make keeping track of things a bitunmanageable—we are going to address this in Lectures 11 and 12.

26

Page 32: Everything is the Same Modeling Engineered Systems

Things to remember from today: Newton’s laws will give you ODEs describing the time evo-lution of a system that has multiple masses, but the number of first-order differential equations youget increases (or goes up) as the number of masses increases. Typically, you should expect to havetwo equations for every mass. Lastly, note that in the equation for the masses, the total distancebetween walls, L, is playing the role of an external force in the equation, and this is quite commonany time there is a constraint between variables—in this case x1, x3, and x5.

27

Page 33: Everything is the Same Modeling Engineered Systems

9 Imaginary Numbers and Euler’s FormulaLast time we learned that Newton’s laws give us linear, constant-coefficient, first-order ODEsfor systems with masses. We know that 1) we want to model mechanical systems using masses,springs, and dampers; and 2) real systems, like the slinky I showed in lecture, oscillate. However,I told you in Lecture 5 that we would use exponential solutions for linear, constant-coefficient,first-order ODEs, so that should be true here as well. But how do we get an exponential functionlike eht to give us cos() and sin()? The answer is that we use the unfortunately namedimaginary numbers—please don’t get derailed by the name! The idea is really simple and magicaland very, very cool, and it all hinges on the Taylor series—one of the few things from calculus Isaid you should remember, and this is the moment you need it. We are going to Taylor expand eht

and sin(ωt) and cos(ωt).eht = 1 +ht + 1

2!h2t2 + 1

3!h3t3 + 1

4!h4t4 + 1

5!h5t5 + 1

6!h6t6 · · ·

sin(ωt) = +ωt − 13!ω3t3 + 1

5!ω5t5 · · ·

cos(ωt) = 1 − 12!ω2t2 + 1

4!ω4t4 − 1

6!ω6t6 · · ·

The thing to note here is that the sin(ωt) term has every other term—every odd power of t— ofthe exponential, and the cos(ωt) terms have the left over terms—all the even powers of t. Moreover,the signs change—sometimes they are plus signs and sometimes they are negative signs. If youthink of this as being a requirement on h, it would imply that

h0 = 1, h1 = ω, h2 = −ω2, h3 = −ω3, h4 = ω4 · · · ,

while keeping even powers separate from odd powers.What function of ω could force these relationships to hold? Amazingly, the choice of

h = jω with j =√−1

accomplishes all of this! Plug h = jω into the exponential and see what happens. We get theexponential with powers of j, ω, and t in the Taylor expansion.

ejωt = 1 + jωt+1

2!(jω)2t2 +

1

3!(jω)3t3 +

1

4!(jω)4t4 +

1

5!(jω)5t5 +

1

6!(jω)6t6 · · ·

We know that j =√−1, so j2 = −1, j3 = −j, and j4 = 1. This gives us a bunch of terms that

alternate sign and half of them include a j.

ejωt = 1 + jωt+1

2!(−1)ω2t2 +

1

3!(−j)ω3t3 +

1

4!(1)ω4t4 +

1

5!(j)ω5t5 +

1

6!(−1)ω6t6 · · ·

If we split these into the terms that have j and the terms that don’t have j,

ejωt =

(1− 1

2!ω2t2 +

1

4!ω4t4 − 1

6!ω6t6 + · · ·

)+ j

(ωt− 1

3!ω3t3 +

1

5!ω5t5 + · · ·

)we get exactly the Taylor expansion of cos() and sin().

ejωt = cos(ωt) + j sin(ωt)

28

Page 34: Everything is the Same Modeling Engineered Systems

This formula ejωt = cos(ωt) + j sin(ωt) is called Euler’s formula and you will use it many timeswhile taking this course.

Now we get to use Euler’s formula when we say that an ODE has an exponential solution.For instance, looking at a spring-mass system, we get x = − k

mx. If we plug in an exponential

x(t) = ehtw—where w is some constant—we see that h2ehtw = − kmehtw, so h2 = − k

mwhich

implies that

h = ±√k

mj.

This means thatx(t) = ehtw = e±j

√kmtw.

Hence, by Euler’s Formula, we know that

x(t) = (cos(

√k

mt)± j sin(

√k

mt))w.

This means we have two possible equations—one with a positive sign and one with a negative sign.Also, this equation still involves j, which we would like to get rid of because x and v are the statevariables, and x and v do not involve imaginary numbers.

Now remember superposition from Lecture 6. If I have two solutions, I can add them togetherand scale them. So

x(t) = (cos(

√k

mt) + j sin(

√k

mt))w

is one solution and

x(t) = (cos(

√k

mt)− j sin(

√k

mt))w

is another solution. If I multiply both by 1/2 and add them, I just get cos(√

kmt)w. If I multiply

both by −1/2j and subtract them, I get sin(√

kmt)w. So the exponential solution gives me two

types of solution—a cos term and a sin term, just as we hoped! Moreover, any solution can bewritten as a constant times the cos term plus a constant times the sin term—these constants willdepend on the initial conditions of the states x(t) and v(t) at t = 0. You will learn how to useinitial conditions to find these constants in the Exercises following this lecture.

The main thing to remember from today is that the imaginary number j comes from wantingthe exponential function to represent oscillation. With it, we can assume an exponential functionis the solution to a linear, constant-coefficient ODE and we can plug it in to the ODE to obtaina solution. It is also worth noting that in this class, and in the “systems” view of an engineeredsystem, numbers rarely count things. Instead, they are more like adjectives, in that they are usedto describe things.

29

Page 35: Everything is the Same Modeling Engineered Systems

10 Imaginary Numbers ContinuedLast time we talked about imaginary numbers and using imaginary numbers as a way of encodingoscillation into the exponential solution of an ordinary differential equation. But most systemsdo not just oscillate forever—they typically experience decaying oscillation due to damping. Forinstance, the slinky I showed in lecture oscillates in gravity. How should we adapt the exponentialsolution so that a spring-mass-damper system like this one can decay.

Let’s look at our model of the spring-mass-damper again. Again, we have the wall on the left,a spring, a damper, and a mass at the end, as seen in Fig.14.

Figure 14: Spring-Mass-Damper System

The equations of motion are

x = − kmx− b

mx

and we assume that the solution is of the form of the exponential function

x(t) = ehtw,

where w is just a constant.If we plug this solution into the differential equation above—keeping it in its second-order

form with two time derivatives of x(t)—we get

h2ehtw = − kmehtw − b

mhehtw

and we can factor out the eht term as well as the constant w.(h2 +

b

mh+

k

m

)ehtw = 0

If w 6= 0—and we know that the exponential is always nonzero—then we know that h2 + bmh+ k

m

must be equal to zero.

h2 +b

mh+

k

m= 0

Hopefully, you recognize that this is in quadratic form, so we can use the the quadratic formulathat says that if we have three coefficients α, β, and γ, then

αh2 + βh+ γ = 0

implies that

h =−β ±

√β2 − 4αγ

2α.

30

Page 36: Everything is the Same Modeling Engineered Systems

In our case, the quadratic formula tells us that

h =− bm±√

b2

m2 − 4 km

2.

This means that the h in the exponential solution is a solution to the quadratic formula. Notethat the plus or minus sign means that there will be two solutions—one that corresponds to theplus sign and one that corresponds to the minus sign. If b = 0, (that is, there is no damper in thesystem) this simplifies to something we have seen before.

b = 0 ⇒ h = ±√k

mj.

This is the same solution that we found last time, so we know that it will give us sin() and cos()terms and that the system will oscillate forever. However, if b 6= 0, then something else can happen.Let’s set k = 1 and m = 1. Then we get

h =−b±

√b2 − 4

2.

If b ≥ 2, then h has no imaginary values because the term in the square root is positive. When hdoes not have an imaginary number, the system is called overdamped because it will not experienceany oscillations at all. If b < 2, then h will have imaginary values because the term in the squareroot is negative. When h does have an imaginary component, the system is called underdamped.For instance, if b = 3, that implies that

h =−3±

√5

2,

so I get two values, neither of which involve the imaginary number j. This will give me an expo-nential solution of the form

x1(t) = e−3+

√5

2tw and x2(t) = e

−3−√5

2tw

depending on the plus or minus. If I instead choose b = 1,

b = 1 ⇒ h =−1±

√−3

2=−1±

√3j

2,

I get −3 in the square root, so I get the imaginary number j showing up in h. This means that I gettwo terms in the exponential solution—a term that includes j and a term that does not.

x1(t) = e−1+

√3j

2tw and x2(t) = e

−1−√3j

2tw

Now, remember from calculus thater+s = eres,

so we can find out that

er+s = eres ⇒ e−1+

√3j

2t = e

−12te√3j2t = e

−12t

(cos

(√3

2t

)+ j sin

(√3

2t

))

31

Page 37: Everything is the Same Modeling Engineered Systems

so I can separate the terms that involve the imaginary number j from the terms that do not. Forinstance, I can take e(−

12+√3

2j)t and separate it into e−

12te√3

2jt, and we know that the right hand term

is equal to cos√32+ sin

√32j.

Using the same trick as last time to get rid of j, we can conclude that solutions are of the formof an exponential times cos() and sin() terms.

To visualize this, a plot of e−12t cos (

√32t)w (where I have set w = 1) might look like a com-

bination of the exponential plot and the cos() plot. Together, they would look like a decayingoscillation.

+

=

Figure 15: An exponential times a cosine is a decaying cosine curve.

What should you remember from today? Remember that exponential solutions can both repre-sent oscillation and decaying oscillation.Example: Consider again the following mechanical diagram.

32

Page 38: Everything is the Same Modeling Engineered Systems

Figure 16: One mass with four elements attached to it

If k = 1 and m = 2, for which values of b will this system have oscillations (assuming thesystem does not start in steady-state)? First, we need to find a differential equation.

As before, force balance gives us

F3 + F4 − F1 − F2 = mvm

where vm is the velocity of the mass. Choosing states x1 and vm, we get

x1 = vm

vm = − kmx1 −

b

mv2 +

k

mx2 +

b

mv4

= − kmx1 −

b

mvm +

k

m(−x1) +

b

m(−vm)

= −2k

mx1 −

2b

mvm.

Hence, we know that x1 + 2bmx1 +

2kmx1 = 0. Choosing k = 1 and m = 2, and plugging in

x(t) = ertA as a solution, we get

(r2 + br + 1)ertA = 0.

Hence, from the quadratic formla,

r =−b±

√b2 − 4

2.

From this we can conclude that oscillations occur whenever 0 < b < 2.

33

Page 39: Everything is the Same Modeling Engineered Systems

11 Vector and Matrix RepresentationsSo far, we have only worked with very, very simple systems. But you can imagine that if we havelots of springs, dampers, and masses all connected together—like the slinky I used in the classlecture where I connected several sections together—then we have an ordinary differential equationthat has a separate equation for every state. Here is where things might get a bit complicated; and,therefore vector and matrix representations become really useful. You should think of these aslargely being useful notation; that is, vector representations and matrix representations of ordinarydifferential equations primarily serve as a way of organizing information in a nice, convenient waythat helps with computations.

Let’s say we have a linear, constant coefficient, first-order differential equation that has statesx, y, and z.

x = x +2y +3z

y = y +4z

z = x +z

I have spaced these numbers and letters in a way that will help us in a moment. You can imaginethat if I had fifty or a hundred or a thousand states here, this could become very challenging tomanage. I’m going to group the states into a single vector x

yz

and by definition the time derivative of this vector of states is equal to the vector of time derivativesof the states.

d

dt

xyz

=

xyz

So far, I have not done anything very interesting—I’m just putting variables into a list. Now comesthe useful part. I’m going to define a matrix to be an array of numbers, like

A =

1 2 34 5 67 8 9

.This is a matrix that has three rows and three columns, with a total of nine numbers.

Our goal is to define some notion of multiplication between the matrix A and the vector ofstates so that if I take

A ·

xyz

I will get the right hand side of the differential equation. In fact, if I just relabel the state vector as

w =

xyz

, I can write Aw to represent the multiplication.

34

Page 40: Everything is the Same Modeling Engineered Systems

The right way to define multiplication between A and w is to take elements of the rows of Aand multiply them by their corresponding elements of the state vector and sum them together. Forinstance, if I take the A matrix I just defined and multiply A and w, I get

Aw =

1 2 34 5 67 8 9

xyz

=

1 · x+ 2 · y + 3 · z4 · x+ 5 · y + 6 · z7 · x+ 8 · y + 9 · z

Note that the result is a vector again, so multiplying a matrix times a vector gives a vector. Now,let’s go back to the differential equation and see how we could choose different values in the com-ponents of A so that we get the right hand side of the differential equation we started with. Theidea is to choose the elements of A so that when you multiply A and the state vector you get theright hand side of the differential equation.

If you look at how I wrote the differential equation in the first place, it is reasonably easy to dothis. In particular, if I choose15

A =

1 2 30 1 41 0 1

⇒ Aw =

1 2 30 1 41 0 1

xyz

=

1 · x+ 2 · y + 3 · z0 · x+ 1 · y + 4 · z1 · x+ 0 · y + 1 · z

I get Aw equal to a vector that is exactly the right hand side of the differential equation.

This has important consequences, because now I can rewrite the differential equation as

w = Aw.

This is exactly the same equation as the one I started with, but with a different notation being used.Now, how is this useful? Let’s think back to Lecture 4. I’d like to use this vector and matrix

notation in my Euler integration code. The initial condition for the differential equation needs toinclude initial conditions of all the states

w0 =

x0y0z0

and Euler integration—expressed in terms of vectors and matrices—will look like

w(t+ dt) = w(t) + dtAw(t).

The great thing about this formula is that once you have the matrix A, the code for your Eulerintegration will always look the same! As an example, let’s look at the vector and matrix notationfor the spring-mass system. We know from Lecture 7 that we get a second-order differentialequation

x = − kmx

15Choosing the elements of A comes down to just reading off the coefficients of x, y, and z in each element of thevector, but this often is not obvious at first.

35

Page 41: Everything is the Same Modeling Engineered Systems

Figure 17: A spring-mass system

and if we rewrite that equation in first order form we get two first-order differential equations witha state of position x and velocity v.

x = v

v = − kmx

If we set w =

[xv

], and choose A =

[0 1− km

0

], then Aw gives us the right hand side of the

differential equation.Let’s say that x0 = 0.5 and v0 = 0 and we want to use this vector notation in Euler integration

with a time step of dt = 0.1. We set w0 to be the vector of intial conditions of the two states andthen

w0 =

[x0v0

]⇒ w(0.1) ≈

[0.50

]+ 0.1︸︷︷︸

dt

[0 1− km

0

] [0.50

]=

[0.5− k

20m

]If I multiply this out, I get an approximation of w(0.1). Just as in Lecture 4, we can repeat thisprocess as many times as we like to get an approximate solution of the differential equation at anytime.

What should you remember from today? Vector and Matrix representations are really, reallyuseful for organizing information. The more complex a system is, the more useful this notationbecomes. If you find yourself dealing with really complicated systems a lot—and as engineers weuse them all the time—you probably will eventually want to take a class that focuses on them. Butfor now, just think of them as a notational convenience that simplifies your life.Example: Consider (again!) the mechanical diagram.

Figure 18: One mass with four elements attached to it

36

Page 42: Everything is the Same Modeling Engineered Systems

We already saw that if we choose states x1 and vm, we get

x1 = vm

vm = − kmx1 −

b

mv2 +

k

mx2 +

b

mv4

= − kmx1 −

b

mvm +

k

m(−x1) +

b

m(−vm)

= −2k

mx1 −

2b

mvm.

How can we write this as a vector-valued differential equation? Let’s choose the state vector x to

be x =

[x1vm

]. Then the choice of

A =

[0 1−2k

m−2bm

]makes x = Ax equivalent to the ODE above because

x = Ax =

[0 1−2k

m−2bm

] [x1vm

]=

[vm

−2kmx1 − 2b

mvm

].

37

Page 43: Everything is the Same Modeling Engineered Systems

12 Vector Solutions to Ordinary Differential EquationsLast time we learned that vector and matrix representations can make your life easier, specificallywhen you implement Euler integration for a complicated system involving many states. But howdo we use vector and matrix representations to find analytic solutions?

Let’s say we have a spring-mass-damper system like the one with three masses in lecture that Icreated by portions of the slinky together.

How many states would we expect? We should have six states total—three for the positionsof each spring and three for the velocities of each mass. This means that the vector and matrixrepresentation would include a state vector that has six components—the six states—and a matrixthat has six rows and six columns. What type of solution to the differential equation w = Aw dowe expect? Hopefully, you are expecting an exponential soluton!

w(t) = ehtw0

Keep in mind that this exponential solution is a vector because w0 is a vector. However, theexponential term itself is still just a number for any given t. If I plug this exponential into w = Aw,I get

w = Aw ⇒ d

dt

(ehtw0

)= Aehtw0

If I then differentiate, I gethehtw0 = Aehtw0

Note that h is a number, eht is a number, w0 is a vector, A is a matrix, eht is again a number, andw0 is again a vector.

h︸︷︷︸number

eht︸︷︷︸number

w0︸︷︷︸vector

= A︸︷︷︸matrix

eht︸︷︷︸number

w0︸︷︷︸vector

If I divide both sides by the exponential term (which is nonzero, so I am allowed to do so), I seethat

hw0 = Aw0.

This is a special situation where a matrixAmultiplying the vectorw0 is the same as just multiplyingthat vector by h! Such a vector is called an eigenvector of A and h is called an eigenvalue of A. Ifthere are n states there will always be n eigenvector-eigenvalue pairs.

The nice thing about this is that you can use MATLAB or Python to calculate eigenvector-eigenvalue pairs easily!

Let’s go back to our spring-mass-damper system and assume that the damping is reasonably

Figure 19: spring mass damper system

38

Page 44: Everything is the Same Modeling Engineered Systems

high, giving us an A matrix of

A =

[0 1−1 −3

]To use an exponential solution, we need to solve Aw0 = hw0, so I use MATLAB to compute

the eigenvectors and eigenvalues. (See the lecture video for an example of this.) MATLAB returnsan eigenvector-eigenvalue pair.

w0,1 =

[−0.41

]h = −2.6

w0,2 =

[−2.61

]h = −0.4

(Note that I have scaled these to make the second component equal to one in each case. I can dothis because any scalar multiple of an eigenvector is also an eigenvector.)

What does this tell us? It says that if

w0,1 =

[−0.41

]⇒ w(t) = e−2.6t

[−0.41

]and if

w0,2 =

[−2.61

]⇒ w(t) = e−0.4t

[−2.61

]Moreover, if w0 is three times one of these vectors, then I would just multiply that exponential

solution by three because of superposition.Lastly, if

w0 =

[−32

],

that is, w0 is the sum of the two eigenvectors—then the solution would be the sum of the twoexponential solutions!

w0 =

[−32

]= w0,1 + w0,2 ⇒ w(t) = e−2.6t

[−0.41

]+ e−0.4t

[−2.61

]This example suggests that we should be able to compute any solution of a differential equationfrom the exponential solutions for each eigenvector-eigenvalue pair, which is in fact true!

What should you remember from today? Remember that vector and matrix representationsare useful for computing analytical solutions—as well as Euler integration—for complex systemswith many states. And remember that eigenvectors and eigenvalues provide the means by whichwe compute those solutions as exponential solutions.

39

Page 45: Everything is the Same Modeling Engineered Systems

Superposition in Vector Linear ODEs with Complex EigenvaluesOn the previous page, and in the lecture video, I talk about superposition of solutions to ODEswhen the eigenvalues are real-valued, but I don’t say anything about what happens when the eigen-values are complex. The amazing thing is that nothing changes! Let me do an example to convinceyou of why this makes sense.

Let’s take a spring-mass system as an example with k = m = 1. We know that x = −x andthat in first-order form this is x = v, v = −x. So we can write it as

w = Aw, where A =

[0 1−1 0

].

The eigenvalues/eigenvector pairs are

r1 = j, w1 =

[−j1

]and r2 = −j, w2 =

[j1

].

We know that we therefore get two solutions:

x1(t) = ejtw1 and x2(t) = e−jtw2.

Moreover, we also know from Euler’s formula that

ejt = cos(t) + j sin(t) and e−jt = cos(t)− j sin(t).

How can we now construct real-valued solutions from x1(t) and x2(t)? Specifically, how can weuse superposition to construct real-valued solutions from x1(t) and x2(t)? By superposition, wecan add and scale x1(t) and x2(t), so consider the following quantities:

−j2(x1(t)− x2(t)) and

1

2(x1(t) + x2(t)).

The expression −j2(x1(t)−x2(t)) simplifies to the vector

[− cos(t)sin(t)

]while the expression 1

2(x1(t)+

x2(t)) simplifies to[sin(t)cos(t)

]. Both of these are real-valued and—again, by superposition—are

solutions to the ODE. Just as importantly, they are what we should expect from plugging the ex-ponential solution into the second-order system x = −x.

Example: Now assume that w(0) =

[10

]. What is the analytic solution for w(t)? It must be

of the form a1

[− cos(t)sin(t)

]+ a2

[sin(t)cos(t)

], but what are the constants a1 and a2? At t = 0, this

simplifies to a1

[−10

]+ a2

[01

], so

[−a1a2

]=

[10

]. Therefore, we get that a1 = −1 and

a2 = 0 and w(t) =[

cos(t)− sin(t)

].

40

Page 46: Everything is the Same Modeling Engineered Systems

Why We Use Exponential SolutionsA very reasonable question that comes up is what is so special about ert? Why not use a differentnumber than e, like 2.5 or π or something else? And why an exponential? Why not arctan(rt) orsin(rt)? There are a couple of ways of understanding answers to this question, but I want to focuson one in particular—the question of existence and uniqueness of ordinary differential equations.

Mathematicians can tell us that if we have an ordinary differential equation

x = f(x, t) and x(0) = x0,

the solution both exists and is unique if f satisfies certain properties. (Roughly speaking, theseproperties are that the first derivative of f with respect to x and t exists; however, the actualconditions are more general.)

Our case of x = Ax (and later x = Ax+Bu(t)) with x(0) = x0 always satisfy these conditionsbecause ∂

∂xAx = A (so the derivative of f with respect to x exists and is A). We therefore can

conclude both that a solution to x = Ax exists and that it is unique—no other solution can existonce we have found one. Why does this matter?

We know, from the previous sections, that we can construct solutions to x = Axwith x(0) = x0using exponential solutions. In fact, by solving for eigenvalues and eigenvectors, we can get asolution for any choice of initial condition. And once we have that solution, there cannot beanother solution with the same initial condition. So no other choice of function could work, unlessit was the same as an exponential function.

41

Page 47: Everything is the Same Modeling Engineered Systems

13 Chemical Diffusion and Fick’s LawFor the last 12 lectures we have been learning about mechanical systems and how to model me-chanical systems that have linear constitutive laws relating mechanical variables, like position xand velocity v, to forces. Today we are going to start in a new area—chemical systems—wherewe will see that many of the lessons we learned from mechanical systems also apply in chemicaldiffusion.

To understand the question we are going to try and answer, it is helpful to visualize a tank ofwater that has fluid in it. The tank has length, depth, and width, but we are only going to considerthe fluid in one dimension along its length —which we will call x. If there is a chemical in thefluid, the concentration C of that chemical can change as a function of position in the tank; that is,C can depend on x, so we will denote it by C(x). However, the concentration C(x) is assumednot to vary with width or depth. We can plot C(x) over the tank, so that the value of the curverepresents the concentration of the chemical at the position x.

For today, we are going to assume that the chemical is at equilibrium, meaning that the con-centration throughout the tank is allowed to vary as a function of x but is not allowed to vary withtime. Also, we are going to assume that the volume, V , of the tank stays constant—because itmakes things easier.

Note that as a result of the equilibrium assumption, the amount of mass in any given volume Vis constant.16

16(because mtotal =∫VC(x)dxdydz, so if C(x) is not changing with time, mtotal is not changing with time either)

42

Page 48: Everything is the Same Modeling Engineered Systems

Also note that if I draw in two positions x1 and x2, I get that the volume between them isV = Adx, where A is the cross-sectional area in the width-depth plane of the tank and dx is thedifference between x1 and x2.

If there are no reactions taking place and there is no accumulation of the chemical—for in-stance, the chemical is not precipitating—then conservation of mass implies that the amount ofmass going into the volume V must be equal to the mass leaving V . We call the rate at which massenters the volume the flux F , which generally varies with x. We define the flux to be positive ata particular location x1 if there is mass of the chemical diffusing from left to right at x1. Hence,conservation of mass implies that the flux F (x1) of chemical into V at x1 must be the same as theflux F (x2) of chemical out of V at x2; that is, F (x1) = F (x2).

Now we ask the question: What drives the flux—what makes it positive or negative? IfC(x) = constant, then the concentration is the same everywhere and we do not expect any fluxof chemical. To understand this, think about the milk that I poured into my coffee in lecture; ifthe coffee is stirred and the milk is equally dispersed throughout the fluid, it would be very strangeto have the milk start diffusing so that it was at a higher concentration in one place than another.Therefore, we don’t expect F (x) to depend on the absolute amount of chemical present. Said interms we have used before in mechanical systems, we don’t expect a constitutive law of the formF (x) = DC(x)—where D is some constant—because that would imply that positive concentra-tion leads to positive flux of the chemical to the right in the diagram.

Instead, if there is more chemical to the right, we expect the chemical to diffuse to the left.Alternatively, if there is more chemical to the left, we expect the chemical to diffuse to the right.17

The next simplest choice we can make is to propose that at a given x (say, x1 or x2 in the figure),the propensity of the chemical to flow in the positive x direction is a function of the derivativedC(x)dx

of C rather than C(x). And, thinking back to mechanical systems, the simplest choice wecould make is to make the constitutive law be linear with respect to the derivative of C. Lastly,what should the sign of the constant be? Well, if the concentration being higher to the right impliesflux to the left, the constant must have a negative sign.

These observations put together are called Fick’s law, which states that

F (x) = −DdC(x)dx

A

, where D > 0 is the constant of proportionality and A is again the cross sectional area (since fluxis occuring everywhere in that cross sectional area). It is worth noting that just like in mechanicalsystems, this linear relationship only occurs because we have a highly controlled environment—the fluid is still, it is probably very uniform, and the chemical being introduced is also uniform.If this were a natural system, with all the environmental factors that could be introduced, a linearrelationship between flux and the derivative of concentration with respect to position x probablycould not be expected.

What should you remember from today? The key thing is that diffusion is driven by flux, andthe simplest model of flux is called Fick’s Law.

17Keep in mind that despite the fact that there is flux, the concentration is assumed to be in equilibrium—C(x) isstill constant with respect to time even though individual atoms of chemical are diffusing across the boundaries.

43

Page 49: Everything is the Same Modeling Engineered Systems

14 The Diffusion Equation with No AccumulationLast time we discussed Fick’s law and how flux is related to the derivative of concentration withrespect to the position x. We also discussed that this linear constitutive law holds because the fluidis very controlled—this is not a natural diffusion process that might have many nonlinearities andhigher-order effects involved. Instead, it is a model of a very controlled process, and we are goingto explore what that means today in the context of diffusion in equillibrium.

Let’s look at our picture of Fick’s law again.

We have a tank and two positions in that tank x1 and x2 that are very close to each other separatedby a distance dx. By the assumption that the concentration is in equillibrium—thatC(x) is constantwith respect to time—we know that the mass of chemical in the small volume between x1 and x2is constant. How can we use the fact that

F (x1) = F (x2)

and

F (x) = −DdC(x)dx

A?

We just plug in to the equillibrium statement (keeping in mind that this implies mass is conservedin any volume).

F (x1) = F (x2)

⇒ −DdC(x1)dx

A = −DdC(x2)dx

A

⇒ D[dC(x2)

dx− dC(x1)

dx]A = 0

Now, since D > 0 and A > 0, in this case we can divide them out of the equation. Moreover, wecan do something kind of tricky—we can divide both sides by dx (which is also positive). Really,this is a trick! There is no way you could guess to do this, but we will see later in Lecture 16 thatthis step is actually pretty natural.

dC(x2)dx− dC(x1)

dx

dx= 0.

44

Page 50: Everything is the Same Modeling Engineered Systems

If we take the limit as dx→ 0, this becomes the second derivative of C(x) with respect to x.

Equilibrium Diffusion Equation with no accumulation

d2C(x)

dx2= 0

This equation is called the diffusion equation. It is also called the heat equation because heatdistributes through a body in the same way. Now remember, this version of the diffusion equationdoes not include any reaction or accumulation and assumes equilibrium.

Notice that this equation does not depend on C(x), only on derivatives of C(x). Hence, solu-tions are reasonably easy to guess—what curve has zero as its second derivative? Straight lines!

Figure 20: If C(0) = 5 and C(1) = 1, then the diffusion equation with no accumulation inequilibrium predicts that C(x) = 5− 4x.

As an example, if you know that a tank has the concentration regulated to be C(x = 0) = 5and C(x = 1) = 1, then the diffusion equation says that

d2C(x)

dx2= 0,

which implies thatC(x) = ax+ b.

The concentration at x = 0 is 5, so b = 5 and the slope between x = 0 and x = 1 is −4, soa = −4. Hence, the concentration, according to the diffusion equation, will be

C(x) = 5− 4x

for every x. It is worth thinking for a moment about what this means physically. The derivativeof the concentration with respect to x is equal to −4 everywhere. Hence, there is flux into thetank at x = 0 and there is flux out of the tank at x = 1. We don’t know why or how that fluxis occurring, we simply know it is occurring. It is probably occurring because of some form ofengineered process control.

Now think about the small volume we started with. Even though there is flux into the tank andflux out of the tank, the mass of chemical in the small volume really is constant, because the flux of

45

Page 51: Everything is the Same Modeling Engineered Systems

chemical into the small volume is the same as the flux of chemical out of the small volume—thisis because we took the limit as dx→ 0.18

Lastly, what if there were no flux in and no flux out of the tank? Then that would meanthat D must be equal to zero because of Fick’s law, so the the solution would be a flat line—theconcentration would be the same everywhere. This is just what we saw in my coffee in lecture—that at equilibrium the concentration of milk in the coffee is the same everywhere.

What should you remember from today? The diffusion equation in equillibrium with noaccumulation is the second derivative of the concentration with respect to position x. When yousolve the diffusion equation, you get a prediction of the concentration everywhere in the tank byonly knowing what is happening at the edges of the tank. Next time we are going to talk aboutwhat happens when there is accumulation—where for some reason the chemical is accumulatingor being taken out of the fluid everywhere.

18This is true, but for the case where the concentration C(x) is linear taking the limit does not matter.

46

Page 52: Everything is the Same Modeling Engineered Systems

15 The Diffusion Equation with AccumulationLast time we talked about the diffusion equation in equillibrium—which means that the concen-tration does not change with time—and without accumulation. Today we talk about the casewhere there is accumulation. Accumulation can happen because the chemical precipitates outof solution—a simple example is rain falling out of a cloud, which of course decreases the concen-tration of water vapor because it has changed into water droplets. Another example is somethingthat many of us did as children—making candy out of a sugar water solution, where as the sugarcrystalizes the concentration of sugar in the water must go down.

What changes if there is accumulation at rate a? That is, at every point in the fluid the chemicalis either being generated—meaning positive accumulation—or destroyed/precipitated—meaningnegative accumulation—at some rate a. The main thing that changes is the conservation of massstatement.

For the volumeV = Adx,

we have three terms affecting the total mass in the volume. First, the term

Accum = aAdx

is the accumulation term that is either adding or removing the chemical everywhere in that volume.Second, there is the flux F (x1) and lastly there is the flux at F (x2). Now here is the unintuitivepart—we are assuming that the chemical process is in equilibrium, so the the total mass in V stillstays the same. Hence, we we get

Accum+ F (x1) = F (x2).

Now, we proceed just like we did last time by replacing the flux terms with Fick’s law

aAdx−DdC(x1)dx

A = −DdC(x2)dx

A

and then we divide by A and dx, just like we did in Lecture 14.

a−DdC(x1)dx− dC(x2)

dx

dx= 0.

Again, taking the limit as dx→ 0, we get

Equilibrium Diffusion Equation with accumulation

a+Dd2C(x)

dx2= 0

This is called the equilibrium diffusion equation with accumulation. Note that this implies anew type of solution, generally not a line.

If a is constant everywhere in the fluid, what curve C(x) has a second derivative that is con-stant? A parabola! Think for a moment about what this means. The equation says that the parabola

47

Page 53: Everything is the Same Modeling Engineered Systems

will be concave down if a is positive, and concave up if a is negative. This makes sense becausethe only way that total mass can stay constant when a is postive is if the chemical is being removedat the boundaries of the tank. That should mean that in equilibrium the concentration is higher inthe middle than it is near the edges. Indeed, if we assume that C(x = 0) = 1, C(x = 1) = 1,a = 1, and D = 1, we get a parabola for C(x).

Figure 21: If there is constant accumulation throughout the fluid at a rate a, then the resulting C(x)will be a parabola.

What happens when a is not constant as a function of x? This can happen for any number ofreasons—maybe sunlight is heating part of the tank but not the rest of it, so there is a temperaturegradient in the fluid causing more accumulation in hotter places. Then we have

a(x) +Dd2C(x)

dx2= 0.

If, for instance, a = kx, then the solution would be cubic in x. You will look at an example of thisin the homework.

Lastly, what happens if a is allowed to depend on C(x) rather than x? This might happen whenthe ability to accumulate a chemical is dependent on how much is already there, which is what wemean by a solution becoming saturated. Then we have a diffusion equation of the form:

a(C(x)) +Dd2C(x)

dx2= 0.

If, for instance, a is proportional to C(x) (i.e., a(C(x)) = kC(x)), then we have the equation

Dd2C(x)

dx2+ kC(x) = 0 ⇒ C = − k

DC.

If you rewrite this as DC + kC = 0, you might more easily recognize this as a linear,constant-coefficient second-order differential equation that is exactly the same as the spring-masssystem we have seen before, where the independent variable is now x instead of t. You know thesolution to this from mechanical systems—the solution of this differential equation will involvesin() and cos() terms (that depend on x, not t). You will do an example of this as well in thehomework.

What should you remember from today? Remember that introducing accumulation—whichis often the goal of a chemical engineer—will generally lead to solutions that are not straightlines, but often times you have all the tools you need to solve the differential equation. Next timewe are going to look at what happens when the system is not in equillibrium. Even though that

48

Page 54: Everything is the Same Modeling Engineered Systems

Figure 22: A spring mass system

makes things more complex mathematically, my suspicion is that you will find the predictionsmore intuitive!Examples:

Look at the figures below.

Where is the flux positive? Where is the flux negative? And where is the accumulation positive?Where is accumulation negative? Remember that both the equillibrium diffusion equation and yourphysical intuition should agree.

Something that is easy to forget is that flux does not imply motion of the fluid. One can haveflux into the tank, like the figure on the left, without implying that fluid is moving into the tank.For all the examples that we consider, the amount of fluid is constant, even if there is flux in andout of the tank.

49

Page 55: Everything is the Same Modeling Engineered Systems

16 Time-Varying DiffusionLast time we talked about diffusion processes with accumulation. But everything we have talkedabout up until this point is dependent on the idea that the concentration is in equillibrium. However,most of our experience with diffusion is not in equillibrium—when I drop dye in water I see thatthe concentration of the dye changes as a function of time! This is a great example of wheresynthesis of your Physical Knowledge into Analytical Reasoning and Computational Skills playsa really important role in your engineering judgment, because you simply have to be able to thinkabout what you expect prior to finding a solution.

Today we are going to develop a way of modeling time-varying diffusion. To make the devel-opment as simple as possible, we are going to assume that there is no accumulation, but that theconcentration is allowed to change in time.

Let’s look at our example of a tank with fluid and some chemical in the tank. We still have thesame basic components as before—a very small volume V with flux in and out of the volume.Now, however, we are going to allow the mass in that volume to change as a function of time. Themass in a small volume is the concentration times the volume

C(x)V = C(x)Q0dx

and the only thing that could lead to the mass changing in that volume is if the flux in and the fluxout are not the same. Hence

∂t(C(x)Q0dx︸ ︷︷ ︸

mass

) = F (x1)− F (x2)

= −D∂C(x1)∂x

Q0 − (−D∂C(x2)∂x

)Q0

= D

(∂C(x2)

∂x− ∂C(x1)

∂x

)Q0

where I have used the partial derivative notation for the derivative of C with respect to t and thederivative of C with respect to x.

This equation implies that we can divide byQ0 and divide by dx—recall that we did this beforein Lecture 14, but without any real reason or explanation. Taking the limit as dx→ 0, we get thatthe time derivative of C is equal to D times the second derivative of C with respect to x.

50

Page 56: Everything is the Same Modeling Engineered Systems

Time-Varying Diffusion Equation with no accumulation

∂C(x)

∂t= D

∂2C(x)

∂x2

Note that there are derivatives both with respect to time and with respect to position. Becauseof that, this equation is called a partial differential equation or PDE for short—this is why I usedthe partial derivative notation earlier. PDEs are often very challenging to solve, and in general wecannot expect to have eht, with sin() and cos() terms showing up as solutions. Also, the initialcondition for this problem is a curve rather than a number.

That is, at time t = 0, the concentration might look like

so that there is a lot of chemical in the left and less in the right part of the tank. If there is noflux of chemical into or out of the tank, we might expect as time progresses this nonequillibriuminitial condition to approach a solution whereC(x) is flat and the chemical has diffused everywhereequally.

However, if we make two assumptions, we can make a lot of progress. First, assume thatthat the tank is infinitely wide x ∈ [−∞,∞]—this is reasonable even if the tank is simply verylarge—and secondly assume that the chemical starts out all in one place, perfectly concentrated ata particular position x. These assumptions model the situation where you drop a single drop ofchemical into a very large tank and we are now asking how that single drop will diffuse throughthe tank as a function of time. If I drop just one small drop of milk into my coffee cup, it takes awhile for the walls of the coffee cup to matter in the diffusion of the milk.

It turns out that with these assumptions we again get an analytical solution that is of the formof an exponential.

C(x, t) = Q01√4πDt

e−x24Dt

This equation solves the diffusion equation for any constant Q0, which will depend on how muchchemical there was in the drop.

Some things to note about this equation include that at t = 0 the coefficient of the exponentialterm is infinite—this is why we assume that the chemical is all in one place at time t = 0. Aftertime t = 0, the coefficient multiplying the number goes down and the curve C(x) becomes broaderas the chemical diffuses away from the point it started.

51

Page 57: Everything is the Same Modeling Engineered Systems

How would you verify that C(x, t) solves the differential equation? Plug into the time-varyingdiffusion equation and find out that the time derivative of this equation is equal to D times the sec-ond derivative with respect to the position x. Verifying that this function is a solution is somethingyou will consider more in the Exercises following this lecture.

You might notice that this function is related to the Gaussian distribution

1√2πσ

e−12

(x−µ)2

σ2

where µ is the mean and σ2 is the variance. This will turn out to be useful in the Demonstrationthat we are going to do for chemical diffusion.

Lastly, notice that the time-varying diffusion equation is in fact a linear differential equation.That means that it satisfies the principle of superposition, which means you can take several ofthese exponential curves and add them together in order to construct a more complex solutioninvolving chemical starting out in several positions x in the fluid.

What should you remember from today? You should remember that when a diffusion processis not in equilibrium and there is no accumulation, the time-varying diffusion equation providesus with a way of approximating how the chemical will diffuse over time throughout the fluid.However, this model requires two relatively strong assumptions—not all systems, even engineeringsystems, will satisfy the assumptions we made!

52

Page 58: Everything is the Same Modeling Engineered Systems

17 The Convolution EquationSo far we have talked about mechanical systems and chemical systems, and we have learned thatlinear, constant-coefficient differential equations describe these systems in many settings. In bothcases, and soon in electrical systems, external signals also can affect behavior. In mechanicalsystems this was in the form of a force, while in chemical systems the external signal was in theform of the accumulation.

For instance, the slinky I showed in lecture has a single mass in the middle that has a frequencyof oscillation based purely on the mass, spring constant, and damping constant. However, whenI started to force one end of the slinky, the mass started to move in a way that depended on howI was forcing it. Today we are going to learn about the convolution equation—this provides us anotion of superposition with respect to external signals, like the one I created with my hand for theslinky example.

Let’s assume that we have a single variable x and a linear, constant coefficient ordinary differ-ential equation with A a number, B a number, and u a signal that is forcing the system.

x = Ax+Bu

The solution to this ODE is

x(t) = eAtx0 +

∫ t

0

eA(t−τ)Bu(τ)dτ

—this is called the convolution equation. Now, this is a pretty scary equation because it has anintegral in it, but let’s spend a moment to look at each component. The left hand side of x(t) isjust the exponential times the initial condition—this is the state evolution if there were no externalsignal u(t) and is called the transient response. It should look familar—it is just the exponentialsolution for the ODE when there is no external signal. The right hand side involves an integral from0 up until time t and does not include x0, but does include u—it is called the steady state response.How does one actually compute this solution? You don’t typically take the integral—instead, youuse Euler integration or some other integration scheme for the ODE.

How should we confirm that the convolution equation is actually a solution to the ODE? Weplug it in and show that the time derivative is equal to Ax+Bu.

d

dt(x(t)) = AeAtx0 + A

∫ t

0

eA(t−τ)Bu(τ)dτ +

=1︷ ︸︸ ︷eA(t−t)Bu(t)︸ ︷︷ ︸from Leibniz rule

= Ax+Bu

Taking the time derivative of the left hand side just drops down an A, while taking the time deriva-tive of the right hand side is a bit trickier. The key thing is that t shows up in two places—in theboundaries of the integral and in the expression being integrated. This means there are two partsof the derivative—the first one comes from differentiating inside the integral and the second onecomes from Leibniz rule, which was one of the rules from calculus I told you that you would need.

Grouping the expressions allows us to conclude that x(t) indeed does solve the ODE. Whatdoes this equation mean? First, it means that we can separate the effect of the initial condition

53

Page 59: Everything is the Same Modeling Engineered Systems

from the effect of the external signal. Secondly, it means that we have superposition for externalsignals—if I give you two signals u1(t) and u2(t), you can find the state trajectory for each oneand then add them to find the state trajectory for u(t) = u1(t) + u2(t).

Figure 23: spring damper system with external force

To make this more clear, let’s look at an example. Let’s go back and look at the spring-dampersystem from Lecture 3 with an external force and an initial condition of x0 = 0. Let’s assume thatFext = sin(2πt)—a 1 Hz signal. This system has the ODE

x = −kbx+

sin(2πt)

b.

The convolution equation tells us that this ODE has the solution

x1(t) = e−kbt x0︸︷︷︸

=0

+

∫ t

0

e−kb(t−τ)1

bsin(2πτ)dτ.

Moreover, if we instead say that Fext = cos(4πt)—a 2 Hz signal—then the convolution equationssays that the solution to the ODE is

x2(t) = e−kbt x0︸︷︷︸

=0

+

∫ t

0

e−kb(t−τ)1

bcos(4πτ)dτ.

Hence, the convolution equation tells us how to solve for the state evolution for both externalsignals. Now, what happens if Fext = sin(2πt) + cos(4πt)? Then we get

x(t) =

∫ t

0

e−kb(t−τ)1

b(sin(2πτ) + cos(4πτ)) dτ

=

∫ t

0

e−kb(t−τ)1

bsin(2πτ)dτ +

∫ t

0

e−kb(t−τ)1

bcos(4πτ)dτ

= x1(t) + x2(t)

That is, we get that x(t) can be obtained either by simulating the system again with an inputFext = sin(2πt)+cos(4πt) or you can take your solutions for Fext = sin(2πt) and Fext = cos(4πt)and simply add them together! The convolution equation is valid for vector-valued ODEs as well,but then the eA term means something slightly different.

What should you remember from today? Remember that for a linear, constant coefficient, first-order ordinary differential equation with an external signal, the convolution equation gives us atype of superposition principle that includes both initial conditions and external signals.Example: Suppose x = −x+ sin(t). Write the solution for x(t) given x0 = 1. (It may be helpfulto know that

∫ t0e−(t−τ) sin(τ)dτ = 1

2(e−t + sin(t)− cos(t)).) Using the convolution equation, we

find that x(t) = e−t + 12(e−t + sin(t)− cos(t)).

54

Page 60: Everything is the Same Modeling Engineered Systems

The Vector-Valued Convolution EquationIn the previous section, we assumed that x is a scalar-valued quantity, which naturally leads to thequestion of how to obtain solutions for differential equations of the form x = Ax+Bu where x isa vector. To think about this, look again at the convolution equation.

x(t) = eAtx0 +

∫ t

0

eA(t−τ)Bu(τ)dτ

Nothing about this equation is particularly specific to a scalar-valued choice of x(t). If we letu be 1 × 1 dimensional, B be n × 1 dimensional, x0 be n × 1 dimensional, and eAt be n × ndimensional, all of the multiplication is at least dimensionally possible. But what does it mean totake the exponential of At when A is a square matrix?

Assume, for concreteness, that A =

[a bc d

]. What do we want to mean by eAt? To me, the

most natural operation is something like

eAt =

[eat ebt

ect edt

].

But this does not turn out to be the right idea, largely because then our proof of why the convolutionequation is a solution to the differential equation x = Ax+Bu no longer holds.19 As an alternative,let us try to use the Taylor series to extend the exponential function to a matrix. In the scalar case,we know that for a scalar a we have

eat = 1 + at+1

2!a2t2 +

1

3!a3t3 +

1

4!a4t4 +

1

5!a5t5 +

1

6!a6t6 + · · · .

If we replace the 1 with the identity matrix In×n and replace a with A, we get a well-formedequation

eAt = In×n + At+1

2!A2t2 +

1

3!A3t3 +

1

4!A4t4 +

1

5!A5t5 +

1

6!A6t6 + · · · .

That is, all the matrix multiplications are dimensionally consistent and the addition is always di-mensionally consistent (e.g., A3 and A3 are both square matrices of dimension n × n and cantherefore be added together).

At this point, we really have no reason to think that this Taylor series definition of eAt is any

more useful than eAt =[eat ebt

ect edt

], but we can find out if it is useful by looking at its derivative.

Taking the derivative of this definition of eAt with respect to t, we get:

d

dteAt =

d

dtIn×n +

d

dtAt+

d

dt

1

2!A2t2 +

d

dt

1

3!A3t3 +

d

dt

1

4!A4t4 +

d

dt

1

5!A5t5 +

d

dt

1

6!A6t6 + · · ·

= A+1

1!A2t+

1

2!A3t2 +

1

3!A4t3 +

1

4!A5t4 +

1

5!A6t5 + · · · .

= A(In×n + At+1

2!A2t2 +

1

3!A3t3 +

1

4!A4t4 +

1

5!A5t5 + · · · )

= AeAt.

19To see this, try and take the same step as we took in the line where A factors out of the integral. If the equationabove is the definition of the matrix exponential, factoring out A is impossible.

55

Page 61: Everything is the Same Modeling Engineered Systems

That means eAt is a solution to x = Ax with x(0) = x0. Moreover, if one now looks back at theproof that the convolution equation is a solution to the differential equation x = Ax + Bu, onesees that if one uses the Taylor series definition of eAt, the steps are exactly the same. Assumingthat x(t) = eAtx0 +

∫ t0eA(t−τ)Bu(τ)dτ , we get that

d

dt(x(t)) = AeAtx0 + A

∫ t

0

eA(t−τ)Bu(τ)dτ +

=1︷ ︸︸ ︷eA(t−t)Bu(t)︸ ︷︷ ︸from Leibniz rule

= Ax+Bu

and find that, with this definition, we obtain a solution to the differential equation x = Ax + Bu.This means that the convolution equation can be used to obtain solutions to vector-valued linearordinary differential equations with external signals.

56

Page 62: Everything is the Same Modeling Engineered Systems

18 Modeling Electrical ComponentsNear the beginning of this course we talked about how we build models of mechanical systemsfrom models of mechanical components. The same thing is true of electrical systems.

Today we are going to investigate how we model components of an electrical system. Youshould think of voltage V as being an effort variable just like force in mechanical systems. Thecharge q is like the energy stored in a mechanical spring. Lastly, the current i is the flow of chargefrom one part of the circuit to another part of the circuit, and is defined to be the time derivative ofcharge.

i =d

dtq

Figure 24: A constitutive law for an engineered electrical component might look like this; just likemechanical elements, we expect the relationship between voltage V and charge q or current i to belinear.

Just like we did with mechanical systems, we use what are called constitutive laws to modelindividual components. These constitutive laws relate variables of interest, like charge q andcurrent i—the derivative of charge with respect to time—to voltage V . For instance, a plot ofa constitutive law might look like this one where the voltage V is on the vertical axis and thevariable q or i is on the horizontal axis. Just like in the mechanical setting, this curve goes throughthe origin, so if a capacitor has zero charge q in it, or if a resistor has zero current i running throughit, then we expect to measure a voltage between one side of the element and the other that is zero.If, however, the capacitor does have charge, or the resistor does have current running through it,then we expect the measured voltage to be nonzero. The key thing is that these are engineereddevices, so the relationship ends up being pretty close to a linear relationship.

(a) (b) (c) (d)

Figure 25: The four electrical elements: (a) a capacitor (b) a resistor (c) an inductor (d) a battery

57

Page 63: Everything is the Same Modeling Engineered Systems

Electrical diagrams play a critical role in how we set up models of electrical systems, and in thisclass we are going to always assume that we have four types of components— capacitors, resistors(not to be confused with mechanical springs), inductors, and batteries.20 Note that the notationfor batteries has some dashes that are larger than others. We will always use the four symbols inFig. 25 to represent the four types of idealized components.

Moreover, the relationship between voltage and charge of a capacitor is always a line repre-sented by the constitutive law

VC =1

Cq

(where the positive number C is called the capacitance). This means that the larger the capaci-tance, the smaller the voltage V required to maintain the charge. (This is why C is in the denom-inator.) The relationship between voltage and current running through a resistor is also always aline represented by the constitutive law

VR = Ri

(where the positive number R is called the resistance).As a convention, we always indicate the positive end of the battery using large dashes at that

end and small dashes at the negative end. We are free to assign current flow conventions any waywe like. For instance, let’s think about a battery-resistor-capacitor circuit. We can say that the

Figure 26: A battery-resistor-capacitor circuit

current runs clockwise in this circuit. Our sign convention for the polarities of the elements thatare not batteries will be that the current always runs into the positive terminal of the element. Inthe case of this capacitor, that means that the positive end is on the right.

Because of the constitutive law, the voltage across a capacitor being positive means that thecharge on the capacitor must be positive.

VC > 0 ⇒ qC > 0

The voltage across a resistor being positive means that the current running through the resistormust be positive.

VR > 0 ⇒ iR > 0

Lastly, sometimes our expectations about electrical systems will not always be well alignedwith our understanding of the idealized elements. As an example, consider this very simple systemthat consists of a spring, a battery, and a switch. When the switch is open, the circuit is not complete

20These are all DC (direct current) components. In this class we will ignore AC (alternating current) components,but there are versions of these for the AC case.

58

Page 64: Everything is the Same Modeling Engineered Systems

Figure 27: A battery-capacitor circuit with a switch

and there is no charge in the capacitor. However, the moment that the switch closes, this idealizedsystem predicts that the capacitor will be instantly charged because its voltage VC will be instantlyequal to the battery voltage VB.

That probably seems unintuitive, but that’s because real capacitors have what are called para-sitic effects that include the nonideal properties of resistors and inductors. Just like in mechanicalsystems, keeping in mind the difference between these idealized elements and the real, physicalelements they represent is a key skill you are developing in this class.

What should you remember from today? Electrical systems also have linear constitutive lawsbecause we engineer them to behave in a linear manner. Remember that we get to choose thecurrent flow convention in the diagram, and that this determines the sign convention we use. Alsokeep in mind that—just like mechanical systems—idealized electrical elements can have unintu-itive behavior.

59

Page 65: Everything is the Same Modeling Engineered Systems

19 Kirchhoff’s LawsLast time we introduced electrical systems—voltage, charge, current, and the constitutive laws thatrelate them. What principles do we use to generate mathematical models of electrical systems? Inthe case of mechanical system, the principles we used came from Newton’s laws. In the case ofelectrical systems, the laws we use are Kirchhoff’s laws.

Kirchhoff’s laws come in the form of two statements—Kirchhoff’s Current Law (KCL) andKirchhoff’s Voltage Law (KVL). The current law states that the current into a node—a place in thecircuit, typically where two wires21 meet—must equal the current out of the node.

KCL:∑

iin =∑

iout KVL:∑

Vloop = 0

Kirchhoff’s voltage law states that the sum of the voltages around a loop must be equal to zero.

Figure 28: A battery-resistor-capacitor circuit

Let’s focus on the voltage law first and look at the example in Fig. 28. Let’s say that we havea capacitor and resistor and a battery in a single loop. We can choose to have the current runningcounterclockwise in the loop and that determines the polarities of the elements. If we evaluate thevoltage law clockwise—starting at the battery—and assign negative signs any time we encounterthe negative side of an element, we get

VB − VC − VR = 0.

If we now substitute the constitutive laws for VC and VR

VC =1

Cq VR = Ri = Rq

we find thatVB −

1

Cq −Rq = 0 ⇒ q = − 1

RCq +

VBR.

This is the same differential equation as the spring-damper system with an external force (Fig. 29).

Figure 29: A spring-damper system with external force

It is a linear, constant coefficient, first-order ODE, so we can use all the same tools we used formechanical systems, including Euler integration, analytical solutions, superposition, and convolu-tion.

21The node could be anywhere, but KCL doesn’t really tell us anything at a node in the middle of a single wirebecause it simply indicates that the current does not change going through a particular point.

60

Page 66: Everything is the Same Modeling Engineered Systems

Figure 30: A capacitor-resistor-battery circuit with two loops

Let’s look at a slightly more complex example that focuses on Kirchhoff’s current law (Fig. 30).Here we have a resistor and a capacitor and a battery. In the way I have drawn the current flowconventions, Kirchhoff’s current laws tells us that iin = iout, so at Node 1 iC = iR + iB and atNode 2 iR + iB = iC , so the two nodes give us the same information.

Figure 31: Three capacitors and two resistors in two loops

Lastly, let’s look at an example that combines KCL and KVL (Fig. 31). This has three ca-pacitors and two resistors. I can assign the current flow convention any way I want. If I evaluateKirchhoff’s current law, I get

iC2 = iC3 + iC4

⇒ qC2 = qC3 + qC4 +=0︷︸︸︷cons

⇒ qC3 = qC2 − qC4 .

The voltage law gives me

VR1 + VC2 + VC3 = 0 VC4 + VR5 − VC3 = 0.

From these, I can conclude that

R1 iR1︸︷︷︸=qC2

+1

C2

qC2 +1

C3

qC3 = 01

C4

qC4 +R5 iR5︸︷︷︸=qC4

− 1

C3

qC3 = 0

If I substitute in for qC3 , and note that iR1 = qC2 and that iR5 = qC4 ,22 I get

qC2 = −1

R1C2

qC2 −1

R1C3

(qC2 − qC4)

qC4 = −1

R5C4

qC4 +1

R5C3

(qC2 − qC4).

This is a linear, constant coefficient, first-order ODE. I could write this in vector and matrix nota-tion by choosing the state to be w = [qC2 , qC4 ].

22Note that putting nodes at the corners of the circuits indicates that we can do this.

61

Page 67: Everything is the Same Modeling Engineered Systems

Figure 32: Three springs and two dampers that are equivalent to the circuit above

What is this system similar to in terms of a mechanical system? Capacitors are like springsand resistors are like dampers, so we might expect three springs and two dampers. Indeed, this is asystem that gives us the same ODE with potentially different coefficients, depending on the springconstants and damping constants.

What should you remember from today? Kirchhoff’s laws provide the principles by which weconstruct ordinary differential equations that predict the evolution of charge in a circuit. We alsolearned that electrical systems often have mechanical analogs, as in the last example. But whatif that mechanical analog had masses in it? What electrical system would behave the same way?Next time, we will talk about inductors and how they complete the analogy between electrical andmechanical systems.

62

Page 68: Everything is the Same Modeling Engineered Systems

20 Kirchhoff’s Laws with InductorsLast time we discussed Kirchhoff’s laws, but I didn’t say anything about how inductors work.Today we are going to talk about the role that inductors play in circuits and how inductors completethe analogy between mechanical and electrical systems.

Inductors have a simple constitutive law that says that the voltage across the inductor is pro-portional to the time derivative of the current through the inductor.

VL = Li′

Here I am using the prime notation for the derivative so that the dot over the i is not confused withthe time derivative.23 This time derivative of the current i, which is itself the time derivative ofcharge q, should remind you of acceleration of mass.

Let’s say we have a simple circuit with a battery, a capacitor, a resistor, and an inductor.Kirchhoff’s voltage law says that the sum of the voltages around the circuit must be equal to

Figure 33: All four electrical elements in a single loop

zero. Therefore, I get

VC + VR + VL = VB1

Cq +Rq + Lq = VB.

Since, with my current sign convention, the current flows into the negative terminal of the battery,I get a negative sign on VB and can move it to the other side of the equation. If I replace voltageswith constitutive laws as well as i with q and i′ with q, I get a second order differential equation. Itis hopefully clear that L is playing the role of mass in this differential equation.

I can rewrite this differential equation in first-order form

q = i

i′ = − 1

LCq − R

Li+

VBL,

and then rewrite that equation in matrix and vector notation using w = [q, i] as the state vector.

d

dt

[qi

]=

[0 1− 1LC−RL

] [qi

]+

[0VBL

]23To make this clear, look at i versus i′. In text this is bad enough, but in handwritten notes it would be terrible to

keep straight.

63

Page 69: Everything is the Same Modeling Engineered Systems

This means I can use Euler integration from Lecture 4 to compute a solution. For instance, if Ichoose the initial condition to be [

q0i0

]=

[0.50

]and choose the constants to be

L = R = C = 1 VB = 9

then I get [q(0.1)i(0.1)

]≈[0.50

]+ 0.1

([0 1−1 −1

] [0.50

]+

[09

])≈[0.50

]+ 0.1

[08.5

]≈[

0.50.85

].

I can also solve for a solution analytically the way we did in Lecture 5. If I assume an expo-nential solution for q(t)

q(t) = ehtw

I get that

h2 +R

Lh+

1

LC= 0

just like we did with mechanical systems. If R = 0

h = ±√

1

LCj ⇒ q(t) = A cos(

√1

LCt) +B sin(

√1

LCt)

then I get h has imaginary values, which means I should expect sin and cos terms in the solution.This means that this circuit will have the charge in the capacitor oscillating for all time—that is,the charge stored by the capacitor will fluctuate forever.

If I haveR 6= 0, then I can use the quadratic formula, just like we did with mechanical systems,to solve for h. Let’s set L = 1 and C = 1. Then we get

h =−R±

√R2 − 4

2

which means that if R > 2 I have an overdamped system that will have no oscillation and ifR < 2 I have an underdamped system that will experience oscillation with exponential decay.

I hope that this has convinced you that electrical and mechanical systems have very similarbehavior. This is because the equations governing their behavior are exactly the same in manycases!

What should you remember from today? When I have a circuit that has electrical componentsthat include capacitors, resistors, inductors, and batteries, I should expect the same kind of behaviorthat I might see in a mechanical system that has springs, dampers, masses, and external forces.

64

Page 70: Everything is the Same Modeling Engineered Systems

Figure 34: A circuit with capacitance values C, the resistance is R, and the inductance is L.

Also, all the mathematical tools that we developed for mechanical systems are also applicable forelectrical systems.Exercise:

Consider the inductor-resistor-capacitor circuit with four elements 1 − 4 in Fig. 34. The ca-pacitance values are C, the resistance is R, and the inductance is L.

1. Write out all three Kirchhoff’s Voltage Laws without plugging in constitutive laws for thissystem.

V1 + V3 = 0, V2 + V4 − V3 = 0, V1 + V2 + V4 = 0

2. Write out the constitutive law for elements 2 and 4.

V2 = Li′, V4 =1

Cq4

3. Write out Kirchhoff’s Current Laws in terms of i1, i2, and i3.

i1 = i2 + i3

4. What is the first-order ordinary differential equation for this system in terms of the states i2,q3, and q4?

i′2 =−1LC

q4 +1

LCq3

q3 = −i2 −1

RCq3

q4 = i2

65

Page 71: Everything is the Same Modeling Engineered Systems

21 Vector and Matrix Representations in Kirchhoff’s LawsLast time we saw that electrical systems have the same basic characteristic behavior as mechanicalsystems—they have exponential solutions and, with an inductor, can experience oscillation. TodayI want to go through an example that will help you get more comfortable with analysis of circuits.

Let’s say we have a circuit that has two inductors and three capacitors. I can assign the current

Figure 35: Three capacitors and two inductors. This diagram should be like the video lecturewhere i2 and i3 are switched.

sign conventions any way I want, and then I mark in the positive sign for every element where thecurrent flows into the element.

Kirchhoff’s current law states that

KCL: ⇒ i1 = i2 + i3

KVL: ⇒ VL1 + VC2 + VC3 = 0

VC4 + VL5 − VC3 = 0

Kirchhoff’s voltage law tells us that the sum of the voltages is zero around both the left loop andthe right loop. I could choose to sum around the outer loop if I wanted, but that would give meredundant information. Notice that in the second KVL equation the sign of VC3 is negative—thisis because the right hand loop, going clockwise, encounters the negative terminal of C3.

Also note that

i1 = iL1 = qC2

i2 = qC3

i3 = iL5 = qC4 .

This means that—just as in Lecture 19—Kirchhoff’s current law implies that

qC2 = qC3 + qC4

⇒ qC2 = qC3 + qC4 +=0︷︸︸︷cons

⇒ qC3 = qC2 − qC4 .

If we integrate this expression with respect to time, we get that qC3 = qC2 +qC4 plus a constant thatwe set equal to zero because the total charge across all the capacitors in a circuit without a batteryis typically zero.

66

Page 72: Everything is the Same Modeling Engineered Systems

The consequence is that we can use Kirchhoff’s voltage law to find an ODE that governs thestate evolution of the circuit. Keep in mind that the current through the left inductor is the same asthe current through the left capacitor and that the same thing holds for the right inductor and rightcapacitor. We get

KVL: ⇒ L1qC2 +1

C2

qC2 +1

C3

(qC2 − qC4) = 0

L5qC4 +1

C4

qC4 −1

C3

(qC2 − qC4) = 0.

If we convert this second-order differential equation to a first-order differential equation andchoose the state vector to be

w =

qC2

qC2

qC4

qC4

,then we can rewrite the differential equation in vector and matrix notation

w =

0 1 0 0

− 1L1C2

− 1L1C3

0 1L1C3

0

0 0 0 11

L5C30 − 1

L5C4− 1

L5C30

w.This means we have an equation of the form

w = Aw.

So we can use Euler integration to approximate solutions or exponential solutions to obtain analyticsolutions.

Lastly, let’s set all the constants to 1.

L1 = L5 = C2 = C3 = C4 = 1

This gives us an A matrix of 0 1 0 0−2 0 1 00 0 0 11 0 −2 0

.What do you expect this system to do? How do you expect it to behave? I can take A and useMATLAB or Python to compute the eigenvalues of A. We know that these eigenvalues—and theeigenvectors that go with them—are part of the exponential solution ehtw from Lecture 12. If Icompute these eigenvalues, I get the following four values.

h = ±√3j and ± j

This means that I should expect oscillation at two different frequencies—sin() and cos() terms withfrequencies of 1 and

√3. Since superposition applies—because this is a linear, constant-coefficient

67

Page 73: Everything is the Same Modeling Engineered Systems

differential equation—we know that I can also expect to sum these sin() and cos() terms at the twofrequencies. If there was a battery that was oscillating the voltage at some third frequency, then Iknow by the convolution equation that I should expect those frequencies to show up as well!

What should you remember from today? We can use all the tools that we learned in mechan-ical systems—including vector and matrix notation and eigenvalue computation—to analyze andcompute solutions for differential equations for electrical systems. Next time we are going to talkmore about analogies between electrical and mechanical systems to strengthen our intuition aboutthe parallels between them.Exercise:

Assume that w = Aw and that A =

[−1 00 −1

]and w =

[w1

w2

].

1. What is the Euler approximation of w(0.1) if dt = 0.1 and w(0) =[

1−1

]

w(0.1) ≈[

1−1

]+ 0.1

[−1 00 −1

] [1−1

]=

[1−1

]+ 0.1

[−11

]=

[0.9−0.9

]2. What type of circuit does this represent? Circle all that apply in Fig. 36:

Figure 36: Five possible circuits

To figure out which ones it could be, count the states and see how they are related to eachother.Hint: The A matrix suggests that the two states are independent of each other, and therelationship is first order.

68

Page 74: Everything is the Same Modeling Engineered Systems

22 Mechanical/Electrical AnalogiesLast time we talked about using vector and matrix notation to represent electrical circuits. Butwhat if we want to use one physical system to represent another physical system? How do weknow when a parallel between two systems exists? The reason we care about this question is thatwe often use our physical knowledge about one system to reason about another. For instance, weknow that mechanical systems can oscillate if damping is low, and from that we might reason thatelectrical systems can oscillate with low resistance—but only if there is an inductor to play the rolethat mass would play in a mechanical setting. This skill of translating between mechanical andelectrical systems is a key part of how we double check that the solutions we obtain actually makesense.

Remember that capacitors are like springs, resistors are like dampers, and inductors are likemasses. As an example, let’s start with a capacitor-resistor simple circuit. You probably can guess

Figure 37: A capacitor-resistor circuit is an analogy of a spring-damper mechanical system.

that the spring-damper system is an analog of this circuit. But in what sense are they equivalent?The answer is in the ODE that represents each one. In the case of the circuit, the ODE is

q = − 1

RCq︸ ︷︷ ︸

electrical

x = −kbx︸ ︷︷ ︸

mechanical

but this is the same as the ODE for the spring-damper system. We think of two physical systemsbeing equivalent when the ODE that describes them is the same.24

Figure 38: A capacitor-resistor-battery circuit is an analogy of a spring-damper mechanical systemwith a force.

If we add an external force to the spring-damper system, what would we have to add to thecircuit to make the two systems equivalent. Once we add a battery to the circuit, the two differentialequations are the same again.

24This equivalence ignores coefficients—just because the parameters in an ordinary differential equation are differ-ent doesn’t mean we think the systems are not equivalent, in much the same way that we think of two spring-massmechanical systems with different masses as still fundamentally being the same system.

69

Page 75: Everything is the Same Modeling Engineered Systems

Let’s say that now we start with a capacitor-inductor circuit—what is the mechanical analog ofthis circuit? You probably guess a spring-mass system—these two systems have the same ODE.

Figure 39: A capacitor-inductor circuit is an analogy of a spring-mass mechanical system.

q = − 1

LCq x = − k

mx

They are also the same as the slinky I showed in class when I held it horizontally. If I add anexternal force or add a battery, they are equivalent to the slinky I showed in lecture oscillatingin gravity. Another example is the capacitor-resistor-inductor circuit, which is equivalent to the

Figure 40: A capacitor-inductor-resistor circuit is an analogy of a spring-damper-mass mechanicalsystem.

spring-damper-mass mechanical system.

Figure 41: Two decoupled capacitor-inductor circuits are an analogy to two decoupled spring-massmechanical systems.

Now, let’s say that I have a different capacitor-inductor circuit. What is the equivalent mechan-ical system? The equivalent system is a mechanical system with two masses, but the dynamics ofthe two masses are completely independent of each other! This is not easy to see in the electricaldiagram—at least it is not so easy for me—but it is really easy to think about in the mechanicaldiagram. With two batteries, this system would be equivalent to two one-mass slinkys.

Now what if we added a capacitor so that the circuit has three capacitors? What mechanicalsystem is equivalent to this circuit? The equivalent mechanical system has two masses and threesprings—the middle spring couples the dynamics of the mass on the left to the dynamics of themass on the right. Again, for me this is much easier to understand in the diagram on the right. Bothof these systems are equivalent to the slinky in lecture with two masses.

What should you remember from today? Analogs between electrical and mechanical systems

70

Page 76: Everything is the Same Modeling Engineered Systems

Figure 42: A coupled circuit is an analogy of a coupled mechanical system.

are a powerful way of gaining intuition and applying the physical knowledge you have about onetype of system to the other types of systems that are equivalent.

71

Page 77: Everything is the Same Modeling Engineered Systems

23 Interpretation of Mathematical Expressions as Physical Sys-tems

Last time we talked about analogies between physical systems. Today we are going to talk aboutusing physical systems to understand and reason about mathematical expressions. If I give you amatrix of the form

A =

[0.001 0.989−3.2 −0.01

]what could you do with it? Could you tell me what it means? Looking directly at a matrix repre-sentation of a dynamical system is a skill that is surprisingly useful, partially because often timesmatrix representations come from data, and data is never as clean as the examples we cover inclass. In the case of this example, what if I write down a matrix that is nearly the same as theexample?

A =

[0 1−3 0

]This is the matrix that represents a spring-mass mechanical system or a capacitor-inductor electri-cal system. If I choose the state vector to be

w =

[xv

],

then w = Aw implies that

x = v

v = −3x

which implies that x = −3x.Looking at Fig 43 and these equations, I now know to expect that the matrix I started with should

Figure 43: Both spring mass mechanical systems and inductor-capacitor electrical circuits have thesame mathematical representation.

have eigenvalues that are nearly only made up of their imaginary parts (i.e., the part without the j isvery small). If I calculate the eigenvalues, I find that h = −0.0045±1.7789j, so my suspicion wascorrect. This pair of eigenvalues means that the damping is very low because the nonimaginarypart of h is very small and negative.

Let’s look at some other examples. For instance, what does

A =

[−1 00 −2

]

72

Page 78: Everything is the Same Modeling Engineered Systems

represent? Because the diagonal elements are nonzero and the off-diagonal elements are zero,we know that these two states are independent of each other and are first-order. Therefore, thisA matrix represents either a two-spring-two-damper mechanical system or a two-capacitor-two-resistor circuit, like those seen in Fig. 44.

Figure 44: Decoupled systems are represented by diagonal matrices

Now let’s think about this four by four matrix.

A =

0 1 0 0−1 0 0 00 0 0 10 0 −1 0

This matrix has two states that depend on each other in the upper left and two states that

depend on each other in the bottom right—this corresponds to two spring-mass systems that aredisconnected or a capacitor-inductor circuit.

Figure 45: Another set of decoupled systems

Lastly, let’s consider one more A matrix.

A =

0 1 0 0−5 0 1 00 0 0 11 0 −1 0

This system has the dynamics of the two masses like the previous example, but also has termsin the upper right and lower left. This means that the masses in the mechanical system must becoupled with each other, like a spring-mass system and a capacitor-inductor circuit.

Figure 46: Coupled second-order systems

73

Page 79: Everything is the Same Modeling Engineered Systems

The key thing is that being able to recognize mechanical and electrical analogs of mathematicalstatements makes interpretation of data—and even this class—much easier!

What should you remember from today? Remember that when you look at a matrix, it helps tothink about what that matrix might represent. The analogy often helps us reason about the systemthe matrix represents, even if it is not a mechanical or electrical system.

74

Page 80: Everything is the Same Modeling Engineered Systems

24 Everything Is The Same—AlmostWe are going to end with what I promised you at the beginning of the class—that everything isthe same. Well, at least with all the caveats that the system is engineered and that we can useconstitutive laws and all of the other restrictions I have made on the way. But today we are goingto see that electrical and chemical systems are sometimes the same, and because of the connectionbetween mechanical and electrical systems, all three types of systems are sometimes the same.

As an example, consider this RC circuit.j

This circuit has lots of repeating elements, each with a capacitor and resistor. All of the capac-itors have capacitance C and all of the resistors have resistance R. The equation that we get for thecharge on each capacitor is

qi =1

RC(qi+1 + qi−1 − 2qi)

Look at the right hand side of this differential equation and now look at the diffusion equation priorto taking the limit as dx→ 0.

d

dtC(xi) = D

C(xi+1)−C(xi)dx

− C(xi)−C(xi−1)dx

dx

= D(C(xi+1) + C(xi−1)− 2C(xi))

dx2

This means that the dynamics of the electrical system are approximately equal to the dynamics ofthe diffusion equation if dx = 1, therefore

D =1

RC.

Let’s test this out and simulate the electrical system while plotting the solution to the diffusionequation on top of it. We can choose a total of n = 100 capacitors and R = 0.1 and C = 2.Moreover, we choose the initial charge on every capacitor to be zero except the one in the verymiddle, which we choose to have a positive initial charge of 1 Coulomb. We plot the height ofeach state and watch it change over time and we plot the solution to the diffusion equation on topof it. Amazingly, these two solutions are right on top of each other! Prior to the near-universal useof computers for simulations, people used this relationship between the circuit and the diffusionequation to use a circuit as an analog simulation of how a chemical might diffuse in a fluid.

What does this mean? It means that electrical systems can experience diffusion if there areenough electrical elements involved. Since electrical and mechanical systems are equivalent, itmeans that there is a mechanical system that is equivalent to the diffusion equation as well! In fact,one mechanical analog is a series of spinning masses with torsional damping between them, where

75

Page 81: Everything is the Same Modeling Engineered Systems

æææææææææææææææææææææææææææææææææææææææ

ææ

ææ

ææ

ææ

ææææææ

ææ

ææ

ææ

ææ

ææææææææææææææææææææææææææææææææææææææ

20 40 60 80

0.1

0.2

0.3

0.4

0.5

Figure 47: The RC circuit follows the evolution of a time-varying diffusion equation. Hence, thecircuit can be used to “simulate” a diffusion process.

we focus on the state v and how an initial velocity in the middle diffuses to velocities through thesystem. You might find it interesting that heat also diffuses in a mechanical body. For instance,if you touch a piece of metal with something hot, the metal will get hot—and the way it gets hotsatsifies the diffusion equation. This is why sometimes the diffusion equation is called the heatequation. So even thermodynamic systems are sometimes the same as mechanical, electrical, andchemical systems. I do not know how you feel about this, but to me this is a really beautiful andprofound idea.

But mechanical, electrical, and chemical systems are not always the same! We saw before thatmechanical and electrical systems are sometimes the same if the components match up well. Wesee here that they are sometimes the same if there are lots of components and those componentsare very uniform—the resistance and capacitance of the circuit has to be the same everywhere forthe circuit to be the same as the heat equation.

Lastly, the relationship between mechanical, electrical, and chemical systems means that wecan use these physical analogies to understand how charge will diffuse through a circuit or howenergy in a mechanical system will diffuse through its elements.

The main thing I hope that you get out of this class is the sense that very different physicalsystems often behave very similarly. Of course, this doesn’t mean that the title of the class isliteral—not everything is the same! But enough things are the same that understanding analogiesbetween systems provides us with a way of connecting analytical reasoning with computation,and computation with our physical knowledge, and our physical knowledge back to the analyticalreasoning. This ability to connect these different ideas and intuitions is part of what makes anengineer competent to make decisions, and I hope you find this class helpful in your future asengineers!

76

Page 82: Everything is the Same Modeling Engineered Systems

c©Todd D. Murphey

77