1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2007-2008 - INRIA
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
8 // <-- CLI SHELL MODE -->
9 // <-- ENGLISH IMPOSED -->
11 // Run with test_run('differential_equations','intg',['no_check_error_output'])
14 // Function written in the Scilab language
15 function y = f(x), y = x*sin(30*x)/sqrt(1-((x/(2*%pi))^2)), endfunction
16 exact = -2.5432596188;
17 I = intg(0, 2*%pi, f);
18 if abs(exact-I) > 1e-9 then pause, end
20 // Function with an argument written in the Scilab language
21 function y = f1(x, w), y = x*sin(w*x)/sqrt(1-((x/(2*%pi))^2)), endfunction
22 I = intg(0, 2*%pi, list(f1, 30));
23 if abs(exact-I) > 1e-9 then pause, end
25 // Function written in Fortran (a Fortran compiler is required)
26 // define a Fortran function
28 F=[' double precision function ffun(x)'
29 ' double precision x, pi'
30 ' pi = 3.14159265358979312d+0'
31 ' ffun = x*sin(30.0d+0*x)/sqrt(1.0d+0-(x/(2.0d+0*pi))**2)'
34 mputl(F, fullfile(TMPDIR, 'ffun.f'));
36 // compile the function
37 l = ilib_for_link('ffun', 'ffun.f', [], 'f');
39 // add the function to the working environment
42 // integrate the function
43 I = intg(0, 2*%pi, 'ffun');
45 if abs(exact-I) > 1e-9 then pause,end
47 // Function written in C (a C compiler is required)
48 // define a C function
49 C=['#include <math.h>'
50 'double cfun(double *x)'
52 ' double y, pi = 3.14159265358979312;'
54 ' return *x*sin(30.0e0**x)/sqrt(1.0e0-y*y);'
56 mputl(C, fullfile(TMPDIR, 'cfun.c'));
58 // compile the function
59 l = ilib_for_link('cfun', 'cfun.c', [], 'c');
61 // add the function to the working environment
64 // integrate the function
65 I = intg(0, 2*%pi, 'cfun');
66 if abs(exact-I) > 1e-9 then pause,end
68 // Test third output argument
69 [i, err, ierr] = intg(0, 1, f);
70 if abs(ierr) <> 0 then pause,end
72 function y = f(x), y = cos(x); endfunction
73 [i, err, ierr] = intg(0, %pi, f);
74 if abs(ierr) <> 2 then pause,end
77 // Error 264: "Wrong value for argument #i: Must not contain NaN or Inf."
78 if execstr("I = intg(%inf, 0, f)", 'errcatch') <> 264 then pause,end
79 if execstr("I = intg(-%inf, 0, f)", 'errcatch') <> 264 then pause,end
80 if execstr("I = intg(%nan, 0, f)", 'errcatch') <> 264 then pause,end
81 if execstr("I = intg(0, %inf, f)", 'errcatch') <> 264 then pause,end
82 if execstr("I = intg(0, -%inf, f)", 'errcatch') <> 264 then pause,end
83 if execstr("I = intg(0, %nan, f)", 'errcatch') <> 264 then pause,end
84 if execstr("I = intg(%nan, %nan, f)", 'errcatch') <> 264 then pause,end