Skip to main content

Differential Equations, Input Functions, Complex Exponentials, and Transfer Functions

  • Chapter
  • First Online:
System Dynamics
  • 5909 Accesses

Abstract

Differential system equations describe the dynamic relationship between an input driving the system, and one of the power variables within the energetic system. We simplify, or linearize, the individual energetic element equations, in order to derive a system equation which is an ordinary differential equation with constant coefficients, a form which we can solve for the output or response function. The method of undetermined coefficients superposes or sums the response of a system into the natural or homogeneous response of the system to a disturbance to its energetic equilibrium, and the steady-state or particular response to each input driving the system. Systems with two or more independent energy storage elements yield differential system equations which may describe oscillations or vibrations. Complex numbers, complex exponentials, and Euler’s equations simplify the solution and interpretation of the response of oscillatory systems. The Laplace transformation transforms differential equations into algebraic equations, which can be expressed as multiplicative dynamic operators called transfer functions. The chapter’s appendix introduces Mathcad and MATLAB to plot the solutions or response functions.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 69.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 89.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 119.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References and Suggested Reading

  • Hildebrand FB (1976) Advanced calculus for applications, 2nd edn. Prentice-Hall, Englewood Cliffs

    Google Scholar 

  • Ogata K (2003) System dynamics, 4th edn. Prentice-Hall, Englewood Cliffs

    Google Scholar 

  • Ogata K (2009) Modern control engineering, 5th edn. Prentice-Hall, Englewood Cliffs

    Google Scholar 

  • Rowell D, Wormley DN (1997) System dynamics: an introduction. Prentice-Hall, Upper Saddle River

    Google Scholar 

  • Shearer JL, Murphy AT, Richardson HH (1971) Introduction to system dynamics. Addison-Wesley, Reading

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Karl A. Seeler .

Appendices

Chapter 2 Appendix

Table 2.3 Laplace transform pairs

Mathcad and MATLAB

In the early 1980s, shortly after personal computers were introduced, there was a flurry of activity to develop software for the emerging market. Two Massachusetts companies targeted engineering and scientific computation with radically different approaches. Mathsoft, the originator of Mathcad, chose to develop software which emulated the mixture of mathematics, graphics, and text, which typifies manual engineering calculations. A Mathcad “worksheet” presents equations in as close to standard mathematical notation as possible. What the user sees is actually a graphical interface defined by user created “regions” or objects that support mathematics, graphics, or text. The regions within the worksheet can be dragged around, resized, copied, and edited. Mathcad worksheets are evaluated automatically from top to bottom, left to right when any change is made.

MathWorks, the developer of MATLAB took a different approach from Mathsoft. Rather than creating an automated engineering computation worksheet, MathWorks chose to create a “high-level” programming language with the functions and functionality needed for engineering and scientific computing. A high-level programming language performs many of the tasks needed to translate an algorithm expressed as human-readable computer code into the instructions required by the computer’s processor to execute the program. Computer programs from 1950’s through the early 1980’s were tiny, by today’s standards. Most general purpose computer programming languages in use during that early period were written to implement mathematical algorithms for engineers and scientists. MathWorks foresaw the time when general purpose programming languages would evolve into “object-oriented” languages to manage the execution of enormous programs, and no longer permitted simple programming of mathematical algorithms. MATLAB is a “procedural” language intended to encode algorithms. The syntax and execution of MATLAB resemble that of the original BASIC computer language from the 1960s, which was developed as an introductory programming language.

2.2.1 Plotting in Mathcad

Mathcad Prime is engineering computational software designed to resemble the layout and appearance of manual computations. Equations, graphics, and text can be placed at will in the worksheet, with the only restriction that constants and functions must be defined above where they are used, because the worksheet is computed from top to bottom, left to right. Mathcad strives to use conventional mathematical notation, making the worksheet significantly easier to read than computer code. Plotting a function in Mathcad requires little more than defining the function to be plotted using an assignment statement.

2.2.1.1 Mathcad Assignment Statements

