Signals.and.Systems.with.MATLAB.Computing.and.Simulink.Modeling.4th_Part73

Signals.and.Systems.with.MATLAB.Computing.and.Simulink.Modeling.4th_Part73

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

View Full Document Right Arrow Icon
Script and Function Files Signals and Systems with MATLAB Computing and Simulink Modeling, Fourth Edition A 27 Copyright © Orchard Publications Important: We must remember that we use roots(p) to find the roots of polynomials only, such as those in Examples A.1 and A.2. fplot(fcn,lims) plots the function specified by the string fcn between the x axis limits specified by lims = [xmin xmax] . Using lims = [xmin xmax ymin ymax] also controls the y axis limits. The string fcn must be the name of an m file function or a string with variable . NaN (Not a Number) is not a function; it is MATLAB’s response to an undefined expression such as , , or inability to produce a result as described on the next paragraph. We can avoid division by zero using the eps number, which we mentioned earlier. Example A.16 Find the zeros, the minimum, and the maximum values of the function (A.9) in the interval Solution: We first plot this function to observe the approximate zeros, maxima, and minima using the fol- lowing script. x= 1.5: 0.01: 1.5; y=1./ ((x 0.1).^ 2 + 0.01) 1./ ((x 1.2).^ 2 + 0.04) 10; plot(x,y); grid The plot is shown in Figure A.14. Figure A.14. Plot for Example A.16 using the plot command x 00 ⁄∞ fx () 1 x0 . 1 2 0.01 + ---------------------------------------- 1 x1 . 2 2 0.04 + 10 = 1 . 5x1 . 5 ≤≤ -1.5 -1 -0.5 0 0.5 1 1.5 -40 -20 0 20 40 60 80 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
Appendix A Introduction to MATLAB® A 28 Signals and Systems with MATLAB Computing and Simulink Modeling, Fourth Edition Copyright © Orchard Publications The roots (zeros) of this function appear to be in the neighborhood of and . The maximum occurs at approximately where, approximately, , and the minimum occurs at approximately where, approximately, . Next, we define and save f(x) as the funczero01.m function m file with the following script: function y=funczero01(x) % Finding the zeros of the function shown below y=1/((x 0.1)^2+0.01) 1/((x 1.2)^2+0.04) 10; To save this file, from the File drop menu on the Command Window, we choose New, and when the Editor Window appears, we type the script above and we save it as funczero01. MATLAB appends the extension .m to it. Now, we can use the fplot(fcn,lims) command to plot as follows: fplot('funczero01', [ 1.5 1.5]); grid This plot is shown in Figure A.15. As expected, this plot is identical to the plot of Figure A.14 which was obtained with the plot(x,y) command as shown in Figure A.14. Figure A.15. Plot for Example A.16 using the fplot command We will use the fzero(f,x) function to compute the roots of in Equation (A.9) more precisely. The MATLAB script below will accomplish this. x1= fzero('funczero01', 0.2); x2= fzero('funczero01', 0.3); fprintf('The roots (zeros) of this function are r1= %3.4f', x1); fprintf(' and r2= %3.4f \n', x2) x0 . 2 = . 3 = . 1 = y max 90 = x1 . 2 = y min 34 = fx () -1.5 -1 -0.5 0 0.5 1 1.5 -40 -20 0 20 40 60 80 100
Background image of page 2
Script and Function Files Signals and Systems with MATLAB Computing and Simulink Modeling, Fourth Edition A 29 Copyright © Orchard Publications
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Signals.and.Systems.with.MATLAB.Computing.and.Simulink.Modeling.4th_Part73

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

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