17-Dec-2012 1> f = inline('x./log(x)') f = f(x) = x./log(x) 2> I1 = 2/6 * (f(3) + 4*f(4) + f(5)) I1 = 5.7930 3> I2 = (f(3) + f(5) + 2*f(4) + 4*(f(3.5) + f(4.5)))/6 I2 = 5.7918 4> I1 - I2 ans = 0.0011609 5> quad(f,3,4) ans = 2.7985 6> quad(f,3,5) ans = 5.7917 7> help quad `quad' is a function from the file /usr/lib/octave/3.6.2/oct/i686-pc-cygwin/quad.oct -- Loadable Function: Q = quad (F, A, B) -- Loadable Function: Q = quad (F, A, B, TOL) -- Loadable Function: Q = quad (F, A, B, TOL, SING) -- Loadable Function: [Q, IER, NFUN, ERR] = quad (...) Numerically evaluate the integral of F from A to B using Fortran routines from QUADPACK. F is a function handle, inline function, or a string containing the name of the function to evaluate. The function must have the form `y = f (x)' where Y and X are scalars. A and B are the lower and upper limits of integration. Either or both may be infinite. The optional argument TOL is a vector that specifies the desired accuracy of the result. The first element of the vector is the desired absolute tolerance, and the second element is the desired relative tolerance. To choose a relative test only, set the absolute tolerance to zero. To choose an absolute test only, set the relative tolerance to zero. Both tolerances default to `sqrt(eps)' or approximately 1.5e^-8. The optional argument SING is a vector of values at which the integrand is known to be singular. The result of the integration is returned in Q. IER contains an integer error code (0 indicates a successful integration). NFUN indicates the number of function evaluations that were made, and ERR contains an estimate of the error in the solution. The function `quad_options' can set other optional parameters for `quad'. Note: because `quad' is written in Fortran it cannot be called recursively. This prevents its use in integrating over more than one variable by routines `dblquad' and `triplequad'. See also: quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad Additional help for built-in functions and operators is available in the on-line version of the manual. Use the command `doc ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list. 8> M = 1000; 9> x = linspace(3, 5-2/M, M); 10> Ips = 2/M * sum(f(x)) Ips = 5.7913 11> xd = linspace(3+2/M, 5, M); 12> Ipd = 2/M * sum(f(xd)) Ipd = 5.7921 13> M = 1000000; 14> M = 1.e6; 15> M M = 1000000 16> x = linspace(3, 5-2/M, M); 17> xd = linspace(3+2/M, 5, M); 18> Ips = 2/M * sum(f(x)) Ips = 5.7917 19> Ipd = 2/M * sum(f(xd)) Ipd = 5.7917 20> format long 21> Ips = 2/M * sum(f(x)) Ips = 5.79171832753196 22> Ipd = 2/M * sum(f(xd)) Ipd = 5.79171907944595 23> M = 1.e12; 24> x = linspace(3, 5-2/M, M); 24> xd = linspace(3+2/M, 5, M); 24> M = 1.e10; 25> x = linspace(3, 5-2/M, M); 25> M = 1.e9; 26> x = linspace(3, 5-2/M, M); 26> M = 1.e8; 27> x = linspace(3, 5-2/M, M); 28> xd = linspace(3+2/M, 5, M); 29> Ips = 2/M * sum(f(x)) 29> M = 1.e7; 30> x = linspace(3, 5-2/M, M); 31> xd = linspace(3+2/M, 5, M); 32> Ips = 2/M * sum(f(x)) Ips = 5.79171866589320 33> Ipd = 2/M * sum(f(xd)) Ipd = 5.79171874108460 34> quad(f,3,5) ans = 5.79171870348890 35> quadl(f,3,5) ans = 5.79171870348890 36> 2*cos(0.64)-1.28*sin(0.64) ans = 0.839781350824723 37> 0.4 * sin(0.64) ans = 0.238878176544957 38> quad('sin(x.^2)', 0, 0.8) warning: quad: passing function body as a string is obsolete; please use anonymous functions ans = 0.16574 39> 0.4 * sin(0.64) ans = 0.23888 40> quit;