Assignment statements are instructions to a program to assign a value or expression to a variable. Assignment statements are read from right to left. In other words, the quantity on the right side of an assignment statement is assigned to the variable or function on the right. Although most computer languages, including MATLAB, use the convention, equal sign i.e., = , as the “assignment operator,” Mathcad does not. The Mathcad assignment operator is : = , which is created by typing a colon. It is supposed to connote an arrow pointing from right to left. The reason Mathcad uses : =  rather than  =  as the assignment operator is because assignment statements are not equalities. Assignment statements are similar to a “store” command on a calculator. An assignment statement is an instruction to store the value or expression on the right within the variable or function name on the left. For example, the following are three valid Mathcad assignment statements.

$$\begin{aligned}& \text{a}:=1 \\ & \text{a}:=\text{a}+1 \\ & \text{F}(\text{t}):=10{\cdot} {\sin }\left( 2{\cdot} \text{t} \right) \\ \end{aligned}$$

The first and third assignment statements also make sense as equalities. However, the second statement written as an equality, \(a = a + 1\), is nonsense.

In Mathcad, a conventional equal sign is a command to evaluate a variable or an expression, and display the result. The use of an equal sign makes sense in this context, because the quantities on either side of the equal sign are equal.

2.2.1.2 Plotting in Mathcad

Let us say you wish to plot the result of example Sect. 2.8.1, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\). You must first define v(t) in the Mathcad worksheet above, or to the left of where you plan to place the plot. When you click on an empty area of a Mathcad worksheet and begin to type, the program presumes that you are entering an equation. If, in fact, you are typing text, Mathcad will recognize you are entering text by the space entered between letters. There are no spaces in equations. When entering an equation, the space bar is used in lieu of the mouse to move the \(\left. {\underline {\,{} \,}}\! \right|\) shaped cursor out of exponents and denominators. Alternatively, if you wish to enter text, type “ as the first character to create a “text region.”

Click in an empty area of a Mathcad worksheet and type

$$\text{v}(\text{t}):2.66*(1-\text{e}\hat{\ }-0.5*{{\text{t}}_{\,\,Space\,\,Bar}}_{\,\,Space\,\,Bar})$$

Then either type tab, or click outside of the equation object. You will see the following:

$$\text{v}(\text{t}):=2.66\cdot \left( 1-{{\text{e}}^{-0.5\cdot t}} \right)$$

Mathcad is case and font sensitive. T, t, t, τ, and t are all different variables. Greek characters can be entered using the Greek alphabet “pallet” (produced by clicking on the αβ button), or by typing the combination of the Ctrl key and g simultaneously, when the cursor is immediately to the right of the Roman character one wishes to change to Greek.

The duration of a response plot should be six or seven times the largest time constant in the system, Sect. 2.9.4. We are plotting a first-order response, where the time constant is the inverse of the magnitude of coefficient in the exponent, \(\sigma=- 0.5\). Type

$$\text{t}\underbrace{\text{Ctrl+g}}_{\text{Simultaneously}}:\,\,|\,\,1/-0.5$$

Press the Ctrl and g keys simultaneously. Type tab or click outside the equation object and you will see

$$\tau :=\left| \frac{1}{-0.5} \right|$$

To insert an x-y plot into a Mathcad worksheet, first place the cursor outside an existing Mathcad text or math region. One can then either use icons or the menus. The first time you click on a plot icon, Mathcad displays the plotting pallet or button bar. Clicking on the icon for an x-y plot in the button bar inserts an empty x-y plot into the worksheet. To use the menu, click on the Insert menu, and follow the drop down menu to the item X-Y Plot.

Insert

Graph

X-Y Plot.

An empty x-y plot will display with solid black rectangles termed “place holders” for the independent and dependent variables and the axes limits, Fig. A2.1.

Fig. A2.1
figure 52

A Mathcad x-y plot object showing the black rectangular place holders. The variables can be scalars, vectors, expressions, or functions. The limits can be numerical values or expressions

