octave:2> tspan=[0,0.3,0.5,0.7,1] tspan = 0.00000 0.30000 0.50000 0.70000 1.00000 octave:3> diff(tspan) ans = 0.30000 0.20000 0.20000 0.30000 octave:4> tspan(2:5) ans = 0.30000 0.50000 0.70000 1.00000 octave:5> tspan(2:5)-tspan(1:4) ans = 0.30000 0.20000 0.20000 0.30000 octave:6> r=2 r = 2 octave:7> odefun = @(t,y) r * y * (1 - y); octave:8> y0=2 y0 = 2 octave:9> yanalitica = @(t) y0 * exp(r * t) ./ (1 + y0 * (exp(r*t)-1)); octave:10> t = linspace(0,1,51); octave:11> plot(t,yanalitica(t)) octave:12> [tout,yout]=euleroesplicito(odefun,t,y0); octave:13> hold on octave:14> plot(tout,yout,'*r') octave:15> n=10 n = 10 octave:16> octave:16> [1,4,2,4,2,4,2,4,2,4,1] ans = 1 4 2 4 2 4 2 4 2 4 1 octave:17> n n = 10 octave:18> repmat([4,2],1,n/2-1) ans = 4 2 4 2 4 2 4 2 octave:19> test_simpson octave:20> fun = @(x) 100 ./ x .^ 2 .* sin (10 ./ x); octave:21> a=1 a = 1 octave:22> b=3 b = 3 octave:23> [q,x]=simpson_adat(fun,a,b,1e-4); error: 'simpson_adat' undefined near line 1 column 6 octave:23> [q,x]=simpson_adat(fun,a,b,1e-4); octave:24> q q = -1.4260 octave:25> x x = 1.0000 1.0078 1.0156 1.0156 1.0234 1.0312 1.0312 1.0391 1.0469 1.0469 1.0547 1.0625 1.0625 1.0703 1.0781 1.0781 1.0859 1.0938 1.0938 1.1016 1.1094 1.1094 1.1172 1.1250 1.1250 1.1328 1.1406 1.1406 1.1484 1.1562 1.1562 1.1641 1.1719 1.1719 1.1797 1.1875 1.1875 1.2031 1.2188 1.2188 1.2344 1.2500 1.2500 1.2656 1.2812 1.2812 1.2969 1.3125 1.3125 1.3281 1.3438 1.3438 1.3594 1.3750 1.3750 1.3906 1.4062 1.4062 1.4219 1.4375 1.4375 1.4531 1.4688 1.4688 1.4844 1.5000 1.5000 1.5156 1.5312 1.5312 1.5469 1.5625 1.5625 1.5781 1.5938 1.5938 1.6094 1.6250 1.6250 1.6406 1.6562 1.6562 1.6719 1.6875 1.6875 1.7031 1.7188 1.7188 1.7344 1.7500 1.7500 1.7812 1.8125 1.8125 1.8438 1.8750 1.8750 1.9062 1.9375 1.9375 1.9688 2.0000 2.0000 2.0312 2.0625 2.0625 2.0938 2.1250 2.1250 2.1562 2.1875 2.1875 2.2188 2.2500 2.2500 2.2812 2.3125 2.3125 2.3438 2.3750 2.3750 2.4062 2.4375 2.4375 2.4688 2.5000 2.5000 2.5625 2.6250 2.6250 2.6875 2.7500 2.7500 2.8125 2.8750 2.8750 2.9375 3.0000 octave:26> quad(fun,a,b) ans = -1.4260 octave:27> q q = -1.4260 octave:28> format long e octave:29> q q = -1.42601481004944e+00 octave:30> quad(fun,a,b) ans = -1.42602475634626e+00 octave:31> plot(x,fun(x),x,zeros(size(x)),'o') octave:32> abs(q-quad(fun,a,b)) ans = 9.94629681905224e-06 octave:33> help quad 'quad' is a built-in function from the file libinterp/corefcn/quad.cc -- Built-in Function: Q = quad (F, A, B) -- Built-in Function: Q = quad (F, A, B, TOL) -- Built-in Function: Q = quad (F, A, B, TOL, SING) -- Built-in 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 online 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. octave:34> diary off