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 -->
10 // <-- ENGLISH IMPOSED -->
13 // Function written in the Scilab language
14 function y = f(x), y = x*sin(30*x)/sqrt(1-((x/(2*%pi))^2)), endfunction
15 exact = -2.5432596188;
16 I = intg(0, 2*%pi, f);
17 if abs(exact-I) > 1e-9 then pause, end
19 // Function with an argument written in the Scilab language
20 function y = f1(x, w), y = x*sin(w*x)/sqrt(1-((x/(2*%pi))^2)), endfunction
21 I = intg(0, 2*%pi, list(f1, 30));
22 if abs(exact-I) > 1e-9 then pause, end
24 // Function written in Fortran (a Fortran compiler is required)
25 // define a Fortran function
27 F=[" double precision function ffun(x)"
28 " double precision x, pi"
29 " pi = 3.14159265358979312d+0"
30 " ffun = x*sin(30.0d+0*x)/sqrt(1.0d+0-(x/(2.0d+0*pi))**2)"
33 mputl(F, fullfile(TMPDIR, "ffun.f"));
35 // compile the function
36 l = ilib_for_link("ffun", "ffun.f", [], "f");
38 // add the function to the working environment
41 // integrate the function
42 I = intg(0, 2*%pi, "ffun");
44 if abs(exact-I) > 1e-9 then pause,end
46 // Function written in C (a C compiler is required)
47 // define a C function
48 C=["#include <math.h>"
49 "double cfun(double *x)"
51 " double y, pi = 3.14159265358979312;"
53 " return *x*sin(30.0e0**x)/sqrt(1.0e0-y*y);"
55 mputl(C, fullfile(TMPDIR, "cfun.c"));
57 // compile the function
58 l = ilib_for_link("cfun", "cfun.c", [], "c");
60 // add the function to the working environment
63 // integrate the function
64 I = intg(0, 2*%pi, "cfun");
65 if abs(exact-I) > 1e-9 then pause,end
67 // Test third output argument
68 [i, err, ierr] = intg(0, 1, f);
69 if abs(ierr) <> 0 then pause,end
73 function y = f(x), y = cos(x); endfunction
75 [i, err, ierr] = intg(0, %pi, f);
76 if abs(ierr) <> 2 then pause,end
79 // Error 264: "Wrong value for argument #i: Must not contain NaN or Inf."
80 if execstr("I = intg(%inf, 0, f)", "errcatch") <> 264 then pause,end
81 if execstr("I = intg(-%inf, 0, f)", "errcatch") <> 264 then pause,end
82 if execstr("I = intg(%nan, 0, f)", "errcatch") <> 264 then pause,end
83 if execstr("I = intg(0, %inf, f)", "errcatch") <> 264 then pause,end
84 if execstr("I = intg(0, -%inf, f)", "errcatch") <> 264 then pause,end
85 if execstr("I = intg(0, %nan, f)", "errcatch") <> 264 then pause,end
86 if execstr("I = intg(%nan, %nan, f)", "errcatch") <> 264 then pause,end