To plot v(t) vs. t, enter t in the independent variable place holder on the x-axis, 0 in the lower limit x-axis place holder, 7*t Ctrl + g (to see \(7 \cdot \tau\)) in the upper limit x-axis place holder, and either the function, v(t), or the expression, \(2.66 \cdot ( {1 - {{\rm{e}}^{ - 0.5 \cdot {\rm{t}}}}} )\), in the dependent place holder on the y-axis. Clicking outside the region causes Mathcad to display the plot, Fig. A2.2.

Fig. A2.2
figure 53

A Mathcad plot of the function, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\)

Mathcad autoscales axes, when the limit place holders are blank. Often, as in this example, autoscaling leads to the display of only a portion of the response. The limits can be edited, after the plot is produced to change either the vertical or horizontal range shown. Clicking on the lower limit of the vertical axis 0.689 introduces the \(\left. {\underline {\,{} \,}}\! \right|\) shaped cursor into that region. Editing 0.689 to read 0, and then either typing tab, or clicking outside the plot region causes Mathcad to re-evaluate and display the plot, Fig. A2.3.

Fig. A2.3
figure 54

The Mathcad plot of the function, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\), with the lower limit of the vertical axis edited to read zero

Plot regions can be dragged around the worksheet, and the frame of a plot region can be dragged to resize the plot. Plots can also be “formatted” to add grid lines, change the grid spacing, and to change the width, color, and type of line, Fig. A2.4. Right-clicking within a plot region brings up a context-sensitive menu which includes the three items, Format…, Trace…, and Zoom… The format dialog box has five tabs which are self-explanatory, with the exception of the “secondary Y-axis.” Clicking the check box “Enable second Y-axis” produces a set of place holders on the right side of the plot, the middle place holder is for a second dependent variable, and the other two are the limits of the secondary Y-axis. We will find a secondary Y-axis useful, since the power variables of energetic systems have different units and, importantly, different magnitudes. Plotting the responses of two different power variables on one axis can lead to one response appearing flat, since its vertical range is misscaled.

Fig. A2.4
figure 55

The Mathcad plot of the function, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\), formatted adding gridlines, axes labels, and a plot title

When we wish to plot two or more “traces” on the same axis, typing a comma after entering a variable or expression in a place holder produces another place holder. For example, we plot \(v( t )\), \(- 2.66{{\rm{e}}^{ - 0.5t}}\), and 2.66 on the same axis, by typing a comma after entering \(v( t )\), and again after entering \(- 2.66{{\rm{e}}^{ - 0.5t}}\), Fig. A2.5.

Fig. A2.5
figure 56

The Mathcad plot of the function, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\), the expression, \(- 2.66{{\rm{e}}^{ - 0.5t}}\), and the constant, 2.66

We chose to set the limits of the time axis at zero and six or seven time constants. If we create a plot by editing the place holders for the independent and dependent variables, but leave the axes limits blank, Mathcad will autoscale the horizontal axis from − 10 to + 10, and evaluate the dependent variable within those limits. Since the input was applied at time, t = 0, the plot will show a response before the input acted on the system, Fig. A2.6. Even though we did not intend for the function to be evaluated for negative time, it can be. The polite term for the resulting plot is “non-causal” since it violates cause and effect. The more common terms include nonsense and garbage.

Fig. A2.6
figure 57

The Mathcad plot of the function, \(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\), autoscaled from \(t =- 10\)to \(t =+ 10\)

Do not plot negative time, unless (1) the input is applied at the negative time of the lower limit, or (2) the response function is multiplied by the Heaviside unit step function to zero out the response function, until the time the input is applied. Mathcad’s notation for the Heaviside unit step function is capital phi, Φ( ). The f(x) button brings up a dialog with all of Mathcad’s built-in functions. The Heaviside unit step is in the “Piecewise Continuous” submenu, or can be found in the alphabetical list. Multiplying the response function by the Heaviside unit step function zeros out the value of the response function, until the moment when the Heaviside step function transitions from zero to one, Fig. A2.7.

Fig. A2.7
figure 58

The Mathcad plot of the product of the response function, v(t), and the Heaviside step function, u s (t). Mathcad’s notation for the Heaviside step function is Φ(t)

