Chapter 3. Elementary Functions and Some of Their Uses

Chapter 3. Elementary Functions and Some of Their Uses - 3...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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-±les . We already used one kind of M-±le (script Fle) to store various executable commands in a rou- tine. Function M-±les differ from script M-±les 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 Fle 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 Fle makes it a function rather than a script Fle. 2. The function name, aline , that appears in the Frst line of this Fle should match the name that we assign to this Fle name when saving it (i.e., aline.m ). Having created a function M-±le 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 Fle:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2001 by CRC Press LLC 1. To evaluate the function for a speciFed value x=x1 , enter aline(x1) to get the function value at this point; that is, y 1 = 3 x 1 – 5. 2. To plot y 1 = 3 x 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-Fle of a function having n inputs and m outputs starts with: function [y1,y2,. ..,ym]=funname(x1,x2,. ..,xn) Above, using a function M-Fle, we showed a method to plot the deFned function aline on the interval (–2, 7) using the fplot command. An alter- native method is, of course, to use arrays, in the manner speciFed in Chapter 1. SpeciFcally, 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 Fle, deFned previously and stored in a function M-Fle 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.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2010 for the course ENGINEERIN ELEC121 taught by Professor Tang during the Spring '10 term at University of Liverpool.

Page1 / 25

Chapter 3. Elementary Functions and Some of Their Uses - 3...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online