0-8493-????-?/00/$0.00+$.50 © 2000 by CRC Press LLC © 2001 by CRC Press LLC 3 Elementary Functions and Some of Their Uses The purpose of this chapter is to illustrate and build some practice in the use of elementary functions in selected basic electrical engineering problems. We also construct some simple signal functions that you will encounter in future engineering analysis and design problems. NOTE It is essential to review the Supplement at the end of this book in case you want to refresh your memory on the particular elementary functions covered in the different chapter sections. 3.1 Function Files To analyze and graph functions using MATLAB, we have to be able to con- struct functions that can be called from within the MATLAB environment. In MATLAB, functions are made and stored in function M-files. We already used one kind of M-file (script file) to store various executable commands in a rou- tine. Function M-files differ from script M-files in that they have designated input(s) and output(s). The following is an example of a function. Type and save the following function in a file named aline.m: function y=aline(x) % (x,y) is a point on a line that has slope 3 % and y-intercept -5 y=3*x-5; NOTES 1. The word function at the beginning of the file makes it a function rather than a script file. 2. The function name, aline, that appears in the first line of this file should match the name that we assign to this file name when saving it (i.e., aline.m). Having created a function M-file in your user volume, move to the com- mand window to learn how to call this function. There are two basic ways to use a function file: © 2001 by CRC Press LLC 1. To evaluate the function for a specified value x=x1, enter aline(x1) to get the function value at this point; that is, y 1 = 3x 1 – 5. 2. To plot y 1 = 3x 1 – 5 for a range of x values, say [–2, 7], enter: fplot('aline',[-2,7]) NOTE The above example illustrates a function with one input and one out- put. The construction of a function M-file of a function having n inputs and m outputs starts with: function [y1,y2, ,ym]=funname(x1,x2, ,xn) Above, using a function M-file, we showed a method to plot the defined function aline on the interval (–2, 7) using the fplot command. An alter- native method is, of course, to use arrays, in the manner specified in Chapter 1. Specifically, we could have plotted the 'aline' function in the following alternate method: x=-2:.01:7; y=3*x-5; plot(x,y) To compare the two methods, we note that: 1. plot requires a user-supplied x-array (abscissa points) and a constructed y-array (ordinate points), while fplot only requires the name of the function file, defined previously and stored in a function M-file and the endpoints of the interval. 2. The fplot automatically creates a sampled domain that is used to plot the function, taking into account the type of function being plotted and using enough points to make the display appear con- tinuous. On the other hand, plot requires that you choose the array length yourself. Both methods, therefore, have their own advantages and it depends on the particular problem whether to use plot or fplot. We are now in position to explore the use of some of the most familiar func- tions. 3.2 Examples with Affine Functions The equation of an affine function is given by: © 2001 by CRC Press LLC y(x) = ax + b (3.1) In-Class Exercises Pb. 3.1 Generate four function M-files for the following four functions: Pb. 3.2 Sketch the functions of Pb. 3.1 on the interval –5 < x < 5. What can you say about the angle between each of the two lines’ pairs. (Did you remember to make your aspect ratio = 1?) Pb. 3.3 Read off the graphs the coordinates of the points of intersection of the lines in Pb. 3.1. (Become familiar with the use and syntax of the zoom and ginput commands for a more accurate reading of the coordinates of a point.) Pb. 3.4 Write a function M-file for the line passing through a given point and intersecting another given line at a given angle. Application to a Simple Circuit The purpose of this application is to show that: 1. The solution to a simple circuit problem can be viewed as the simultaneous solution of two affine equations, or, equivalently, as the intersection of two straight lines. 2. The variations in the circuit performance can be studied through a knowledge of the affine functions, relating the voltages and the current. Consider the simple circuit shown in Figure 3.1. In the terminology of the circuit engineer, the voltage source V S is called the input to the circuit, and the current I and the voltage V are called the circuit outputs. Thus, this is an example of a system with one input and two outputs. As you may have stud- ied in high school physics courses, all of circuit analysis with resistors as ele- ments can be accomplished using Kirchhoff’s current law, Kirchoff’s voltage law, and Ohm’s law. • Kirchoff’s voltage law: The sum of all voltage drops around a closed loop is balanced by the sum of all voltage sources around the same loop. yx x yx x yx x yx x 123 4 32 35 3 3 3 4() ; () ; () ; ()=+ =+ =−+ =−+ Hint: tan( ) tan( ) tan( ) tan( )tan( ) ab ab ab += + − 1 © 2001 by CRC Press LLC • Kirchoff’s current law: The algebraic sum of all currents entering (exiting) a circuit node must be zero. (Assign the + sign to those currents that are entering the node, and the – sign to those current exiting the node.) • Ohm’s law: The ratio of the voltage drop across a resistor to the current passing through the resistor is a constant, defined as the resistance of the element; that is, The quantities we are looking for include (1) the current I through the cir- cuit, and (2) the voltage V across the load resistor R. Using Kirchoff’s voltage law and Ohm’s law for resistance R 1 , we obtain: V s = V + V 1 = V + IR 1 (3.2) while applying Ohm’s law for the load resistor gives: V = IR (3.3) These two equations can be rewritten in the form of affine functions of I as functions of V: (3.4) (3.5) FIGURE 3.1 A simple resistor circuit. I R 1 R V s + _ V R V I = LI VV R s 1 1 : () = − LI V R 2 : = © 2001 by CRC Press LLC If we know the value of V s , R, and R 1 , then Eqs. (3.4) and (3.5) can be repre- sented as lines drawn on a plane with ordinate I and abscissa V. Suppose we are interested in finding the value of the current I and the volt- age V when R 1 = 100Ω, R = 100Ω, and V s = 5 V. To solve this problem graphi- cally, we plot each of the L 1 and L 2 functions on the same graph and find their point of intersection. The functions L 1 and L 2 are programmed as follows: function I=L1(V) R1=100; R=100; Vs=5; I=(Vs-V)/R1; function I=L2(V) R1=100; R=100; Vs=5; I=V/R; Because the voltage V is smaller than the source potential, due to losses in the resistor, a suitable domain for V would be [0, 5]. We now plot the two lines on the same graph: fplot('L1',[0,5]) hold on fplot('L2',[0,5]) hold off In-Class Exercise Pb. 3.5 Verify that the two lines L 1 and L 2 intersect at the point: (I = 0.025, V = 2.5). In the above analysis, we had to declare the numerical values of the param- eters R 1 and R in the definition of each of the two functions. This can, at best, be tedious if you are dealing with more than two function M-files or two parameters; or worse, can lead to errors if you overlook changing the values of the parameters in any of the relevant function M-files when you decide to modify them. To avoid these types of problems, it is good practice to call all © 2001 by CRC Press LLC functions from a single script M-file and link the parameters’ values together so that you only need to edit the calling script M-file. To link the values of parameters to all functions in use, you can use the MATLAB global com- mand. To see how this works, rewrite the above function M-files as follows: function I=L1(V) global R1 R % global statement Vs=5; I=(Vs-V)/R1; function I=L2(V) global R1 R % global statement Vs=5; I=V/R; The calling script M-file now reads: global R1 R %global statement R1=100; %set global resistance values R=100; V=0:.01:5; %set the voltage range I1=L1(V); %evaluate I1 I2=L2(V); %evaluate I2 plot(V,I1,V,I2,'-') %plot the two curves In-Class Exercise Pb. 3.6 In the above script M-file, we used arrays and the plot command. Rewrite this script file such that you make use of the fplot command. Further Consideration of Figure 3.1 Calculating the circuit values for fixed resistor values is important, but we can also ask about the behavior of the circuit as we vary the resistor values. Suppose we keep R 1 = 100Ω and V s = 5 V fixed, but vary the value that R can take. To this end, an analytic solution would be useful because it would give us the circuit responses for a range of values of the circuit parameters R 1 , R, V s . However, a plot of the lines L 1 and L 2 for different values of R can also pro- vide a great deal of qualitative information regarding how the simultaneous solution to L 1 and L 2 changes as the value of R changes. © 2001 by CRC Press LLC The following problem serves to give you a better qualitative idea as to how the circuit outputs vary as different values are chosen for the resistor R. In-Class Exercise Pb. 3.7 This problem still refers to the circuit of Figure 3.1. a. Redraw the lines L 1 and L 2 , using the previous values for the circuit parameters. b. Holding the graph for the case R = 100Ω, sketch L 1 and L 2 again for R = 50Ω and R = 500Ω. How do the values of the voltage and the current change as R increases; and decreases? c. Determine the largest values of the current and voltage that can exist in this circuit when R varies over non-negative values. d. The usual nomenclature for the circuit conditions is as follows: the circuit is called an open circuit when R = ∞, while it is called a short circuit when R = 0. What are the (V, I ) solutions for these two cases? Can you generalize your statement? Now, to validate the qualitative results obtained in Pb. 3.7, let us solve analytically the L 1 and L 2 system. Solving this system of two linear equations in two unknowns gives, for the current and the voltage, the following expressions: (3.6) (3.7) Note that the above analytic expressions for V and I are neither linear nor affine functions in the value of the resistance. In-Class Exercise Pb. 3.8 This problem still refers to the circuit of Figure 3.1. a. Keeping the values of V s and R 1 fixed, sketch the functions V(R) and I(R) for this circuit, and verify that the solutions you found previously in Pbs. 3.7 and 3.8, for the various values of R, agree with those found here. VR R RR V s ()= + 1 IR RR V s ()= + 1 1 © 2001 by CRC Press LLC b. Given that the power lost in a resistive element is the product of the voltage across the resistor multiplied by the current through the resistor, plot the power through the variable resistor as a func- tion of R. c. Determine the value of R such that the power lost in this resistor is maximized. d. Find, in general, the relation between R and R 1 that ensures that the power lost in the load resistance is maximized. (This general result is called Thevenin’s theorem.) 3.3 Examples with Quadratic Functions A quadratic function is of the form: y(x) = ax 2 + bx + c (3.8) Preparatory Exercises Pb. 3.9 Find the coordinates of the vertex of the parabola described by Eq. (3.8) as functions of the a, b, c parameters. Pb. 3.10 If a = 1, show that the quadratic Eq. (3.8) can be factored as: y(x) = (x – x + )(x – x – ) where x ± are the roots of the quadratic equation. Further, show that, for arbi- trary a, the product of the roots is and their sum is In-Class Exercises Pb. 3.11 Develop a function M-file that inputs the two real roots of a second- degree equation and returns the value of this function for an arbitrary x. Is this function unique? Pb. 3.12 In your elementary mechanics course, you learned that the trajec- tory of a projectile in a gravitational field (oriented in the –y direction) with c a , −b a . © 2001 by CRC Press LLC an initial velocity v 0, x in the x-direction and v 0, y in the y-direction satisfies the following parametric equations: where t is time and the origin of the axis was chosen to correspond to the position of the particle at t = 0 and g = 9.8 ms –2 a. By eliminating the time t, show that the projectile trajectory y(x) is a parabola. b. Noting that the components of the initial velocity can be written as function of the projectile initial speed and its angle of inclination: v 0, y = v 0 sin(φ) and v 0, x = v 0 cos(φ) show that, for a given initial speed, the maximum range for the projectile is achieved when the inclination angle of the initial veloc- ity is 45°. c. Plot the range for a fixed inclination angle as a function of the initial speed. 3.4 Examples with Polynomial Functions As pointed out in the Supplement, a polynomial function is an expression of the form: (3.9) where a n ≠ 0 for an n th -degree polynomial. In MATLAB, we can represent the polynomial function as an array: (3.10) Example 3.1 You are given the array of coefficients of the polynomial. Write a function M- file for this polynomial using array operations. Let p = [132103]: Solution: function y=polfct(x) p=[1 3 2 1 0 3]; xvt y gt vt xy ==−+ 0 2 0 1 2 ,, and px ax a x ax a n n n n ()=+ +…++ − − 1 1 10 paa a nn =… − [] 10 © 2001 by CRC Press LLC L=length(p); v=x.^[(L-1):-1:0]; y=sum(p.*v); In-Class Exercises Pb. 3.13 Show that, for the polynomial p defined by Eq. (3.9), the product of the roots is and the sum of the roots is Pb. 3.14 Find graphically the real roots of the polynomial p = [1 3 2 1 0 3]. 3.5 Examples with the Trigonometric Functions A time-dependent cosine function of the form: (3.11) appears often in many applications of electrical engineering: a is called the amplitude, ω the angular frequency, and φ the phase. Note that we do not have to have a separate discussion of the sine function because the sine func- tion, as shown in the Supplement, differs from the cosine function by a con- stant phase. Therefore, by suitably changing only the value of the phase parameter, it is possible to transform the sine function into a cosine function. In the following example, we examine the period of the different powers of the cosine function; your preparatory task is to predict analytically the rela- tionship between the periods of the two curves given in Example 3.2 and then verify your answer numerically. Example 3.2 Plot simultaneously, x 1 (t) = cos 3 (t) and x 2 = cos(t) on t ∈ [0, 6π]. Solution: To implement this task, edit and execute the following script M-file: t=0:.2:6*pi; % t-array a=1;w=1; % desired parameters x1=a*(cos(w*t))^3; % x1-array constructed () ,−1 0 n n a a − − a a n n 1 . xa t=+cos( )ωφ [...]... FIGURE 3. 6 Profile of the second input to Pb 3. 32 For a message signal given by: 1 m(t) = 3 0 0 ≤ t ≤ t0 / 3 t0 / 3 < t ≤ 2t0 / 3 otherwise a Write the expression for the modulated signal using the unit area rectangle and the trigonometric functions b Plot the modulated signal as function of time (Let fc = 200 and t0 = 0.01.) Pb 3. 34 In conventional AM, m(t) in the DSB-AM expression for the... LLC FIGURE 3. 4 Profile of the signal of Pb 3. 31 FIGURE 3. 5 Profile of the first input to Pb 3. 32 Pb 3. 33 In DSB-AM (double-sideband amplitude modulation), the amplitude of the modulated signal is proportional to the message signal, which means that the time domain representation of the modulated signal is given by: uDSB(t) = Ac m(t) cos(2πfct) where the carrier-wave shape is c(t) = Ac cos(2πfct) and the...x2=a*cos(w*t); % x2-array constructed plot(t,x1,t,x2,' ') In-Class Exercises Pb 3. 15 Determine the phase relation between the sine and cosine functions of the same argument Pb 3. 16 The meaning of amplitude, angular frequency, and phase can be better understood using MATLAB to obtain graphs of the cosine function for a family of a values, ω values, and φ values a With ω = 1 and φ = π /3, plot the cosine... by a distance of 1 m Express your answer using the most appropriate of the following sub-units: mF = 10 3 F (milli-Farad); nF = 10 −9 F (nano-Farad); fF = 10 −15 F (femto-Farad); µF = 10 –6 F (micro-Farad); pF = 10 −12 F (pico-Farad); aF = 10 −18 F (atto-Farad); Pb 3. 29 Assume that you have two capacitors, one consisting of a coaxial cable (radii a and b) and the other of two parallel wires, separated... 3) sinh2(x) exp(–x2) Pb 3. 37 Decompose the signal shown in Figure 3. 7 into its even and odd parts: Pb 3. 38 Plot the function y defined through: x 2 + 4 x + 4 y( x) = 0.16 x 2 − 0.48 x 0 and find its even and odd parts © 2001 by CRC Press LLC for − 2 ≤ x < −1 for − 1 < x < 1.5 elsewhere FIGURE 3. 7 Profile of the signal of Pb 3. 37 3. 10 Animation of a Moving Rectangular Pulse You might often want... 1:0.1:2 b With a = 1 and ω = 1, plot the cosine curves corresponding to φ = 0:π/10:π c With a = 1 and φ = π/4, plot the cosine curves corresponding to ω = 1:0.1:2 Homework Problem Pb 3. 17 Find the period of the function obtained by summing the following three cosine functions: x1 = 3 cos(t / 3 + π / 3) , x 2 = cos(t + π), x 3 = 1 3 cos (t + π) 2 3 Verify your result graphically 3. 6 3. 6.1 Examples with... rectified sine function train Its function M-file is function y=psinef(x) s=rem(x,2*pi) if s>0 & s=pi & s= . 0-8 49 3- ? ?? ?-? /00/$0.00+$.50 © 2000 by CRC Press LLC © 2001 by CRC Press LLC 3 Elementary Functions and Some of Their Uses The purpose of this chapter is to illustrate and build some. LLC L=length(p); v=x.^[(L-1) :-1 :0]; y=sum(p.*v); In-Class Exercises Pb. 3. 13 Show that, for the polynomial p defined by Eq. (3. 9), the product of the roots is and the sum of the roots is Pb. 3. 14 Find graphically. to describe the random variable X. In-Class Exercises Pb. 3. 20 In each of the following cases, find the entropy: a. N = 32 and for all i b. N = 8 and c. N = 4 and d. N = 4 and HX px px ii i N (