home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / ZERODEMO.M < prev   
Encoding:
Text File  |  1993-03-07  |  818 b   |  36 lines

  1. %ZERODEMO This demo shows how to find the zero of a function.
  2.  
  3. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  4.  
  5. clf
  6. echo on
  7. clc
  8. %   A function called FZERO is used to find a zero of a function.
  9.  
  10. %   Consider a function called HUMPS(x) that we've defined in 
  11. %   an M-file on disk,
  12.  
  13. type humps
  14. pause   % Press any key to continue.
  15.  
  16. %   Let's plot this function on the interval from 0 to 2,
  17.  
  18. fplot('humps',[0,2]), grid
  19. title('Notice the zero near x = 1.2'), pause
  20. clc
  21. %   To find a zero of this function near x = 1, we invoke FZERO:
  22.  
  23. z = fzero('humps',1)
  24. %   And the value above is the zero near 1.0.
  25.  
  26. pause   % Press any key for plot.
  27.  
  28. x = 0.4:.02:1.6;
  29. y = humps(x);
  30. plot(x,y,z,humps(z),'.')
  31. title('Zero of humps(x)'), grid
  32.  
  33. echo off
  34. h = get(gca,'children');
  35. set(h(1),'markersize',35)
  36.