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

  1. %QUADDEMO Demonstrate adaptive numerical quadrature.
  2.  
  3. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  4.  
  5. echo on
  6. clc
  7. %   Quadrature is a technique used to numerically evaluate
  8. %   integrals, i.e. to calculate definite integrals. In MATLAB
  9. %   a function called QUAD implements quadrature using a
  10. %   recursive adaptive Simpson's rule.
  11.  
  12. %   Consider a function called HUMPS(x) that we've defined in 
  13. %   an M-file on disk,
  14.  
  15. type humps
  16. pause   % Strike any key to continue.
  17.  
  18. %   Let's plot this function on the interval from 0 to 1,
  19.  
  20. fplot('humps',[0,1]')
  21. title('Plot of the function HUMPS(x)'), pause
  22. clc
  23. %   To integrate this function over the interval  0 < x < 1  we
  24. %   invoke QUAD:
  25.  
  26. % Q = quad('humps',0,1)
  27.  
  28. pause   % Strike any key to start plot of iterations.
  29. clc
  30.  
  31. %   QUAD returns the area under the function.
  32. Q = quad('humps',0,1,1e-3,1);
  33. title(['Area is ',num2str(Q)]),
  34. Q
  35.  
  36. echo off
  37. disp('End')
  38.