As an example of a second-order oscillatory step response, we will plot the result of Sect. 2.7.3

$$v\left( t \right)=2.74{{\text{e}}^{-0.16t}}\cos \left( 0.68t-2.91 \right)+2.66$$

Recall the exponent of the real exponential is σ, the real component of the eigenvalues of the system, and the frequency ω is the magnitude of the imaginary component of the eigenvalues.

$${{s}_{1}},\,{{s}_{2}}=\sigma \pm j\omega \,\,\,\,\,\,\to \,\,\,\,\,\,{{s}_{1}},\,{{s}_{2}}=-0.16\pm j0.68$$

Create an assignment statement defining the response variable, v 2(t). Note the subscript 2, which is part of the function’s name. Mathcad refers to a subscript which is part of a variable of function name as a “literal” subscript, to distinguish it from a subscript which represents the index of a vector. A literal subscript is created by typing a period immediately before the literal subscript. A “vector” subscript or index is created by typing a left square bracket [ immediately before the subscript. Type

$$\text{v}.\text{2}(\text{t}):2.74*\text{e}\hat{\ }-0.5*{{\text{t}}_{\,\,Space\,\,Bar}}_{\,\,Space\,\,Bar}*\cos (0.68*\text{t}-2.91)+2.66$$

to see

$${{\text{v}}_{2}}\left( \text{t} \right):=2.74\cdot {{\text{e}}^{-0.16\cdot \text{t}}}\cdot \cos \left( 0.68\cdot \text{t}-2.91 \right)+2.66$$

The time constant, which scales the duration of the plot, is the time constant of the decay envelope. The upper limit of the time axis should be six or seven τ, where

$$\tau =\left| \frac{1}{\sigma } \right|\,\,\,\,\,\,\to \,\,\,\,\,\,\tau =\left| \frac{1}{-0.16} \right|\,\,\,\,\,\,\to \,\,\,\,\,\,\tau =43.75\,\,\sec \approx 44\,\,\sec $$

Mathcad permits assignment statements to be evaluated. Type

$$\text{t}\underbrace{\text{Ctrl+g}}_{\text{Simultaneously}}.2:\,\,|\,\,1/-0.16=$$

to see

$${{\tau }_{2}}:=\left| \frac{1}{-0.16} \right|=6.25$$

Create a plot by clicking the X-Y Plot button, which should be visible in both the button bar below the menus and in the Graph pallet. Get into the habit of entering the independent variable, t, and its limits, before entering the function name or expression as the dependent variable. Reversing the order leads to Mathcad trying to be helpful and autoscaling using its standard range of − 10 to 10, which is rarely the range we will want. Format the plot, adding gridlines, axes labels, and a plot title, Fig. A2.8.

Fig. A2.8
figure 59

The Mathcad plot of the response function, v 2(t), formatted with gridlines, axes labels, and a plot title

We can reuse function and variable names. The assignment operator : =  is a “local” assignment, meaning that it can be overwritten by a new assignment operator which appears to its left or below it in the worksheet. If we reuse a variable name, Mathcad underlines it with a green squiggle, to alert us, in case we thought the variable name was unique. Mathcad handles units as if they were variables, and has virtually every engineering unit predefined. Click on the measuring cup symbol to bring up the unit dialog box. Many common choices for variable names are predefined units. Consequently, variables may be underlined with a green squiggle, even though they are unique, because they are also the abbreviation of a unit.

Mathcad permits mixed units in calculations. Mathcad converts all units to SI prior to computation, and then presents the results in SI (or sometimes metric) but adds a blank placeholder. If the user enters a unit into the placeholder, Mathcad recomputes and expresses the result those units.

For example, type in the following volume computation, where the three lengths are expressed in inches, feet, and centimeters.

$$5*\text{in}*0.6*\text{ft}*14*\text{cm}=$$

You will see,

$$5\cdot \text{in}\cdot 0.6\cdot \text{ft}\cdot 14\cdot \text{cm}=3.252\,\text{L}\,\blacksquare $$

Edit the place holder. Type in^3. You will see

$$5\cdot \text{in}\cdot 0.6\cdot \text{ft}\cdot 14\cdot \text{cm}=3.252\,\text{L}\,\blacksquare $$

2.2.2 Plotting in MATLAB

2.2.2.1 MATLAB’s Environment

MATLAB is a programming “environment.” The default configuration opens with a tabbed tool bar across the top of the screen and five windows below it, with the Command Window in the center. MATLAB is an “interpreter” which means MATLAB translates and executes code line by line. The practical effect is that the “command line,” identified by “prompt” > > in the Command Window, can be used as a calculator. For example, typing 2 + 4 Enter at the command prompt yields

 > > 2 + 4

ans = 

6

MATLAB keeps a record of the commands and the variables used in calculations and scripts. The Command History window shows a history of commands entered which extends to prior uses of MATLAB. It is convenient for an individual using MATLAB on a personal machine, but it also means that users of a public machine have access to the prior user’s command history. The command history can be cleared by right-clicking on the title bar at the top of the Command History window to bring up a context menu and selecting the item “Clear Command History.”

2.2.2.2 Array Variables

The record of the variables used is shown in the window titled, Workspace, with three columns, Name, Value, and Min. Note that MATLAB created the variable named ans and displays its Values and Min as 6. The icon at the left of row is a square subdivided into four squares. This is a clue that the MATLAB’s default variable type is an “array.” An array is an ordered set of data where an individual element is identified by an index. The indices locate elements in an array as if they were Cartesian coordinates. A one-dimensional array, also called a vector, because it resembles mathematical vectors, is a sequence where an element is identified by a single index. Two-dimensional arrays, which resemble matrices, require two indices to identify an element. In standard mathematical notation, the index of an element in a vector or matrix would be subscripted. There are no subscripts, superscripts, or Greek characters in computer code, only the keyboard characters. Array indices are contained in parentheses. For example, element 14 of the vector y is written as y(14). A vector index may be an expression, such as y(n + 1). The values of vector indices must be positive integers. A restriction of MATLAB is that the smallest vector index is one, not zero.

2.2.2.3 Assignment Statement

The assignment operator in MATLAB is a conventional equal sign, = . Assignment statements are read from right to left. The right side can be a numerical value, a previously defined variable, or an expression. The left side must be a variable.

2.2.2.4 For-End Loop

MATLAB provides a number of “flow-control” instructions, or commands, which allow the execution sequence of repeat or skip blocks of code. We will use a logic structure called a for-end loop which, as one might guess, begins with the word for on the first line of the code block and ends with the word end on the last. A variable which serves as a counter is defined in the for line and given an integer range. The counter variable consecutively assumes values of a defined range. The lines of code between the for and end lines are repeatedly executed, until each counter variable defined in the for line and incremented by one passes through, and the loop reaches its upper limit.

Example. We will wish to repeat the calculation of a response function, perhaps one thousand times. We choose a name, say n, for the counter variable. We can use the counter variable in the code between the for and end statements, but we must not change its value. MATLAB will increment the value of the counter variable, and check it against the upper limit of the range. The syntax of a for-end loop that executes 10 times is

figure a

We can create a vector variable and assign it values using a for-end loop. Say we need a time vector t from t = 0 to t = 1.0 with the time step or increment \(\Delta t = 0.1\). How many elements are in the vector t? There are 11. The common error is to divide the interval by the increment,

\(\frac{{{t}_{end}}-{{t}_{start}}}{\Delta t}=\frac{1.0-0}{0.1}=10\) Intervals

This is the correct number of intervals of one-tenth between zero and one, but we are short of one value needed to create the end point for the last interval. The calculation of interval end points is

\(\frac{{{t}_{end}}-{{t}_{start}}}{\Delta t}+1=\frac{1.0-0}{0.1}+1=11\) Interval End Points.

2.2.2.5 MATLAB’s Editor

We will use MATLAB’s editor to write a “script” or program to create the vector t., stored with the extension.m, and then run at the command line by typing the file’s name. Search as you may, you will not find a tab or window for MATLAB’s editor from the default environment. The editor is opened, when you choose the icon, “New Script,” in the Home tool strip tab. The Editor opens as a second program. The only way to navigate from the Editor back to the MATLAB environment is by clicking on the MATLAB icons in the Windows task bar, and selecting the MATLAB environment.

Comments are labels, explanations, and notes added to computer code for the programmer’s and future user’s benefit. The longer and more complicated the code, the more important are comments for structuring the program and making it understandable. Comments begin with a percent sign % and are colored green in MATLAB’s editor. A comment may occupy the end of a line of code, or may be a line by itself. Comments which identify variables and describe the function of blocks of code are essential. The purpose of writing a script is to save time by automating tasks. Poorly commented code is difficult to understand and use, and defeats the purpose.

We will begin our script with a comment giving the name of the script, First.m, and the date. MATLAB names cannot have spaces. Use an underscore instead. Our simple program is

figure b

Write and save the script. Although you can accept MATLAB’s default location, it is best to save your script to a personal storage device or location. Click on the green triangular Run icon in the tool bar at the top. A dialog will appear stating that the script is not in the current folder or on the MATLAB path. Click on the button, Add to Path, which adds your personal storage location to those locations that MATLAB checks for scripts. It will also run the script. Nothing appears to happen, because you are still in the Editor. Navigate to the MATLAB environment. You will see the result in the Command Window. The elements of vector t are written to the Command Window for each iteration through the loop. Notice that t is now listed in the Workspace window, and has the Value, < 1 × 11 double > , describing it as a one-dimensional array with 11 elements of a data-type double. Data type refers to how data are stored. Double refers to “double precision floating point” number. Double precision uses 64 bits of computer memory. Floating point refers to scientific notation.

2.2.2.6 Plotting

We will now edit First.m to create a second vector y and plot it. Although MATLAB has pi as a constant, it does not have Euler’s number e. Exponentiation to the base e is performed with the function exp(). MATLAB’s function, plot(), produces an interactive plot which can be resized, formatted, and “interrogated” using the “data cursor.” The arguments of plot() are pairs of vectors which contain the x and y-axes coordinates of the data plotted, e.g., plot(x, y). In our example, the independent variable is the vector t. Add the plot command after the end statement.

Our output is now graphical in the form of a plot. We do not need to see the values of t and y written to the screen. In fact, writing each iteration of the loop to the screen slows execution of the script significantly. A semicolon at the end of line of code is an instruction not to write that line on the screen.

figure c

Save and run this script. The MATLAB plot titled Figure 1 will appear as a new document, Fig A2.9. If Figure 1 does not exist, it will be displayed on top of the Editor. If Figure 1 already exists, it will be overwritten with the current plot but will not be brought to the front. Navigate to it by clicking on the MATLAB icons in the task bar at the bottom of the screen.

Fig. A2.9
figure 60

Plot of the MATLAB script, First.m

MATLAB figures can be formatted after they are created, by opening the “Tools” menu item in the menu bar of the figure, and choosing Edit Plot. It is also possible to format figures with commands in the script. Although more complicated, it allows the formatting to be automated. The technique is addressed in the Programming in MATLAB appendix to Chap. 8.

2.2.2.7 The Dark Side of MATLAB’s Workspace

There is a dark side to MATLAB’s workspace. Variables remain in the workspace, until they are deleted, by selecting the variable in the Workspace window, right-clicking, and choosing delete, or the entire workspace is cleared by selecting the title bar of the Workspace window, right-clicking, and choosing Clear Workspace. The existence of variables in the workspace can mask errors and omissions in scripts. For example, say you write a script to calculate a response function. You intend to define a variable named tau equal to a certain value, but you simply forget and omit that line of code. If you run the script and tau was not used in any previous calculations and, consequently, is not in the workspace, MATLAB identifies the error. A ding sounds, and the Command windows displays an error message indicating that an undefined variable was used in line x of the script. On the other hand, if you omit the definition of tau in the script, but tau exists in the workspace with a different value, MATLAB will use the workspace value. The script will execute but produce an erroneous result.

Minor editing of the script, First.m, will provide a graphical example of the effect of MATLAB’s workspace. Second.m uses the same variables, named t and y, as First.m. The upper limit of the for-end loop is reduced to 9 from 11. Finally, the argument of exp() is multiplied by two, increasing the exponential decay rate.

figure cb

The plot, Fig. A2.10, is correct from t = 0 to t = 0.8, corresponding to the portions of the vectors, t and y, which were overwritten with new values. The final two elements of vectors t and y were not overwritten, and still hold values created by the previous script First.m, leading to the kink in the curve. Although this example may seem contrived, it is not. Engineers tend to use and reuse the same meaningful variable names. MATLAB does not create a new instance of an existing variable. Consequently, when MATLAB executes an error, or the results of successful execution of a script do not make sense, clear the workspace and run the script again.

Fig. A2.10
figure 61

Plot of the MATLAB script, Second.m, showing a kink due to the final two values, which were retained in the vectors, t and y, from the previous execution of a script, First.m

2.2.2.8 Plotting Flow Chart and Script

We now have the basics to write a MATLAB script to plot response functions. We must develop the logic to establish the duration of the plot and the time step of the calculation. The variable is tau_max, the largest time constant of the system. tchar is the smallest characteristic time of the system, which may be either a time constant, or, if the response is oscillatory, a period of oscillation T, Sect. 2.9.4. The time step, dt, is 1/200 of tchar. The duration of the calculation, tend, should be approximately six or seven tau_max. The number of calculations for the plot N is

$$N=\frac{tend}{dt}$$

The for-end loop is similar, and the plot() command is identical to scripts, First.m and Second.m. Figs. A2.11 and A2.12 are flow charts of the script.

We cannot name the script, plot.m, because plot () is a MATLAB function, so we will name it Plotting.m. Because we must edit the script each time we wish to plot a new response function, it is helpful to uniquely identify each version of the script with a date code, i.e., plotting_060314.m. The plot produced by the code, Fig. A2.13, is then formatted and annotated using MATLAB's plot editing features.

figure cc
figure cd
figure e
Fig. A2.11
figure 62

Upper half of the Flowchart of the MATLAB script, Plotting.m

Fig. A2.12
figure 63

Lower half of the Flowchart of the MATLAB script, plotting.m

Plotting additional traces on the y-axis requires the creation of additional output vectors, and then adding pairs of independent, dependent variable vectors to the plot statement. We will rename the script, plotting_060314A.m, as the following: plotting_060314C.m, and edit it to plot\(v( t ) = 2.66( {1 - {{\rm{e}}^{ - 0.5t}}} )\), \(- 2.66{{\rm{e}}^{ - 0.5t}}\), and 2.66 on the vertical axis. The revisions are in the for-end loop and in the command plot (). The resulting plot is Fig. 2.14.

Fig. A2.13
figure 64

The MATLAB plot of the response function, v(t), from the script, plotting_060214A.m, after formatting

Fig. A2.14
figure 65

The MATLAB plot of the response function, v 2(t), from the script, plotting_060214B.m, after formatting

Fig. A2.15
figure 66

The MATLAB plot of the response function, v 1(t), −2.66−0.5 t and 2.66 from the script, plotting_060214C.m, after formatting

figure f
figure g

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Springer Science+Business Media New York

About this chapter

Cite this chapter

Seeler, K. (2014). Differential Equations, Input Functions, Complex Exponentials, and Transfer Functions. In: System Dynamics. Springer, New York, NY. https://doi.org/10.1007/978-1-4614-9152-1_2

Download citation

  • DOI: https://doi.org/10.1007/978-1-4614-9152-1_2

  • Published:

  • Publisher Name: Springer, New York, NY

  • Print ISBN: 978-1-4614-9151-4

  • Online ISBN: 978-1-4614-9152-1

  • eBook Packages: EngineeringEngineering (R0)

Publish with us

Policies and ethics