Download presentation
Presentation is loading. Please wait.
Published byGrace Bailey Modified over 7 years ago
1
Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB® to the reader. This early introduction has the purpose of familiarizing the reader with the basic operations of MATLAB so that the program may be used throughout the book to support the mathematical analysis.
2
Desktop Layout The screen shown on the next slide is based on Version7, Release 14. The Student Version of MATLAB comes with the Symbolic Mathematics Toolbox and the program Simulink. All examples in the text should work with the Student Version
4
Prompt MATLAB automatically inserts the prompt >> at the beginning of each line in the Command Window of the Professional Version. The corresponding prompt for the Student Version is EDU>>. We will assume the shorter prompt of the Professional Version throughout the text and the presence of the prompt on a line will alert the reader to the fact that a MATLAB command and possible results will follow.
5
Command Window The Command Window may be used on an interactive basis by simply typing in the commands after >> for the Professional Version or after EDU>> for the Student Version on a line-by-line basis. Depress Enter on the keyboard after each line is entered, and any results generated by the command will immediately appear on the screen unless the addition of a semicolon has suppressed the display or unless the command is part of a sequence.
6
Notational Conventions
In the MATLAB examples, we will usually display the results exactly as they appear on the screen. This means that the type style will be different from the standard mathematical style in the remainder of the book, but the symbols should be perfectly clear. Standard mathematical notation includes italicized symbols with subscripts and/or superscripts but MATLAB notation will be non-italicized without subscripts or superscripts.
7
Command Window versus M-files
The Command Window will allow you to work in a manner similar to that of a calculator. You can enter a command and see the numerical results immediately. The important thing is that it is interactive. This is in contrast to the writing of M-files, which is performed in a different window. An M-file is a form of computer program.
8
Clear Commands Clearing the screen: >> clc
Clearing all variables: >> clear Clearing a variable x: >> clear x
9
Spacing Blank spaces between distinct sections of a command line may be used to avoid a “crowded” appearance provided that they don't disrupt a particular command function or number. Thus, x=5 , x = 5, and x = 5 are all acceptable. However, if the number is 51, you will get an error message if you try to put a space between the 5 and the 1. Likewise a variable x1 cannot be expressed as x 1.
10
Basic Arithmetic Operations
In many of the slides that follow, basic arithmetic operations will be employed using simple numbers to illustrate the manner in which the command window can be used in much the same way as a calculator. To save space on the slides, many of the blank lines that appear on the computer screen will be eliminated.
11
Entering Numbers >> 5 ans = 5 >> x = 5 x = >> y = 3
12
Addition and Subtraction
>> z1 = 5 + 3 z1 = 8 >> z1 = x + y >> z2 = y - x z2 = -2
13
Checking on the Variables
>> whos Name Size Bytes Class x x double array y x double array z x double array z x double array This information may also be found in the Current Directory window.
14
Multiplication Multiplication is performed by placing an asterisk (*) between the numbers. >> z3 = 5*3 z3 = 15 >> z3 = x*y
15
Division Division of x by y is performed as follows: >> z4 = x/y
1.6667 An alternate form is as follows: >> z4 = y\x
16
Exponentiation Exponentiation is performed by using the symbol (^).
>> z5 = x^2 z5 = 25
17
Suppressing the Listing of Results
If it is desired to perform a computation and not show it on the screen, the command should be followed by a semicolon (;). For example, >>z6 = y^x; The value is in memory and may be seen by entering the variable name. >> z6 z6 = 243
18
Entering in Exponential Form
A microwave frequency of 15 GHz (1 GHz = 109 Hz) may be entered as >> f = 15e9 f = 1.5000e+010 Boltzmann’s constant k = 1.38x10-23 J/K may be entered as >> k = 1.38e-23 k = 1.3800e-023
19
Square Root >> z7 = sqrt(x) z7 = 2.2361
20
Hierarchy Without parentheses, the normal hierarchy of arithmetic operations is exponentiation, multiplication, division, addition, and subtraction. Parentheses may be used to change the order. When in doubt, it is prudent to add parentheses to ensure that the order is performed properly. The process of placing parentheses within parentheses is called nesting.
21
Consider the algorithm shown below.
1. Add 3 to x. 2. Square the result of step 1. 3. Multiply the result of step 2 by 6. 4. Add 8 to the result of step 3. 5. Take the square root of step 4 and the value obtained is y.
22
The algorithm may be implemented by MATLAB on a step-by-step basis.
>> u1 = 3 + x ; >> u2 = u1^2 ; >> u3 = 6*u2 ; >> u4 = 8+u3 ; >> y = sqrt(u4) y =
23
The algorithm may be implemented in one step using nesting.
>> y = sqrt(8+(6*((3+x)^2))) y =
24
Some MATLAB Constants >> pi ans = 3.1416 >> eps
>> sqrt(-1) i The next slide shows 4 ways to enter an imaginary number.
25
>> 5i ans = i >> 5j >> i*5 >> j*5
26
Division by Zero Divison by zero will either yield Inf (“infinity”) or NaN (“not a number”) depending on the form. As examples, if the command 1/0 is entered, the result is Inf, and if the command 0/0 is entered, the result is NaN.
27
Programming with M-Files
A computational procedure may need to be repeated for more than one set of input data and/or the code consists of a relatively long list of commands. In this case, it is usually more convenient to develop an M-file, which may be saved and used as often as desired. An M-file (or M-file script) is a MATLAB-based computer program for performing a particular analysis.
28
Programming with M-Files (Continuation)
Any of the commands that may be applied in the Command Window may be combined into an M-file program. Instructions for accepting input data for different cases may be added to the programs. To use the MATLAB editor, left-click on File and left-click on New. After preparing the file, it should be saved with the extension .m. Details are provided in the text.
29
Chapter 2 Matrices Matrices provide an orderly way of arranging values or functions to enhance the analysis of systems in a systematic manner. Their use is very important in simplifying large arrays of equations and in determining their solutions. In particular, computer algorithms for manipulating large arrays are simplified greatly by matrix notation and operations.
30
A particular reason for introducing matrices at this point is that MATLAB is heavily matrix oriented. One does not have to be an expert in matrix theory to utilize the powerful features of MATLAB, but it is very helpful to understand some of the terminology and manipulations. This chapter will deal with those basic elements of matrix theory that can be used for that purpose. The term linear algebra is often used to represent the general theory of matrices and the associated algebraic operations.
31
General Form of a Matrix of Size m x n with m Rows and n Columns
32
Square Matrix If m = n, the matrix is said to be square. In this case, the matrix could be designated as an m x m matrix.
33
Vectors A matrix having only one row is called a row matrix. A matrix having only one column is called a column matrix. A matrix of either form is called a vector. The row matrix is called a row vector and the column matrix is called a column vector.
34
Scalars A 1 x 1 matrix is called a scalar and is the form of most variables considered in simple algebraic forms.
35
Transpose The transpose of a matrix A is denoted as A’ and is obtained by interchanging the rows and columns. Thus, if A has a size of m x n, A’ will have a size of n x m. If the transpose operation is applied twice, the original matrix is restored.
36
Example 2-1. Determine the size of the matrix shown below.
The matrix has 2 rows and 3 columns. Its size is 2 x 3.
37
Example 2-2. Determine the size of the matrix shown below.
The matrix has 3 rows and 2 columns. Its size is 3 x 2.
38
Example 2-3. Determine the size of the matrix shown below.
The matrix has 3 rows and 3 columns. Its size is 3 x 3. It is a square matrix.
39
Example 2-4. Express the integer values of time from 0 to 5 s as a row vector.
The size of the vector is 1 x 6.
40
Example 2-5. Express the variables x1, x2, and x3 as a column vector.
41
Example 2-6. Determine the transpose of the matrix A below.
42
Addition and Subtraction of Matrices
Matrices can be added together or subtracted from each other if and only if they are of the same size. Corresponding elements are added or subtracted.
43
Multiplication of Two Matrices
Two matrices can be multiplied together only if the number of columns of the first matrix is equal to the number of rows of the second matrix. This means that
44
Multiplication of Two Matrices (Continuation)
The number of rows in the product matrix is equal to the number of rows in the first matrix and the number of columns in the product matrix is equal to the number of columns in the second matrix.
45
Multiplication of Two Matrices (Continuation)
An element in the product matrix is obtained by summing successive products of elements in the row of the first with elements of the column of the second.
46
Division of Matrices ? There is no such thing as division of matrices. However, matrix inversion can be viewed in some sense as a procedure similar to division. This process will be considered later.
47
Example 2-7. Determine C = A + B for the matrices shown below.
48
Example 2-8. Determine D = A - B for the matrices shown below.
49
Example 2-9. For the matrices of Examples 2-1 and 2-2, determine possible orders of multiplication.
50
Example 2-10. For the matrices of Examples 2-1 and 2-2, determine C=AB.
51
Example 2-10. Continuation.
52
Example 2-11. For the matrices of Examples 2-1 and 2-2, determine D=BA.
53
Determinants The determinant of a matrix A can be determined only for a square matrix. It is a scalar value. Various representations are shown as follows:
54
Determinant of 2 x 2 Matrix
55
Determinants of Higher-Order
For determinants of matrices of higher order than 2 x 2, the process can become tedious. There are many “tricks”, but some are useful only when the matrix has simple numbers. The text provides a procedure based on minors and cofactors, but since the ultimate goal is to use MATLAB, that procedure will not be covered on these slides. Instead, formulas for the 3 x 3 case will be provided.
56
Determinant of 3 x 3 Matrix
57
Singular Matrix If det(A)=0, the matrix is said to be singular. If the matrix represents the coefficients of a set of simultaneous equations, it means that the equations are not independent of each other and cannot be solved uniquely.
58
Example 2-13. Determine the determinant of the matrix shown below.
59
Examples 2-13, 2-14, and 2-15 These 3 examples involve computations concerning the minors and cofactors of a 3 x 3 matrix and will not covered in this presentation. The results that follow these computations will be considered in a later example.
60
Identity Matrix
61
Inverse Matrix The inverse of a matrix A is denoted by A-1 and is defined by the equation that follows.
62
Inverse of a 2 x 2 Matrix
63
Example 2-16. Determine the inverse of the matrix A below.
64
Example 2-17. The inverse of A below is developed in the text.
65
Simultaneous Linear Equations
66
Matrix Form of Simultaneous Linear Equations
67
Define variables as follows:
68
Matrix Solution Development
69
The general form and the final solution follow.
70
Example 2-18. Use matrices to solve the simultaneous equations below.
71
Example 2-18. Continuation.
72
Example 2-18. Continuation.
73
Transformation of Linear Variables
74
Transformation Continuation
75
Transformation Continuation
76
Example For the system of equations provided below, determine the z values in terms of the x values.
77
Example 2-19. Continuation.
78
Example 2-19. Continuation.
79
Chapter 3 Matrix Algebra with MATLAB
Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are performed in MATLAB. All variables in MATLAB are considered as matrices. A simple scalar is considered as a 1 x 1 matrix. For MATLAB variables containing higher dimensions, certain special rules are required to deal with them.
80
Entering a Matrix in MATLAB
MATLAB Format >> A = [2 -3 5; ] A =
81
Entering a Row Vector in MATLAB
MATLAB Format >> x = [1 4 7] x =
82
Entering a Column Vector in MATLAB
MATLAB Format >> x = [1; 4; 7] x = 1 4 7
83
Alternate Way to Enter a Column Vector
>> x = [1 4 7]' x = 1 4 7
84
Matrix Addition and Subtraction
Matrix addition and subtraction with MATLAB are achieved in the same manner as with scalars provided that the matrices have the same size. Typical expressions are shown below. >> C = A + B >> D = A - B
85
Error Messages MATLAB has many error messages that indicate problems with operations. If the matrices have different sizes, the message is ??? Error using ==> Matrix dimensions must agree.
86
Matrix Multiplication
Matrix multiplication with MATLAB is achieved in the same manner as with scalars provided that the number of columns of the first matrix is equal to the number of rows of the second matrix. A typical expression is >> E = A*B
87
Array Multiplication There is another form of multiplication of matrices in which it is desired to multiply corresponding elements in a fashion similar to that of addition and subtraction. This operation arises frequently with MATLAB, and we will hereafter refer to the process as the array product to distinguish it from the standard matrix multiplication form.
88
Array Multiplication Continuation
For the array product to be possible, the two matrices must have the same size, as was the case for addition and subtraction. The resulting array product will have the same size. If F represents the resulting matrix, a given element of F, denoted by fij is determined by the corresponding product from the two matrices as
89
MATLAB Array Multiplication
To form an array product in MATLAB, a period must be placed after the first variable. The operation is commutative. The following two operations produce the same result. >> F=A.*B >> F=B.*A
90
MATLAB Array Multiplication Continuation
If there are more than two matrices for which array multiplication is desired, the periods should follow all but the last one in the expression; e. g., A.*B.*C in the case of three matrices. Alternately, nesting can be used; e.g. (A.*B).*C for the case of three matrices.
91
MATLAB Array Multiplication Continuation
The array multiplication concept arises in any operation in which the command could be “confused” for a standard matrix operation. For example, suppose it is desired to form a matrix B from a matrix A by raising each element of A to the 3rd power, The MATLAB command is >> B = A.^3
92
Determinant of a Matrix
The determinant of a square matrix in MATLAB is determined by the simple command det(A). Thus, if a is to represent the determinant, we would type and enter >> a = det(A) Note that a is a scalar (1 x 1 "matrix").
93
Inverse Matrix The inverse of a square matrix in MATLAB is determined by the simple command inv(A). Thus, if B is to represent the inverse of A , the command would be >> B = inv(A)
94
Simultaneous Equation Solution
MATLAB Format: >> x = inv(A)*b Alternate MATLAB Format: >> x = A\b
95
Example 3-1. Enter the matrices below in MATLAB
Example 3-1. Enter the matrices below in MATLAB. They will be used in the next several examples. >> A = [2 -3 5; ]; >> B = [2 1; 7 -4; 3 1];
96
Example 3-2. Determine the transpose of B and denote it as C.
>> C = B' C = The 3 x 2 matrix has been converted to a 2 x 3 matrix.
97
Example 3-3. Determine the sum of A and C and denote it as D.
>> D = A + C D =
98
Example 3-4. Determine the product of A and B with A first.
>> A*B ans =
99
Example 3-5. Determine the product of B and A with B first.
ans =
100
Example 3-6. Determine the array product of A and C and denote it as E.
>> E = A.*C E =
101
Example 3-7. Enter the matrix A. It will be used in several examples.
102
Example 3-7. Continuation
Example 3-7. Continuation. Determine the determinant of A and denote it as a. >> a = det(A) a = 20
103
Example 3-8. Determine the inverse matrix of A and denote it as Ainv.
>> Ainv = inv(A) Ainv =
104
Example 3-9. Use MATLAB to solve the simultaneous equations below.
105
Example 3-9. Continuation.
Assume that A is still in memory. >> b = [-8; 7; 4] b = -8 7 4
106
Example 3-9. Continuation.
>> x = inv(A)*b x = 2.0000 4.0000
107
Example 3-9. Continuation.
Alternately, >> x = A\b x = 2.0000 4.0000
108
Chapter 4 Curve Plotting with MATLAB
MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed as part of an overall mathematical analysis, or experimental data may be provided to the program for the primary purpose of plotting. Curves obtained from MATLAB plots can be exported to other programs for presentation purposes.
109
MATLAB has the capability to generate plots of many types
MATLAB has the capability to generate plots of many types. This includes linear plots, line plots, logarithmic plots on both scales, logarithmic plots on one scale, stem plots, bar graphs, and three-dimensional plots. We will be using these capabilities throughout the text, so the present development is intended as an introduction, with many operations to follow in later chapters.
110
Vector Lengths A very important fact that should be emphasized at the outset is that to plot one vector against another, the vectors must have the same number of elements. One can plot either a column vector or a row vector versus either a column vector or a row vector provided they have the same number of values.
111
Different Vector Lengths
If the vectors have different lengths, it is possible to use a portion of the longer one as one of the variables. For example, suppose y has 200 values and x has 120 values. One could define y1 by the following command: >> y1 = y(1:120) The variable y1 now has the same number of points as x and the two could be plotted together.
112
The Variables x and y In the two-dimensional plotting commands, the horizontal axis will be referred to as the x-axis and the vertical axis will be referred to as the y-axis. However, the actual variables can be labeled with any quantities. It is only in the plot commands that x and y are used.
113
Creating a Linear Array
Whenever a plot is to be created from an equation, and linear plots for both the dependent and independent variables are desired, the most convenient way to achieve the result is to create a linear array or vector for the values of the independent variable. MATLAB offers a number of different commands that can be used for this purpose. For this explanation, assume that the independent variable is x.
114
Command for Linear Array
>> x = x1:xstep:x2 where x1=beginning point, x2=final point, and xstep=step size. Assuming that the final point coincides with an integer multiple of xstep, the number of points N is
115
Alternate Command for Linear Array
>> x = linspace(x1, x2, N) where x1=beginning point, x2=final point, and N=number of points. The name linspace represents “linear spacing”. Again, the number of points N is
116
Example 4-1. When air resistance can be ignored, the velocity (in m/s) of an object falling from rest is Use MATLAB to plot the velocity over a time interval from 0 to 10 s.
117
Example 4-1. Continuation.
It should be emphasized that this is a simple linear equation with a vertical intercept of 0 so we actually need only two points to plot the curve. However, our purpose is to learn how to use MATLAB for plotting and we will utilize far more points than necessary as a learning process.
118
Example 4-1. Continuation.
A time step of 0.1 s will be selected. >> t = 0:0.1:10; Alternately, >> t = linspace(0,10,101);
119
Example 4-1. Continuation. We can inspect various values of t.
ans =
120
Example 4-1. Continuation.
>> v = 9.8*t; This command generates 101 values of v corresponding to the 101 values of t. It can be plotted by the command >> plot(t, v) The result is a “raw” plot but various labels can be added as will be shown on the next slide.
122
Example 4-1. Continuation.
A horizontal label is provided. >> xlabel(‘Time, seconds’) A vertical label is provided. >> ylabel(‘Velocity, meters/second’) A title is provided. >> title(‘Figure 4-3. Velocity of falling object of Example 4-1 with grid.’) A grid is added. >> grid
124
Example 4-2. A force in newtons (N) is given below. Plot the function.
Assume 101-point t vector is in memory. >> f1 = 0.25*t.*t; or >> f1 = 0.25*t.^2: >> plot(t, f1) >> xlabel(‘Time, seconds’) >> ylabel(‘Force, newtons’) >> title(‘Figure 4-4. Force as a function of time in Example 4-2.’) >> grid
126
Example 4-3. A force in newtons (N) is given below. Plot the function.
Assume 101-point t-vector is in memory. >> f2 = *t.^2; >> plot(t, f2) >> xlabel(‘Time, seconds’) >> ylabel(‘Force, newtons’) >> title(‘Figure 4-6. Second force as initially obtained in Example 4-3.’) >> grid
128
Example 4-3. Continuation.
Plot is modified by the command >> axis([ ])
130
Multiple Plots on Same Graph
The two functions f1 and f2 of the previous two examples can be plotted on the same graph by the command >> plot(t, f1, t, f2) The command gtext(‘label’) allows a label to placed on a graph using crosshairs. The resulting functions are shown on the next slide.
132
Log-Log Plots
133
Example 4-5. Plot the 2nd degree function below on a log-log graph.
>> x = logspace(-1, 1, 100); >> y = x.^2; >> loglog(x, y) A grid and additional labeling were provided and the curve is shown on the next slide.
135
Bar and Stem Plots Command for a bar plot: >> bar (x, y)
Command for a stem plot: >> stem (x, y)
136
Example 4-6. The text contains the sales in thousands of dollars for a small business from 1993 through Construct a bar graph. >> year = 1993:2002; >> sales = [ the 10 values in the text]; >> bar(year, sales) The graph with additional labeling is shown on the next slide.
138
Example 4-7. Plot the data of the previous example using a stem plot.
Assume that the variables year and sales are still in memory. The command is >> stem (year, sales) The plot with additional labeling is shown on the next slide.
140
Chapter 5 Common Functions and their Properties
The concept of functions is a very basic part of mathematics and one that appears in all forms of algebra, trigonometry, and calculus. While there are hundreds of different types of mathematical functions, certain common ones tend to occur quite often in applied engineering and scientific applications. In this chapter, we will explore some of these most common functions and study their behavior.
141
Now that basic MATLAB matrix operations and curve plotting have been covered, much of the work that follows will provide coverage of the MATLAB commands immediately after introducing the mathematical forms. This will be the norm where the commands are fairly simple and are best introduced after discussing the mathematical form. In particular, the need to plot curves of functions immediately after introducing the functions will be best achieved with MATLAB commands.
142
Functions A function is a relationship between two or more variables. At this point in the text, we will consider only the variables x and y for a given function. In most cases, we will consider that x is the independent variable and y is the dependent variable. This does not necessarily mean that x causes y in all cases, but it suggests that we first assign a value of x and then determine the value or values of y.
143
Horizontal and Vertical Axes
Normally, x is assigned to the horizontal axis and y is assigned to the vertical axis. The general notation indicating that y is a function of x will take the form y=f(x) and letters other than f may be used when there are several functions. Alternately, subscripts may be added to different functions to give them separate identities. Sometimes, we will use the simpler notation y=y(x) to mean the same thing.
144
Single-Valued versus Multi-Valued
A single-valued function is one in which a single value of x results in a single value of y. A multi-valued function is one in which a single value of x results in more than one value of y. An example of a single-valued function is shown in Figure 5-1(a), and a multi-valued function is shown in Figure 5-1(b). Both appear on the next slide.
146
Continuous versus Discontinuous
The definition of a continuous function is one in which at any value of the independent variable, approaching the value from the left results in the same dependent value as approaching the value from the right. An example of a continuous function is shown in Figure 5-2(a), and a function that has one finite discontinuity is shown in Figure 5-2(b). Both appear on the next slide.
148
Domain and Range Assume that a function is being evaluated over specific limits such as from x1 to x2. This portion of the x-axis is called the domain. All values of the dependent variable y that are produced in the process are called the range. In casual usage, engineers and technologists tend to refer to both as ranges.
149
Inverse Functions If we have a function y=f(x), and we can reverse the process and solve for x in terms of y, we have the inverse function. For the moment, we will denote the inverse simply as x=g(y). We will retain the original variable names and then consider y as the independent variable and x as the dependent variable.
150
Even and Odd Functions An even function is one that satisfies
f(-x)=f(x) Figures 5-4 and 5-6 are even functions. An odd function is one that satisfies f(-x)=-f(x) Figures 5-5 and 5-7 are odd functions.
151
Example 5-1. Determine if the function below is single-valued or multi-valued.
With x as the independent variable and y as the dependent variable, there is only one value of y for a given value of x. Hence the function is single-valued.
152
Example 5-2. Is the function of Example 5-1 even, odd, or neither.
Since f(-x)=f(x), the function is even.
153
Example 5-3. Determine the inverse of the function of Example 5-1.
We now consider y as the independent variable and x as the dependent variable.
154
Example 5-4. Is the inverse function of Example 5-3 single-valued or multi-valued?
Since two values of x result from a given value of y, the inverse function is multi-valued. This tells us that a function may be single-valued but its inverse may be multi-valued or vice-versa. In many applications, only the positive square root would be of interest, so if the negative square root is rejected, we could interpret the result as being single-valued.
155
Example 5-5. Is the inverse function of Example 5-3 even, odd, or neither?
The inverse function is neither even nor odd.
156
MATLAB Subplot The subplot allows more than one plot to be prepared on the same printer page. In fact, Figures 5-1 and 5-2 were both prepared using that command.The syntax for the subplot command is as follows: >> subplot(m, n, k) Integers m and n define the number of rows and columns of subplots. The integer k defines the particular one based on left to right and top to bottom.
157
Example 5-6. Plot the function of Example 5-1 and the inverse of Example 5-3 using subplots.
>> x = linspace(-2, 2, 201); >> y = x.^2-1; >> subplot(2, 1, 1) >> plot(x, y) Additional labeling commands were used. >> subplot(2, 1, 2) >>plot(y, x)
159
Power and Polynomial Functions
164
Straight-Line Equation
The quantity m is the slope of the line and b is the vertical intercept. For m>0, the slope is upward and for m<0, the slope is downward. The line crosses the vertical axis at a value b.
165
Example 5-7. Write the equation and plot the line having a slope of 2 and a vertical intercept of -4. This case is about as simple as any can be since we are given the two parameters required in the slope/vertical intercept form. The straight-line is shown on the next slide.
167
Example 5-8. Write the equation and plot the line passing through the points (3, 5) and (6, -7).
169
Polynomial Functions A polynomial function is one composed of a sum of power terms of the form of xn with integer values of n and constant factors. A typical polynomial function of degree N can be expressed in the following form:
170
Roots of a Polynomial Function
A root of a polynomial equation is a value of x such that the polynomial is zero when it is evaluated for that particular value of x. This means that for any root xk of the polynomial p(x) on the previous slide, the following equation is satisfied:
171
Theorem on Roots A polynomial of degree N has exactly N roots. These roots may be classified as 1. Real roots of first order 2. Complex roots of first order 3. Real roots of multiple order 4. Complex roots of multiple order In this classification scheme, purely imaginary roots may be considered as a special case of complex roots.
172
Complex Roots For real polynomial coefficients, any complex roots appear in conjugate pairs. Thus, if a+ib is a root, a-ib will also be a root. The value a-ib is the complex conjugate of a+ib. The quantity i is the basis for the complex number system and is given by
173
Factored Form of a Polynomial
174
MATLAB Evaluation of Polynomial
Assume that the vector x has been entered. To illustrate for the third degree case, one way to evaluate is shown below. >> y = A3*x.^3 + A2*x.^2 + A1*x + A0 An easier way will be shown on the next slide.
175
Easier MATLAB Procedure for Polynomial Evaluation
Define a row vector C as follows: >> C = [A3 A2 A1 A0]; The polynomial will be evaluated at all values of x by the command >> y = polyval(C, x)
176
Factoring of Polynomials
Define a row vector C as follows: >> C = [A3 A2 A1 A0]; The roots will be determined by the command >> R =roots(C) The vector R as is a column vector whose values are the roots of the polynomial.
177
Forming the Polynomial from the Roots
Assume that the roots of a polynomial are formed as either a row or a column vector and denoted as R. The coefficient matrix C of the polynomial is determined by >> C = poly(R) If the coefficient of the highest degree term is other than one, it is necessary to modify C as follows: >> C = AN*C
178
Multiplication of Polynomials
Two polynomials can be multiplied together by the use of the conv command. The term conv is a contraction of the term convolution which has applications in signal processing and in both differential and difference equations. To illustrate, assume two 2nd degree polynomials.
179
Multiplication of Polynomials Continuation
Form row vectors for the coefficients. >> C1 = [A2 A1 A0]; >> C2 = [B2 B1 B0]; The coefficient matrix of the product polynomial is obtained by the command that follows. C3 = conv(C1, C2)
180
Example 5-9. Use MATLAB to determine the roots of
>> C = [ ]; >> R = roots(C) R = i i
181
Example Reconstruct the coefficients of the polynomial from the roots of the preceding example. >> C1 = 3*poly(R) C1 = We could use the polyval command to evaluate the polynomial if desired.
182
Example 5-11. Determine the roots of the 5th degree polynomial below.
>> C=[ ]; >> R = roots(C) R = i i i i
183
Example 5-12. Reconstruct the polynomial of Example 5-11 from the roots.
Assume that the 5 roots are still in memory as a vector. >> C1 = poly(R) C1 =
184
Example 5-13. Evaluate the 5th degree polynomial for x = 0, 0
Example Evaluate the 5th degree polynomial for x = 0, 0.5, 1, and 2. Assume that C is still in memory. >> x = [ ]; >> y = polyval(C, x) y =
185
Exponential Function to the Base e
The basic exponential function arises in a large number of scientific and engineering problems. The "purest" form of the exponential is as a power of the mathematical constant e=2.718 to four significant digits. The form of the function for both positive and negative x is shown on the next slide.
187
Decaying Exponential Function
The most common form of the exponential function in practical engineering problems is the decaying or damped exponential function. Many applications involve time as the independent variable and the forms are shown below and on the next slide.
189
MATLAB Exponential Forms
Assume that a vector x is in memory. MATLAB uses exp for e and the command to generate y is >> y = exp(x) If a base other than e is desired, the exponentiation operation is used. For example, if the base is 10, the command is >> y = 10.^x
190
Example 5-14. Consider the exponential function shown below.
Determine (a) the time constant and (b) the damping constant. (c). Based on the rule-of-thumb provided in the text, about how long would it take to reach a practical level of zero?
191
Example 5-14. Continuation.
192
Example A force f begins with 20 N and decays exponentially with a time constant of 5 s. Write the equation.
193
Example 5-16. Generate the two curves of Figure 5-11 and plot them.
One is the exponential function and the other is the straight-line y1 = 1 - x. >> x = linspace(0, 5, 501); >> y = exp(-x); >> x1 = linspace(0, 1, 11); >> y1 = 1-x1; >> plot(x, y, x1, y1) Other routine labeling was provided on Figure 5-11.
194
Logarithmic Function The logarithmic function is the inverse of the exponential function. However, because it arises in many applications, it will be represented in the usual form with x as the independent variable and y as the dependent variable. The mathematical form is provided below and a curve is shown on the next slide.
196
Logarithms to Other Bases
In general, the logarithm to a base a other than e is determined by the first equation below. The base 2 and the base 10 are also considered.
197
MATLAB Logarithmic Commands
The logarithm to the base e in MATLAB is >> y = log(x) This could be confusing since some math books use log(x) to mean to the base 10. The logarithm to the base 10 in MATLAB is >> y = log10(x)
198
Example 5-17. Some definitions are provided below.
Use MATLAB to develop a conversion curve in which G varies from 0.01 to 100. Use a semi-log plot with G on the horizontal logarithmic scale and GdB on the vertical linear scale.
199
Example 5-17. Continuation.
The command to generate G on a logarithmic scale from 0.01 to 100 is >> G = logspace(-2, 2, 200); The decibel gain is generated by >> GdB = 10*log10(G); A logarithmic x scale and a linear y scale are generated by the command >> semilogx(G, GdB) A grid and additional labeling are provided and the curve is shown on the next slide.
201
Example 5-18. Plot the absolute gain versus the decibel gain from Example 5-17.
We could solve for G in terms of GdB, but that is unnecessary since we have both G and GdB in memory. We simply reverse the order of the variables and change semilogx to semilogy. The command is >> semilogy(GdB, G) The plot with additional labeling is shown on the next slide.
203
Example 5-19. Use MATLAB to plot the gaussian function shown below over the domain from -3 to 3.
>> a = 1/(sqrt(2*pi)); >> x = linspace(-3,3,301); >> y = a*exp(-0.5*x.^2); >> plot(x, y) With additional labeling, the curve is shown on the next slide.
205
Trigonometric Functions
There are six basic trigonometric functions: (1) sine, (2) cosine, (3) tangent, (4) cotangent, (5) secant, and (6) cosecant. However, the first three tend to occur more often in practical applications than the latter three. Moreover, the latter three can be expressed as reciprocals of the first three (not in the order listed). Therefore, we will focus on the first three, but the definitions of the latter three will be provided for reference purposes.
206
Angle Measurement The most basic mathematical unit for an angle is the radian (rad). It does have a mathematical basis for its form and does arise as a natural process. One complete revolution for a circle corresponds to 2 radians. To convert between radians and degrees, the following formulas can be used:
207
Figure 5-16. Right-triangle used to define trigonometric functions.
208
Trigonometric Definitions
209
Sine Function The form of the sine function over the domain from 0 to 2 is shown on the next slide.The function is periodic, meaning that it repeats the pattern shown for both positive and negative x. The domain shown constitutes one cycle of the periodic function and the period on an angular basis is 2 radians. The sine function is an odd function.
211
Cosine Function The form of the cosine function over the domain from 0 to 2 is shown on the next slide. As in the case of the sine function, the cosine function is periodic with a period of 2 radians on an angular basis. The cosine function is an even function.
213
Tangent Function The form of the tangent function over the domain from 0 to 2 is shown on the next slide.This function is periodic, but there are two cycles shown in the given domain. Hence, the tangent function is periodic with a period of radians on an angular basis. The tangent function is an odd function. Moreover, it has infinite discontinuities at odd integer multiples of /2.
215
MATLAB Trigonometric Functions
The 6 MATLAB commands are >> y = sin(x) >> y = cos(x) >> y = tan(x) >> y = cot(x) >> y = sec(x) >> y = csc(x)
216
Sinusoidal Time Functions
217
Period and Frequency For either the sine or cosine, the quantity is the number of radians per second that the function undergoes in the argument. This quantity is called the angular velocity in mechanics and is called the angular frequency in electricity. It is related to the cyclic frequency by the relationship
218
Combining Sine and Cosine Functions at the Same Frequency
The sum of a sine and a cosine function at the same frequency may be expressed as either a sine or a cosine function with an angle. The angle may be determined from the phase diagram on the next slide.
220
Example 5-20. Use MATLAB to plot the function below over two cycles.
>> x = linspace(0, 2, 201); >> y = 20*sin(2*pi*x+pi/6); >> plot(x, y) The plot is shown on the next slide.
222
Chapter 6 Differential Calculus
The two basic forms of calculus are differential calculus and integral calculus. This chapter will be devoted to the former and Chapter 7 will be devoted to the latter. Finally, Chapter 8 will be devoted to a study of how MATLAB can be used for calculus operations.
223
Differentiation and the Derivative
The study of calculus usually begins with the basic definition of a derivative. A derivative is obtained through the process of differentiation, and the study of all forms of differentiation is collectively referred to as differential calculus.If we begin with a function and determine its derivative, we arrive at a new function called the first derivative. If we differentiate the first derivative, we arrive at a new function called the second derivative, and so on.
224
The derivative of a function is the slope at a given point.
225
Various Symbols for the Derivative
226
Figure 6-2(a). Piecewise Linear Function (Continuous).
227
Figure 6-2(b). Piecewise Linear Function (Finite Discontinuities).
228
Piecewise Linear Segment
229
Slope of a Piecewise Linear Segment
230
Example 6-1. Plot the first derivative of the function shown below.
232
Development of a Simple Derivative
233
Development of a Simple Derivative Continuation
234
Chain Rule where
235
Example 6-2. Approximate the derivative of y=x2 at x=1 by forming small changes.
236
Example 6-3. The derivative of sin u with respect to u is given below.
Use the chain rule to find the derivative with respect to x of
237
Example 6-3. Continuation.
238
Table 6-1. Derivatives
239
Table 6-1. Derivatives (Continued)
240
Example 6-4. Determine dy/dx for the function shown below.
241
Example 6-4. Continuation.
242
Example 6-5. Determine dy/dx for the function shown below.
243
Example 6-6. Determine dy/dx for the function shown below.
244
Higher-Order Derivatives
245
Example 6-7. Determine the 2nd derivative with respect to x of the function below.
246
Applications: Maxima and Minima
1. Determine the derivative. 2. Set the derivative to 0 and solve for values that satisfy the equation. 3. Determine the second derivative. (a) If second derivative > 0, point is a minimum. (b) If second derivative < 0, point is a maximum.
247
Displacement, Velocity, and Acceleration
248
Example 6-8. Determine local maxima or minima of function below.
249
Example 6-8. Continuation.
For x = 1, f”(1) = -6. Point is a maximum and ymax= 6. For x = 3, f”(3) = 6. Point is a minimum and ymin = 2.
250
Chapter 7 Integral Calculus
The basic concepts of differential calculus were covered in the preceding chapter. This chapter will be devoted to integral calculus, which is the other broad area of calculus. The next chapter will be devoted to how both differential and integral calculus manipulations can be performed with MATLAB.
251
Anti-Derivatives An anti-derivative of a function f(x) is a new function F(x) such that
252
Indefinite and Definite Integrals
253
Definite Integral as Area Under the Curve
254
Exact Area as Definite Integral
255
Definite Integral with Variable Upper Limit
More “proper” form with “dummy” variable
256
Area Under a Straight-Line Segment
257
Example 7-1. Determine
258
Example 7-1. Continuation.
259
Example 7-2. Determine
260
Guidelines 1. If y is a non-zero constant, integral is either increasing or decreasing linearly. 2. If segment is triangular, integral is increasing or decreasing as a parabola. 3. If y=0, integral remains at previous level. 4. Integral moves up or down from previous level; i.e., no sudden jumps. 5. Beginning and end points are good reference levels.
262
Tabulation of Integrals
263
Table 7-1. Common Integrals.
264
Table 7-1. Continuation.
265
In Examples 7-3 through 7-5 that follow, determine the following integral in each case:
266
Example 7-3
267
Example 7-4
268
Example 7-5
269
In Examples 7-6 and 7-7 that follow, determine the definite integral in each case as defined below.
270
Example 7-6
271
Example 7-7
272
Displacement, Velocity, and Acceleration
273
Displacement, Velocity, and Acceleration Continuation
274
Alternate Formulation in Terms of Definite Integrals
275
Example 7-8. An object experiences acceleration as given by
Determine the velocity and displacement.
276
Example 7-8. Continuation.
277
Example 7-8. Continuation.
278
Example 7-9. Rework previous example using definite integral forms.
279
Example 7-10. Plot the three functions of the preceding examples.
280
Example 7-10. Continuation.
>> a = 20*exp(-2*t); >> v = *exp(-2*t); >> y = 10*t + 5*exp(-2*t) - 5; >> plot(t, a, t, v, t, y) The plots are shown on the next slide.
282
Chapter 8 Calculus Operations with MATLAB
We are now ready to see how calculus operations can be performed with MATLAB. It should be noted that a digital computer operates on a numerical basis with addition, subtraction, multiplication, and division, along with memory storage and logic. True differentiation and integration can never be achieved exactly with numerical processes. However, there are two ways that differentiation and integration can be achieved on a practical level with MATLAB.
283
Two Types of Operations
First, MATLAB can be viewed as a very comprehensive "look-up" table in that numerous derivatives and integrals as character strings can be manipulated with software. The Symbolic Math Toolbox permits the exact formulas for derivatives and integrals to be extracted, manipulated, and plotted.
284
Two Types of Operations (Continued)
Second, MATLAB can be used for calculus with numerical approximations to differentiation and integration. While such approximations are not exact, they can be used to provide extremely close approximations to the derivatives and integrals of experimental data, even when closed form solutions are impossible.
285
Symbolic Variables A symbolic variable is one that can be manipulated in the same manner as in an equation, and it may or may not ever take on any numerical values. To make x and a symbolic, the command is >> syms x a Alternately, the symbolic portion of a command may be enclosed with apostrophes ' '.
286
Symbolic Differentiation
The command is diff( ) with the function to be differentiated in parentheses. All variables should have been established as symbolic variables or the function should be enclosed by apostrophes.
287
Example 8-1. Use MATLAB to determine derivative of function below.
>> syms x >> y = 4*x^5 y = 4*x^5 >> yprime = diff(y) yprime = 20*x^4
288
Example 8-1. Continuation.
Second Approach: >> yprime = diff(4*x^5) yprime = 20*x^4
289
Example 8-1. Continuation.
Third Approach: >> y = '4*x^5' y = 4*x^5 >> yprime = diff(y) yprime = 20*x^4
290
Example 8-1. Continuation.
The third approach could also be performed in one step. >> yprime = diff('4*x^5') yprime = 20*x^4
291
Example 8-2. Use ezplot to plot y and yprime of Example 8-1.
The simplest form is ezplot(y), but the domain will be from -2 to 2. The domain can be changed by >> ezplot(y, [x1 x2]) In this example, ezplot(y, [-1 1]) ezplot(yprime,[-1 1]) The plots after labeling are shown on the next two slides.
294
Symbolic Integration The command is int( ) with the function to be integrated in parentheses. All variables should have been established as symbolic variables or the function should be enclosed by apostrophes. Indefinite Integral: >> yint = int(y) Definite Integral: >> yint = int(y, a, b)
295
Example 8-3. Use MATLAB to determine integral of function below.
>> syms x >> y = x^2*exp(x) y = x^2*exp(x) >> z = int(y) z = x^2*exp(x)-2*x*exp(x)+2*exp(x)
296
Example 8-3. Continuation.
We require that z(0) = 0, but the function obtained has a value of 2 at x = 0. Thus, >> z = z - 2 z = x^2*exp(x)-2*x*exp(x)+2*exp(x)-2 Plots of y and z are shown on the next two slides.
299
Numerical Differentiation
Generally, numerical differentiation is more prone to error than numerical integration due to the nature of “sudden changes” in differentiation.
300
Diff Command for Numerical Data
Assume that x and y have been defined at N+1 points. A vector u with N points is defined as
301
Diff Command for Numerical Data. Continuation.
The following command forms u: >> u = diff(y) To approximate derivative, >> yprime = diff(y)/delx Because x and y have one more point than yprime, they can be adjusted. >> x = x(1:N) >> y = y(1:N) >> plot(x, y, x, yprime)
302
Example 8-5(a) For y = sin x, determine numerical derivative based on 11 points in one cycle.
>> x = linspace(0, 2*pi, 11); >> y = sin(x); >> delx = 2*pi/10; >> yprime = diff(y)/delx; >> x = x(1:10); >> plot(x, yprime, x, cos(x),’o’) The plots are shown on the next slide.The approximation is “crude” as expected.
304
Example 8-5(b) For y = sin x, determine numerical derivative based on 101 points in one cycle.
>> x = linspace(0, 2*pi, 101); >> y = sin(x); >> delx = 2*pi/100; >> yprime = diff(y)/delx; >> x = x(1:100); >> plot(x, yprime, x, cos(x),’o’) The plots are shown on the next slide.The approximation is much better.
306
Numerical Integration
Two types will be studied: 1. Zero-order integration 2. First-order integration, which is also known as the trapezoidal rule. Assume vectors x and y that have each been defined at N points.
307
Zero-Order Integration
308
Two Zero-Order MATLAB Commands
The two MATLAB commands for zero-order integration are sum() and cumsum(). >> area = delx*sum(y) >> z = delx*cumsum(y)
309
First-Order Integration
310
Two First-Order MATLAB Commands
The two MATLAB commands for first-order integration are trapz() and cumtrapz(). >> area = delx*trapz(y) >> z = delx*cumtrapz(y)
311
Example 8-6(a). Determine exact area A for following integral:
312
Example 8-6(b). Determine approximate area A1 with zero-order integration algorithm and step-size of 0.05. >> delx = 0.05; >> x = 0:delx:2; >> y = 4*x.^3; >> A1 = delx*sum(y) A1 =
313
Example 8-6(c). Determine approximate area A2 with first-order integration algorithm and step-size of 0.05. >> delx = 0.05; >> x = 0:delx:2; >> y = 4*x.^3; >> A2 = delx*trapz(y) A2 =
314
Example 8-7(a). Determine the exact running integral for the following function:
315
Example 8-7(b) and (c). Determine first-order approximation with 100 points per cycle and plot the two functions. >> delx = 2*pi/100; >> x = 0:delx:2*pi; >> y = sin(x); >> z1 = delx*cumtrapz(y); >> plot(x, z1, x, 1 - cos(x), ‘o’) The plots are shown on the next slide.
317
Example 8-8 A test is performed on a mechanical part and the acceleration versus time is measured and shown on the next slide. Use MATLAB to determine and plot the velocity and displacement as a function of time.
318
Acceleration versus Time Data
319
MATLAB Analysis >> delt = 0.1; >> t = 0:delt:2;
>> a = [ the 21 values of a]; >> v = delt*cumtrapz(a); >> y = delt*cumtrapz(v); >> plot(t,a,t,v,t,y) Additional labeling was provided and the curves are shown on the next slide.
321
Chapter 9 Differential Equations: Classical Methods
A differential equation (DE) may be defined as an equation involving one or more derivatives of an unknown dependent variable or several variables with respect to one or more independent variable or variables.
322
Linear DE versus Non-Linear DE
A linear differential equation is one in which the dependent variable and its derivatives with respect to the independent variable are of the first degree and all multiplicative factors are either constants or functions of the independent variable. An example follows.
323
Two Examples of Non-Linear Differential Equations
324
Ordinary DE versus Partial DE
The preceding equations have been ordinary types since the dependent variable was a function of only one independent variable. An example of a partial differential equation follows.
325
Continuous-Time versus Discrete-Time
The preceding definitions relate to continuous-time or "analog” systems. However, the same forms may be adapted to discrete-time or "digital" systems. In such cases, the equations are generally known as difference equations. Most numerical methods involve approximating differential equations as difference equations.
326
Boundary Conditions or Initial Conditions
The solution of an Nth order DE usually involves N arbitrary constants. These constants are determined from the boundary conditions. When these conditions are specified as the initial value of the function and the first N-1 derivatives, they are called initial conditions.
327
Example 9-1. Classify the following DE in several ways:
The DE is linear since none of the coefficients are functions of y and there are no higher degree terms in y or its derivatives. The DE is an ordinary type since y is a function only of t.
328
Constant Coefficient Linear Ordinary Differential Equation (CCLODE)
329
Example 9-2. Classify the DE below.
This DE is a CCLODE type. It is a 4th order DE.
330
Simple Integrable Forms
In theory, this equation may be solved by integrating both sides k times. It may be convenient to introduce new variables so that only first derivative forms need be integrated at each step.
331
Example 9-3. An object is dropped from a height h at t = 0
Example 9-3. An object is dropped from a height h at t = 0. Determine velocity v and displacement y.
332
Example 9-3. Continuation.
333
Example 9-4. Consider situation below and solve for velocity and displacement in both x and y directions.
334
Example 9-4. Continuation.
335
Example 9-4. Continuation.
336
Example 9-4. Continuation.
337
Example 9-4. Continuation.
338
Constant Coefficient Linear Ordinary Differential Equations (CCLODE)
The general solution consists of a homogeneous solution plus a particular solution. The homogeneous solution is also called the complementary solution.
339
Homogeneous Equation
340
Homogeneous Solution
341
Characteristic Equation
Substitute the form on the previous slide in the DE and cancel the common exponential factor. The result is the characteristic equation shown below.
342
Homogeneous Solution Form
The m roots of the characteristic equation are determined, and the form of the homogeneous solution for non-repeated roots is shown below. Note that if f(t) = 0, this result is the complete solution.
343
Particular Solution The particular solution depends on the form of f(t). Assuming non-repeated roots, the table below shows the forms involved.
344
Combining Particular and Homogeneous Solutions
1. The form of the particular solution is substituted in the DE and its constants are determined. 2. The homogeneous and particular solutions are combined and the arbitrary constants from homogeneous solution are determined from boundary or initial conditions.
345
Example 9-5. Solve DE given below.
346
Example 9-6. Solve DE given below.
347
Example 9-7. Solve DE given below.
348
Example 9-7. Continuation.
349
Example 9-7. Continuation.
350
Example 9-8. Solve DE given below.
351
Example 9-8. Continuation.
352
Example 9-9. Solve DE given below.
353
Example 9-9. Continuation.
354
Some General Properties of Systems Described by CCLODEs
355
Stability A system is said to be stable if its natural response approaches zero as the time increases without limit. If this condition is met, the system will be stable for any finite forcing response. For a stable system, the terms below are often used.
356
Classification of Roots of the Characteristic Equation
1. first-order and real 2. first-order and complex (including purely imaginary) 3. multiple-order and real 4. multiple-order and complex (including purely imaginary)
357
Example 9-10. Investigate properties of DE below.
358
Example 9-10. Continuation.
The system is stable since both of the terms in the homogeneous solution approach zero as time increases. Since the system is stable, the natural response is a transient response, and the forced response is a steady-state response.
359
Second-Order Systems There are three cases: (1)roots are real and different, (2) roots are real and equal, and (3) roots are complex (including purely imaginary).
360
Three Forms for Stable Systems
361
Relative Damping 1. If the roots are real and unequal, the system is said to be overdamped. 2. If the roots are real and equal, the system is said to be critically damped. 3. If the roots are complex, the system is said to be underdamped. 4. A special case of an underdamped system is when there is no damping. the system is then said to be undamped.
362
Example 9-11. Solve DE given below.
363
Example 9-11. Continuation.
364
Example 9-12. Solve DE given below.`
365
Example 9-12. Continuation.
366
Chapter 10 Differential Equations: Laplace Transform Methods
The Laplace transform was developed by the French mathematician by the same name ( ) and was widely adapted to engineering problems in the last century. Its utility lies in the ability to convert differential equations to algebraic forms that are more easily solved. The notation has become very common in certain areas as a form of engineering “language” for dealing with systems.
367
Figure 10-1. Steps involved in using the Laplace transform.
368
Laplace Transformation
369
Basic Theorems of Linearity
The Laplace transform of a product is not the product of the transforms.
370
Figure 10-2. Illustration of the unit step function.
371
Example 10-1. Derive the Laplace transform of the unit step function.
372
Example 10-2. Derive the Laplace transform of the exponential function
373
Table 10-1. Common transform pairs.
374
Example 10-3. A force in newtons (N) is given below
Example A force in newtons (N) is given below. Determine the Laplace transform.
375
Example 10-4. A voltage in volts (V) starting at t = 0 is given below
Example A voltage in volts (V) starting at t = 0 is given below. Determine the Laplace transform.
376
Example A pressure in pascals (p) starting at t = 0 is given below. Determine the Laplace transform.
377
Inverse Laplace Transforms by Identification
When a differential equation is solved by Laplace transforms, the solution is obtained as a function of the variable s. The inverse transform must be formed in order to determine the time response. The simplest forms are those that can be recognized within the tables and a few of those will now be considered.
378
Example 10-6. Determine the inverse transform of the function below.
379
Example 10-7. Determine the inverse transform of the function below.
380
Example 10-8. Determine the inverse transform of the function below.
When the denominator contains a quadratic, check the roots. If they are real, a partial fraction expansion will be required. If they are complex, the table may be used. In this case, the roots are
381
Example 10-8. Continuation.
382
Example 10-8. Continuation.
383
Forms for CCLODE Transforms
384
The roots of D(s) are called poles and they may be classified in four ways.
1. Real poles of first order. 2. Complex poles of first order (including purely imaginary poles) 3. Real poles of multiple order 4. Complex poles of multiple order (including purely imaginary poles)
385
Partial Fraction Expansion Real Poles of First Order
386
Example 10-9. Determine inverse transform of function below.
387
Example 10-9. Continuation.
388
Example 10-10. Determine exponential portion of inverse transform of function below.
389
Example 10-10. Continuation.
390
Partial Fraction Expansion for First-Order Complex Poles
391
Example 10-11. Complete the inverse transform of Example 10-10.
392
Example 10-11. Continuation.
393
Second-Order Real Poles
Assume that F(s) contains a denominator factor of the form (s+)2. The expansion will take the form shown below.
394
Example 10-12. Determine inverse transform of function below.
395
Example 10-12. Continuation.
396
Laplace Transform Operations
397
Significant Operations for Solving Differential Equations
398
Procedure for Solving DEs
399
Example 10-13. Solve DE shown below.
400
Example 10-13. Continuation.
401
Example 10-14. Solve DE shown below.
402
Example 10-14. Continuation.
403
Example 10-14. Continuation.
404
Example 10-15. Solve DE shown below.
405
Example 10-15. Continuation.
406
Example 10-16. Solve DE shown below.
407
Example 10-16. Continuation.
408
Example 10-16. Continuation.
409
Chapter 11 Solution of Differential Equations with MATLAB
MATLAB has some powerful features for solving differential equations of all types. We will explore some of these features for the CCLODE forms. The approach here will be that of the Symbolic Math Toolbox. The result will be the form of the function and it may be readily plotted with MATLAB.
410
Symbolic Differential Equation Terms
Dy D2y Dny
411
Representative CCLODE Form
>> y = dsolve(‘b2*D2y+b1*D1y+b0*y=A*sin(a*t)’, ‘y(0)=C1’, ‘Dy(0)=C2’) >> ezplot(y, [t1 t2])
412
Example 11-1. Solve DE below with MATLAB.
>> y = dsolve('Dy + 2*y = 12', 'y(0)=10') y = 6+4*exp(-2*t) >> ezplot(y, [0 3]) >> axis([ ])
414
Example 11-2. Solve DE below with MATLAB.
>> y = dsolve('Dy + 2*y = 12*sin(4*t)', 'y(0)=10') y = -12/5*cos(4*t)+6/5*sin(4*t)+62/5*exp(-2*t) >> ezplot(y, [0 8]) >> axis([ ])
416
Example 11-3. Solve DE below with MATLAB.
>> y = dsolve('D2y + 3*Dy + 2*y = 24', 'y(0)=10', 'Dy(0)=0') y = 12+2*exp(-2*t)-4*exp(-t) >> ezplot(y, [0 6])
418
Example 11-4. Solve DE below with MATLAB.
>> y = dsolve('D2y + 2*Dy + 5*y = 20', 'y(0) = 0', 'Dy(0) = 10') y = 4+3*exp(-t)*sin(2*t)-4*exp(-t)*cos(2*t) >>ezplot(y, [0 5]}
420
Symbolic Laplace Transform
Establish t and s as symbolic variables. >> syms t s The time function f is then formed and the Laplace transform command is >> F = laplace(f) Some useful simplifications are >> pretty(F) >> simplify(F)
421
Symbolic Inverse Laplace Transform
Establish t and s as symbolic variables. >> syms t s The Laplace function F is then formed and the inverse Laplace transform command is >> f = ilaplace(F) The simplification operations may also be useful for inverse transforms.
422
Example 11-5. Determine the Laplace transform of f(t)=5t with MATLAB.
>>syms t s >> f = 5*t f = 5*t >> F = laplace(f) F = 5/s^2
423
Example 11-6. Determine the Laplace transform of the function below using MATLAB.
>> syms t s >> v = 3*exp(-2*t)*sin(5*t) + 4*exp(-2*t)*cos(5*t) v = 3*exp(-2*t)*sin(5*t)+4*exp(-2*t)*cos(5*t)
424
Example 11-6. Continuation.
>> V = laplace(v) V = 15/((s+2)^2+25)+4*(s+2)/((s+2)^2+25) >> V=simplify(V) (23+4*s)/(s^2+4*s+29)
425
Example 11-7. Determine the inverse transform of the function below using MATLAB.
>> syms t s >> F=100*(s+3)/((s+1)*(s+2)*(s^2+2*s+5)) F = (100*s+300)/(s+1)/(s+2)/(s^2+2*s+5)
426
Example 11-7. Continuation.
>> f = ilaplace(F) f = 50*exp(-t)-20*exp(-2*t)-30*exp(-t)*cos(2*t)-10*exp(-t)*sin(2*t) >> pretty(f) 50 exp(-t) - 20 exp(-2 t) - 30 exp(-t) cos(2 t) - 10 exp(-t) sin(2 t)
427
Example 11-8. Determine the inverse transform of the function below using MATLAB.
>> syms t s >> Y = 10/(s+2) + 48/((s+2)*(s^2+16)) Y = 10/(s+2)+48/(s+2)/(s^2+16)
428
Example 11-8. Continuation.
>> y = ilaplace(Y) y = 62/5*exp(-2*t)-12/5*cos(16^(1/2)*t)+3/10*16^(1/2)*sin(16^(1/2)*t) >> y=simplify(y) 62/5*exp(-2*t)-12/5*cos(4*t)+6/5*sin(4*t)
429
Chapter 12 Introduction to Statistics
A random variable is one in which the exact behavior cannot be predicted, but which may be described in terms of probable behavior. A random process is any process that involves one or more random variables. The subjects of probability and statistics are based on a mathematical and scientific methodology for dealing with random processes and variables.
430
Figure 12-1. A random variable.
431
Probability Probability is associated with the very natural trend of a random event to follow a somewhat regular pattern if the process is repeated a sufficient number of times.
432
Probability Assume that the first event occurs n1 times, the second event n2 times, and so on. The various probabilities are then defined as
433
Probabilities Properties
434
Example For 52-card deck, determine probabilities of drawing (a) red card, (b) a heart, (c) an ace, (d) ace of spades, (e) ace of hearts or the ace of diamonds. (a) (b)
435
Example 12-1. Continuation.
(d) (e)
436
Probability Terminology
437
Mutual Exclusiveness Let P(A1+A2) represent the probability that either A1 or A2 occurs. Two events are mutually exclusive if
438
Figure 12-2(a). Events that are mutually exclusive.
439
Figure 12-2(b). Events that are not mutually exclusive.
440
Events that are not Mutually Exclusive
If the two events are not mutually exclusive, then the common area must be subtracted from the sum of the probabilities.
441
Statistical Independence
Let P(A1A2) represent the probability that both A1 and A2 occur. Two events are statistically independent if
442
Conditional Probability
P(A2/A1) is defined to mean “the probability that A2 is true given that A1 is true.”
443
Example 12-2. What is the probability that a single card will be an ace or a king?
444
Example 12-3. What is the probability that a single card will be an ace or a red card?
445
Example 12-4. Two cards are drawn from a deck
Example Two cards are drawn from a deck. The first is replaced before the second is drawn. What is the probability that both will be aces?
446
Example Consider the same experiment but assume the first card is not replaced. What is the probability that both will be aces?
447
Example The switches below are SI and only close 90% of the time when activated. Determine probability that both close.
448
Example 12-7. The switches are changed as shown
Example The switches are changed as shown. Determine the probability of success.
449
Example 12-7. Alternate Solution.
450
Discrete Statistical Functions
A discrete variable is one that can assume only a finite number of levels. For example, a binary signal can assume only two values: a logical 1 and a logical 0. To develop the concept, consider a random voltage x(t) that can assume 4 levels. The values are listed below and a short segment is illustrated on the next slide.
451
Figure 12-5. Short segment of random discrete voltage.
452
Figure 12-6. Number of samples of each voltage based on 100,000 total samples.
453
Figure 12-7. Probability density function (pdf) of random discrete voltage.
454
Probability Evaluations
The quantity X represents a random sample of a process. The expression P(X=x) means “the probability that a random sample of the process is equal to x.”
455
Probability Distribution Function F(x)
456
Example For the pdf considered earlier, determine the probability values in the statements that follow.
457
Example 12-8. Continuation.
458
Example 12-8. Continuation.
459
Example 12-9. Determine the probability distribution function of the random discrete voltage.
460
Statistical Averages of Discrete Variables.
In dealing with statistical processes, there is a difference between a complete population and a sample of a population insofar as parameter estimation is concerned. We will assume here that we are dealing with a complete population. Expected Value or Expectation
461
Statistical Averages of Discrete Variables. Continuation.
Mean Value Mean-Squared Value Root-Mean Square (RMS Value)
462
Statistical Averages of Discrete Variables. Continuation.
Variance Alternate Formula for Variance Standard Deviation
463
Example For pdf of Example 12-8, determine (a) mean value, (b) mean-square value, (c) rms value, (d) variance, and (e) standard deviation.
464
Example 12-10. Continuation.
465
Binomial Probability Density Function
Consider the probability that in four trials, A will occur exactly twice. The different combinations are as follows: AABB ABAB ABBA BBAA BABA BAAB
466
Combinations The number of combinations of n trials with exactly x occurrences of one of the two outcomes, where x is a non-negative integer no greater than n, is given by
467
Binomial PDF
468
Example 12-11. An unbiased coin is flipped 3 times
Example An unbiased coin is flipped 3 times. What is the probability of getting exactly one head?
469
Example 12-12. For previous example, what is the probability of getting at least one head?
470
Example 12-12. Alternate Approach.
471
Continuous Statistical Functions
If the random variable x is continuous over a domain, it can be described by a continuous pdf. The probability of a sample assuming an exact value is 0.
472
Figure 12-9. Typical pdf of a continuous variable.
473
Probability Distribution Function F(x)
474
Figure Probability of a random sample lying within a domain is the area under the pdf curve between the limits.
475
Example 12-13. Determine K below.
476
Example For the pdf of the last example, determine the probability values in the statements that follow. Refer to Figure if necessary.
477
Example 12-14. Continuation.
478
Figure 12-12. Various areas in Example 12-14.
479
Example 12-15. Determine the probability distribution function for the uniform pdf of Example 12-14.
480
Figure 12-13. Probability distribution function for Example 12-15.
481
Statistical Averages of Continuous Variables.
With discrete variables, the averages are determined by summations. With continuous variables, the averages are determined by integrals. Expected Value or Expectation
482
Statistical Averages of Continuous Variables. Continuation.
Mean Value Mean-Squared Value Root-Mean Square (RMS Value)
483
Statistical Averages of Discrete Variables. Continuation.
Variance Alternate Formula for Variance Standard Deviation
484
Example For uniform pdf of previous examples, determine (a) mean value, (b) mean-square value, (c) total rms value, (d) variance, and (e) standard deviation.
485
Example 12-16. Continuation.
486
Figure 12-14. Gaussian Probability Density Function.
487
Mathematical Properties of Gaussian PDF
488
Normalized Gaussian PDF
489
Figure 12-15. Normalized Gaussian PDF.
490
Gaussian Probability Distribution Function
492
Example In this example, the normalized gaussian pdf will be used to evaluate various probabilities that will be listed on the next several slides. Table 12-2 in the text will be used to determine the values required in the computations.
493
Example 12-17. Continuation.
494
Example 12-17. Continuation.
Alternately,
495
Example 12-17. Continuation.
Alternately,
496
Example A random voltage x(t) is gaussian distributed with a dc value of 0 and an rms value of 5 V. Determine various probabilities listed in the steps that follow.
497
Example 12-18. Continuation.
498
Example A random force has a gaussian distribution with a mean value of 10 N and standard deviation of 5 N. Determine the probability that a sample exceeds 20 N.
499
Example 12-19. Continuation.
500
Sampling Statistics Sample Parameter True Mean Mean-Square Variance
In all cases thus far, it has been assumed that the statistics of the complete population were known. In many applications, only a sample of the population can be obtained. Sample Parameter True Mean Mean-Square Variance Standard Deviation
501
Sample Parameters Sample Mean Sample Mean-Square Value
502
Sample Parameters (Continued)
Sample Variance or Sample Standard Deviation
503
Other Sample Statistical Parameters
Median. The median is the midpoint value. Mode. The mode is the most frequently occurring value. Range. The range is the largest value minus the smallest value.
504
Example In a large class, a sample of 25 grades taken at random resulted in the values below. Determine the sample statistics.
505
Example 12-20. Continuation.
alternate method
506
Example 12-20. Continuation.
507
MATLAB Statistical Parameters
508
Example 12-21. Use MATLAB to solve Example 12-20.
>> xb = [ ]; >> xc = [ ]; >> xd = [ ]; >> xe = [ ]; >> x = [xa xb xc xd xe];
509
Example 12-21. Continuation.
>> xmean = mean(x) xmean = >> xmedian = median(x) xmedian = 79
510
Example 12-21. Continuation.
>> xstd = std(x) xstd = >> xmean_square = mean(x.^2) xmean_square = 6.1034e+003
511
Gaussian Probabilities Using the Error Function
512
Complementary Error Function
513
Summary of MATLAB Error Function Commands
Error Function: erf(x) Inverse Error Function: erfinv(x) Complementary Error Function: erfc(x) Inverse Complementary Error Function: erfcinv(x)
514
Inverse Operations with MATLAB
To find the value of z such that P(Z z) = p, the following MATLAB command is used: >> z = sqrt(2)*erfinv(2*p - 1) To find the value of z such that P(Z z) = p, the following MATLAB command is used: >> z = sqrt(2)*erfcinv(2*p)
515
Example 12-22. Rework the first four parts of Example 12-17 using MATLAB.
>> k = sqrt(2); (a) P(Z 0) >> pa=.5*(erf(10/k) - erf(0)) pa = 0.5000 (b) P(1 Z 3) >> pb = 0.5*(erf(3/k) - erf(1/k)) pb = 0.1573
516
Example 12-22. Continuation.
(c) P(-1 Z 2) >> pc = 0.5*(erf(2/k) - erf(-1/k)) pc = 0.8186 (d) P(-2 Z 2) >> pd = 0.5*(erf(2/k) - erf(-2/k)) pd = 0.9545
517
Example An internet line has noise with a dc value of 0 and an rms value of 2 V. An error occurs if the noise exceeds a threshold. Determine threshold for p = 10-5. >> z = sqrt(2)*erfcinv(2*1e-5) z = 4.2649
519
Chapter 13 Curve Fitting and Correlation
This chapter will be concerned primarily with two separate but closely interrelated processes: (1) the fitting of experimental data to mathematical forms that describe their behavior and (2) the correlation between different experimental data to assess how closely different variables are interdependent.
520
The fitting of experimental data to a mathematical equation is called regression. Regression may be characterized by different adjectives according to the mathematical form being used for the fit and the number of variables. For example, linear regression involves using a straight-line or linear equation for the fit. As another example, Multiple regression involves a function of more than one independent variable.
521
Linear Regression Assume n points, with each point having values of both an independent variable x and a dependent variable y.
522
Preliminary Computations
523
Best-Fitting Straight Line
524
Example 13-1. Find best fitting straight line equation for the data shown below.
525
Example 13-1. Continuation.
526
Example 13-1. Continuation.
527
Example 13-1. Continuation.
>> yapp = *x ; >> y = [the 10 values of y]; >> plot(x, yapp, x, y, 'o') The best-fit plot and the actual points are shown on the next slide.
529
MATLAB General Polynomial Fit
>> x = [x1 x2 x xn]; >> y = [y1 y2 y yn]; >> p = polyfit(x, y, m) >> yapp = polyval(p, x) >> plot(x, yapp, x, y, 'o')
530
Example 13-2. Rework Example 13-1 using MATLAB.
>> y = [the 10 values of y]; >> p = polyfit(x, y, 1) p = These are the same values obtained manually in Example 13-1.
531
Example 13-3. For data of previous two examples, obtain a 2nd degree fit.
Assume that the vectors x and y are still in memory. >> p = polyfit(x, y, 2) p = >> yapp2 = polyval(p, x); >> plot(x, yapp2, x, y, 'o') The results are shown on the next slide.
533
Example 13-4. Determine several polynomial fits for the function below.
>> y = sin(pi*t); >> plot(t, y) A plot of the function is shown on the next slide.
535
Example 13-4. Continuation.
>> p1 = polyfit(t, y, 1) p1 = >> yapp1 = polyval(p1, t); >> plot(t, yapp1, t, y, 'o') The results are shown on the next slide.
537
Example 13-4. Continuation.
(b) m = 2 >> p2 = polyfit(t, y, 2) p2 = The polynomial is the same as for m = 1. This is due to the fact that the sine function is an odd function and the coefficients of the terms with even degrees are zero.
538
Example 13-4. Continuation.
(c) m = 3 >> p3 = polyfit(t, y, 3) p3 = >> yapp3 = polyval(p3, t); >> plot(t, yapp3, t, y, 'o') The results are shown on the next slide. A fit for m = 4 would be the same as for m = 3.
540
Example 13-5. Continuation.
>> p5 = polyfit(t, y, 5) p5 = >> yapp5 = polyval(p5, t); >> plot(t, yapp5, t, y, 'o') The results are shown on the next slide.
542
Example For data below, obtain a 2nd degree fit for the temperature T as a function of the distance x. >> x = 0:5; >> T = [ ]; >> p = polyfit(x,T,2) p =
543
Example 13-5. Continuation.
>> T1 = polyval(p, x1); >> plot(x1, T1, x, T, 'o') The results are shown on the next slide.
545
Multiple Linear Regression
546
Multiple Regression (Continuation)
547
MATLAB Procedure for Linear Regression
1. Form m column vectors each of length k representing the independent variables. >> x1 = [x11 x12 x x1k]'; >> x2 = [x21 x22 x x2k]'; . >> xm = [xm1 xm2 xm3.....xmk]';
548
MATLAB Procedure (Continuation)
2. Form a column vector of length k representing the dependent variable y. >> y = [y1 y2 y3.....yk]'; 3. Form a rectangular matrix X of size k by m+1 as follows: >> X= [ones(size(x1)) x1 x xm]; 4. Determine a column vector a of length m+1 by the command that follows: >> a = X\y
549
MATLAB Procedure (Continuation)
5. The best-fit linear multiple regression formula is then given by >> Y = X*a; 6. The maximum difference between the actual data and the formula is >> Error_Maximum = max(abs(Y-y))
550
Correlation
551
Correlation Coefficient
552
Implications of Correlation Coefficient
1. If C(x, y) = 1, the two variables are totally correlated in a positive sense. 2. If C(x, y) = -1 , the two variables are totally correlated in a negative sense. 3. If C(x, y) = 0, the two variables are said to be uncorrelated.
553
One Final Note Correlation does not necessarily imply causation!
554
Chapter 14 Introduction to Spatial Vector Analysis
The term vector has slightly different meanings in different areas of mathematics, engineering and science. Throughout the text thus far, the term has been used to refer to row or column matrices according to the standard conventions of matrix algebra, and these conventions are in turn employed by MATLAB.
555
Another widely used definition for vector is associated with spatial quantities that have specific directions in terms of the three-dimensional coordinate system in which we live. Examples of such quantities are forces, velocities, displacements, electric fields, magnetic fields, and many other physical variables. A three-dimensional spatial vector can be represented in terms of a row or column vector in MATLAB. There are certain mathematical operations that are useful in describing these quantities and the subject area is called vector analysis.
556
For the purposes of this chapter, a spatial vector will be defined as a quantity that has both a magnitude and a direction. Since the focus throughout the chapter will be on spatial vectors, the adjective spatial will often be omitted. At any point at which a MATLAB vector is created, the terms row vector and column vector will be used as appropriate.
557
Rectangular Coordinate System
558
Unit Vectors in Rectangular Coordinate System
560
Direction Angles
561
Relationships for Direction Angles
562
Example A force has x, y, and z components of 3, 4, and –12 N, respectively. Express the force as a vector in rectangular coordinates.
563
Example 14-2. Determine the magnitude of the force in Example 14-1.
564
Example 14-3. Determine the three direction angles for the force of Examples 14-1 and 14-2.
565
Example 14-3. Continuation.
566
Vector Operations to be Considered
Scalar or Dot Product A•B Vector or Cross Product AxB Triple Scalar Product (AxB)•C
567
Consider two vectors A and B oriented in different directions.
568
Scalar or Dot Product
569
First Interpretation of Dot Product: Projection of A on B times the length of B.
570
Second Interpretation of Dot Product: Projection of B on A times the length of A.
571
Some Implications of Dot Product
572
Example 14-4. Perform several scalar operations on the following vectors:
573
Example 14-4. Continuation.
574
Vector or Cross Product
575
Cross Product AxB
576
Cross Product BxA
577
Area of parallelogram below is the magnitude of the cross product.
578
Some Implications of Cross Product
579
Example 14-5. Determine the cross product of the vectors of Example 14-4.
580
Example 14-6. Determine a unit vector perpendicular to the vectors of Examples 14-4 and 14-5.
581
Triple Scalar Product
582
Volume of parallelepiped below is the triple scalar product of the vectors.
583
Example 14-7. Determine the triple scalar product of the vectors
584
Work and Energy Let F represent a constant force vector and let L represent a vector path length over which the work W is performed. The first equation below will determine the work. If the force is a function of the position, the differential form is required.
585
Force on Current Carrying Conductor
586
Force Resulting in Torque Vector
587
Voltage Induced in Moving Conductor
Assume that a conductor of vector length L is moving with vector velocity v through a magnetic field vector B. The voltage measured across the length is given by the triple scalar product that follows.
588
MATLAB Dot Product >> A = [Ax Ay Az] >> B = [Bx By Bz]
>> P_dot = dot(A, B) The magnitude of a vector A can be determined by the following command: >>A_mag = sqrt(dot(A, A))
589
MATLAB Cross Product >> A = [Ax Ay Az] >> B = [Bx By Bz]
>> P_cross = cross(A,B)
590
MATLAB Triple Scalar Product
>> A = [Ax Ay Az] >> B = [Bx By Bz] >> C = [Cx Cy Cz] >> P_triple = det([A; B; C])
591
Chapter 15 Complex Numbers
A few operations with complex numbers were used earlier in the text and it was assumed that the reader had some basic knowledge of the subject. The subject will now be approached from a broader perspective and many of the operations will be developed in detail. To deal with Fourier analysis in Chapter 16, complex number operations are required.
592
Complex Numbers and Vectors
In a sense, complex numbers are two-dimensional vectors. In fact, some of the basic arithmetic operations such as addition and subtraction are the same as those that could be performed with the spatial vector forms of Chapter 14 in two dimensions. However, once the process of multiplication is reached, the theory of complex number operations diverges significantly from that of spatial vectors.
593
Rectangular Coordinate System
The development begins with the two-dimensional rectangular coordinate system shown on the next slide. The two axes are labeled as x and y. In complex variable theory, the x-axis is called the real axis and the y-axis is called the imaginary axis. An imaginary number is based on the definition that follows.
594
Complex Plane
595
Form of Complex Number
596
Conversion Between Forms
597
Euler’s Formula
598
Example 15-1. Convert the following complex number to polar form:
599
Example 15-2. Convert the following complex number to polar form:
600
Example 15-3. Convert the following complex number to rectangular form:
601
Example 15-4. Convert the following complex number to rectangular form:
602
Addition of Two Complex Numbers
603
Addition of Two Complex Numbers
604
Subtraction of Two Complex Numbers
605
Subtraction of Two Complex Numbers
606
Example 15-5. Determine the sum of the following complex numbers:
607
Example 15-6. For the numbers that follow, determine zdiff = z1-z2.
608
Multiplication in Polar Form
609
Division in Polar Form
610
Multiplication in Rectangular Form
611
Complex Conjugate
612
Division in Rectangular Form
613
Example 15-7. Determine the product of the following 2 complex numbers:
614
Example 15-8. Repeat previous example using rectangular forms.
615
Example 15-9. Determine the quotient z1/z2 for the following 2 numbers:
616
Example 15-10. Repeat previous example using rectangular forms.
617
Exponentiation of Complex Numbers: Integer Power
618
Roots of Complex Numbers
619
Example 15-11. For the value of z below, determine z6 = z6.
620
Example 15-12. Determine the 4 roots of s4 + 1 = 0.
621
MATLAB Complex Number Operations: Entering in Rectangular Form
>> z = 3 + 4i z = i >> z = 3 + 4j The i or j may precede the value, but the multiplication symbol (*) is required.
622
MATLAB Complex Number Operations: Entering in Polar Form
>> z = 5*exp(0.9273i) z = i >> z = 5*exp((pi/180)*53.13i) This result indicates that polar to rectangular conversion occurs automatically upon entering the number in polar form.
623
MATLAB Rectangular to Polar Conversion
>> z = 3 + 4i z = i >> r = abs(z) r = 5 >> theta = angle(z) theta = 0.9273
624
Other MATLAB Operations
>> z_conj = conj(z) z_conj = i >>real(z) ans = 3 >> imag(z) 4
625
Chapter 16 Fourier Analysis with MATLAB
Fourier analysis is the process of representing a function in terms of sinusoidal components. It is widely employed in many areas of engineering, science, and applied mathematics. It provides information as to what frequency components represent a function. Some basic principles and the means for performing the analysis with MATLAB will be considered in this chapter.
626
Initial Assumptions Since many of the variables for which Fourier analysis is required are functions of time t, we will use it as the independent variable. The dependent variable will be denoted as x(t). The function x(t) is said to be in the time domain and the Fourier representation is said to be in the frequency domain. The frequency domain form is called the spectrum. We will first consider the spectra of periodic functions. A periodic function satisfies x(t) = x(t+T)
627
Periodic Function The function below is an example of a periodic function with period T.
628
Fourier Series for Periodic Functions
Spectral analysis of periodic functions is achieved through the Fourier series. The 3 forms are (1) cosine-sine form, (2) amplitude-phase form, and (3) complex exponential form. (1) and (2) are referred to as one-sided forms and (3) will be referred to as a two-sided form. A constant term in the series is often called the dc value.
629
Simple Initial Analysis
630
Example 16-1. List frequencies for the assumed periodic waveform below.
Only one cycle is shown.
631
Example 16-1. Continuation.
Since the positive area is clearly greater than the negative area, there will be a constant or dc term in the series. The frequencies are 0 (dc) 200 Hz 400 Hz 600 Hz 800 Hz, etc.
632
Fourier Series Cosine-Sine Form
633
Fourier Series Cosine-Sine Form (Continuation)
634
Fourier Series Amplitude-Phase Form
635
Fourier Series Complex Exponential Form
636
Some Relationships
637
Example 16-2. A Fourier series is given below
Example A Fourier series is given below. List frequencies and plot the one-sided amplitude spectrum. The frequencies are 0 (dc) 10 Hz 20 Hz 30 Hz
638
One-Sided Amplitude Spectrum of Example 16-2
639
Two-Sided Amplitude Spectrum of Example 16-3
640
Periodic Function of Examples 16-4, 16-5, and 16-6.
641
Example 16-4. Determine Fourier series.
642
Example 16-4. Continuation.
643
Example 16-5. One-Sided Spectral Plot
644
Example 16-6. Two-Sided Spectral Plot
645
Fourier Transform
646
Amplitude and Phase Spectra
647
Comparison of Fourier Series and Fourier Transform
The Fourier series is usually applied to a periodic function and the transform is usually applied to a non-periodic function. The spectrum of a periodic function is a function of a discrete frequency variable. The spectrum of a non-periodic function is a function of a continuous frequency variable.
648
Example 16-7. Determine the Fourier transform of the function below.
649
Example 16-7. Continuation.
650
Example 16-8. Determine the Fourier transform of the function below.
651
Example 16-8. Continuation.
652
Discrete and Fast Fourier Transforms
The discrete Fourier transform (DFT) is a summation that produces spectral terms that may be applied to either periodic or non-periodic functions. The fast Fourier transform (FFT) is a computationally efficient algorithm for computing the DFT at much higher speeds. The IDFT and IFFT are the corresponding inverse transforms.
653
Sampled Signal
654
Definitions of DFT and IDFT
655
Initial Assumptions for MATLAB
The function must be interpreted as periodic. It is recommended that the number of points N be even. The spectrum will also be periodic. It will be unique only at N/2 points. The integer for a MATLAB indexed variable must start at a value of 1. The highest unambiguous frequency corresponds to a MATLAB index of N/2.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.