//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
+//
// <-- CLI SHELL MODE -->
+//
// <-- ENGLISH IMPOSED -->
-// Run with test_run('differential_equations','intg',['no_check_error_output'])
ilib_verbose(0);
// Function written in the Scilab language
function y = f(x), y = x*sin(30*x)/sqrt(1-((x/(2*%pi))^2)), endfunction
// Function written in Fortran (a Fortran compiler is required)
// define a Fortran function
cd TMPDIR;
-F=[' double precision function ffun(x)'
- ' double precision x, pi'
- ' pi = 3.14159265358979312d+0'
- ' ffun = x*sin(30.0d+0*x)/sqrt(1.0d+0-(x/(2.0d+0*pi))**2)'
- ' return'
- ' end'];
-mputl(F, fullfile(TMPDIR, 'ffun.f'));
+F=[" double precision function ffun(x)"
+" double precision x, pi"
+" pi = 3.14159265358979312d+0"
+" ffun = x*sin(30.0d+0*x)/sqrt(1.0d+0-(x/(2.0d+0*pi))**2)"
+" return"
+" end"];
+mputl(F, fullfile(TMPDIR, "ffun.f"));
// compile the function
-l = ilib_for_link('ffun', 'ffun.f', [], 'f');
+l = ilib_for_link("ffun", "ffun.f", [], "f");
// add the function to the working environment
-link(l, 'ffun', 'f');
+link(l, "ffun", "f");
// integrate the function
-I = intg(0, 2*%pi, 'ffun');
+I = intg(0, 2*%pi, "ffun");
abs(exact-I);
if abs(exact-I) > 1e-9 then bugmes();quit;end
// Function written in C (a C compiler is required)
// define a C function
-C=['#include <math.h>'
- 'double cfun(double *x)'
- '{'
- ' double y, pi = 3.14159265358979312;'
- ' y = *x/(2.0e0*pi);'
- ' return *x*sin(30.0e0**x)/sqrt(1.0e0-y*y);'
- '}'];
-mputl(C, fullfile(TMPDIR, 'cfun.c'));
+C=["#include <math.h>"
+"double cfun(double *x)"
+"{"
+" double y, pi = 3.14159265358979312;"
+" y = *x/(2.0e0*pi);"
+" return *x*sin(30.0e0**x)/sqrt(1.0e0-y*y);"
+"}"];
+mputl(C, fullfile(TMPDIR, "cfun.c"));
// compile the function
-l = ilib_for_link('cfun', 'cfun.c', [], 'c');
+l = ilib_for_link("cfun", "cfun.c", [], "c");
// add the function to the working environment
-link(l, 'cfun', 'c');
+link(l, "cfun", "c");
// integrate the function
-I = intg(0, 2*%pi, 'cfun');
+I = intg(0, 2*%pi, "cfun");
if abs(exact-I) > 1e-9 then bugmes();quit;end
// Test third output argument
[i, err, ierr] = intg(0, 1, f);
if abs(ierr) <> 0 then bugmes();quit;end
+prot = funcprot();
+funcprot(0);
function y = f(x), y = cos(x); endfunction
-Warning : redefining function: f . Use funcprot(0) to avoid this message
-
+funcprot(prot);
[i, err, ierr] = intg(0, %pi, f);
Warning: Round-off error detected, the requested tolerance (or default) cannot be achieved. Try using bigger tolerances.
if abs(ierr) <> 2 then bugmes();quit;end
// IEEE compatibility
// Error 264: "Wrong value for argument #i: Must not contain NaN or Inf."
-if execstr("I = intg(%inf, 0, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(-%inf, 0, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(%nan, 0, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(0, %inf, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(0, -%inf, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(0, %nan, f)", 'errcatch') <> 264 then bugmes();quit;end
-if execstr("I = intg(%nan, %nan, f)", 'errcatch') <> 264 then bugmes();quit;end
+if execstr("I = intg(%inf, 0, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(-%inf, 0, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(%nan, 0, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(0, %inf, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(0, -%inf, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(0, %nan, f)", "errcatch") <> 264 then bugmes();quit;end
+if execstr("I = intg(%nan, %nan, f)", "errcatch") <> 264 then bugmes();quit;end