home *** CD-ROM | disk | FTP | other *** search
-
- NAME
- Integra.lib v1.0a
-
- COPYRIGHT
- (C) Copyright 1994,95 Daniele Finocchiaro, Gianluca Marcoccia
-
- FUNCTION
- Integra.lib is a library package for the numerical
- computation of definite one-dimensional integrals.
-
- AUTHORS
- Daniele Finocchiaro, Gianluca Marcoccia
- (marcocci@cli.di.unipi.it)
-
- CREATION DATE
- 24-Oct-1994
-
- MODIFICATION HISTORY
- v1.0 - (24-10-94) initial release at IPISA 1994
-
- v1.0a - (06-02-95) nearly complete rewriting of the documentation
- added english docs and rearranged distribution
-
- TABLE OF CONTENTS
-
- Integra.lib/Int_function
- Integra.lib/Int_string
- Integra.lib/Int_points
- Integra.lib/Int_eq_points
- Integra.lib/Int_points_p
- Integra.lib/Int_eq_points_p
- Integra.lib/Parse_addfunction
- Integra.lib/Parse_eval
- Integra.lib/Parse_evalx
- Integra.lib/Int_function Integra.lib/Int_function
-
- NAME
- Int_functions -- calculate integral on supplied f(x)
-
- SYNOPSIS
- result = Int_function( &foobar, 0.0, 1.0, &pr )
-
- double Int_function( double (*f)(double),
- double from, double to, int *prec);
-
- /* Function e^(-x^2) */
- double foobar(double x) { return exp(-x*x); }
-
- int pr = 15;
-
- FUNCTION
- The algorithm will evaluate the C function f() passed as an argument.
- At exit, (*prec) is usually bigger(or equal to) than the value passed
- to the function. This might not happen if the integration routined
- met particular difficulties with the provided function.
- (if prec=0 or (*prec) is out of 0..18 range,
- default value of 15 is used)
-
- INPUTS
- f - pointer to a C function that requires a double
- and returns a double
- from - lower limit of the range of integration
- to - upper limit
- prec - pointer to an integer containing the number of
- precision digits required (default=15)
-
- RESULT
- result - value of the integral. When this value is returned
- in (*prec) you can find the number of digits exstimated
- to be exact.
-
- EXAMPLE
-
- NOTES
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_string
-
- Integra.lib/Int_string Integra.lib/Int_string
-
- NAME
- Int_string -- calculate integral on supplied string function
-
- SYNOPSIS
- result = Int_string( "e^(-x*x)", 0., 1., &pr );
-
- double Int_string( char *expr, double from, double to, int *prec);
-
- int pr = 15;
-
- FUNCTION
- The algorithm will evaluate the function f() passing the string to
- Parse_evalx( expr, x ).
- This is a parser function that evaluates a string containing a
- function. Read the documentation about the parser function for the
- format used in the string.
- About `prec' see previous function.
-
-
- INPUTS
- expr - string containing expression for f(x)
- from - lower limit of the range of integration
- to - upper limit
- prec - pointer to an integer containing the number of precision
- digits required (default=15)
-
- RESULT
- result - value of the integral. When this value is returned
- in (*prec) you can find the number of figures exstimated
- to be exact.
-
- EXAMPLE
-
- NOTES
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_function
- Integra.lib/Parse_addfunction
- Integra.lib/Parse_eval
- Integra.lib/Parse_evalx
-
- Integra.lib/Int_points Integra.lib/Int_points
-
- NAME
- Int_points - calculate integral of function already known
- in some points
-
- SYNOPSIS
- result = Int_points(100,x,fx);
-
- double Int_points(int n, double x[n], double fx[n])
-
- double x[100] = { .. , .. , .. ... .. };
- double fx[100] = { .. , .. , .. ... .. };
-
- FUNCTION
- This function is used to integrate functions that are
- already known on a assigned set of point. This means, for example,
- that the values of x and f(x) have been previously obtained by some
- kind of measurements, and now we need to evaluate an approximation
- of the integral of f(x). This problem shows up often in practical
- applications.
- In this version we have implemented an interpolatory formula on 5
- points. On an intuitive basis this means that every 5 points we
- create the interpolation polinomial of fifth degree that passes
- thru these 5 points, and we calculate the integral of this one.
-
- INPUTS
- n - number of points (>=2)
- x[] - array containing x points where we know f(x)
- fx[] - array containing values of f(x[i])
-
- RESULT
- result - evaluation of the integral.
-
- EXAMPLE
-
- NOTES
- BEWARE: utilization of this routine is to be avoided as it implements
- a much simpler integration method. (it is very fast anyway)
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_points_p
-
- Integra.lib/Int_eq_points Integra.lib/Int_eq_points
-
- NAME
- Int_eq_points - calculate the integral of function already known
- in equidistribuited points
-
- SYNOPSIS
- result = Int_eq_points(100,0.1,fx);
-
- double Int_eq_points(int n, double h, double fx[n])
-
- double fx[100] = { .. , .. , .. ... .. };
-
- FUNCTION
- In this function we assume x points to be equidistribuited at a
- distance of 'h' each other. In general:
-
- x[i] = x[0] + i*h
-
- Assuming this we can implement a much more efficient version of the
- previous function, as far as the weights of the integration formula
- are predefined. This algorithm is an extension to 5 points of the
- Cavalieri-Simpson procedure. (which works with 3 points)
-
- INPUTS
- n - number of points (>=2)
- h - offset between x(es)
- fx[] - array containing values of f(x[i])
-
- RESULT
- result - evaluation of the integral.
-
- EXAMPLE
-
- NOTES
- BEWARE: utilization of this routine is to be avoided as it implements
- a much simpler integration method. (it is very fast anyway)
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_eq_points_p
-
- Integra.lib/Int_points_p Integra.lib/Int_points_p
-
- NAME
- Int_points_p -- calculate integral of function already known in some
- points, also returns partial results of the
- computation
-
- SYNOPSIS
- result = Int_points_p(100,x,fx,part);
-
- double Int_points_p(int n, double x[n],
- double fx[n], double partial[n-1]);
-
- double x[100] = { .. , .. , .. ... .. };
- double fx[100] = { .. , .. , .. ... .. };
- double *part;
-
- FUNCTION
- This function returns also intermediate approximations,
- this is to say that it will return the evaluation of the integral
- every time it adds a point to the solution.
- This function is the same as Int_points, but returns in the partial[]
- array all the intermediate values of the integral this is to say:
-
- partial[i] = integral of f(x) between x[0] and x[i+1]
-
- In particular partial[n-2] is the value returned by the function.
-
- INPUTS
- n - number of points (>=2)
- x[] - array containing x points where we know f(x)
- fx[] - array containing values of f(x[i])
- partial[] - array to be filled with partial integral values
-
- RESULT
- result - evaluation of the integral.
-
- EXAMPLE
-
- NOTES
- CAVEAT: if partial==NULL Int_points() gets called instead.
-
- BEWARE: utilization of this routine is to be avoided as it implements
- a much simpler integration method. (it is very fast anyway)
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_points
-
- Integra.lib/Int_eq_points_p Integra.lib/Int_eq_points_p
-
- NAME
- Int_eq_points_p -- calculate the integral of function already known
- in equidistribuited points, also returns
- partial results of the computation
-
- SYNOPSIS
- result = Int_eq_points_p(100,0.1,fx,part);
-
- double Int_eq_points_p(int n, double h,
- double fx[n], double partial[n-1]);
-
- double fx[100] = { .. , .. , .. ... .. };
- double *part;
-
- FUNCTION
- Same as previous function, but x points are equidistributed.
-
- INPUTS
- n - number of points (>=2)
- h - offset between x(es)
- fx[] - array containing values of f(x[i])
- partial[] - array to be filled with partial integral values
-
- RESULT
- result - evaluation of the integral.
-
- EXAMPLE
-
- NOTES
- CAVEAT: if partial==NULL Int_eq_points() gets called instead.
-
- BEWARE: utilization of this routine is to be avoided as it implements
- a much simpler integration method. (it is very fast anyway)
-
- BUGS
-
- SEE ALSO
- Integra.lib/Int_eq_points
-
- Integra.lib/Parse_addfunction Integra.lib/Parse_addfunction
-
- NAME
- Parse_addfunction -- add a function to the directory
- of known functions
-
- SYNOPSIS
- result = Parse_addfunction("foo",&foobar);
-
- int Parse_addfunction(char *name, double (*f)(double) );
-
- double foobar(double x) { return cos(x)*(x+1); }
-
- FUNCTION
- The function Parse_addfunction adds the specified function to the
- directory of acknowledged functions.
- This way of operation is useful when a certain function is known at
- compilation time, and you can write explicitely the code that
- calculates it. In this way we can implement further functions which
- are not supplied (yet).
-
- INPUTS
- name - a name to be used as reference to the function
- f - pointer to the function to be added and associated to
- the 'name'.
-
- RESULT
- This function returns 0 if everything is ok, -1 if it was not
- possible to add the function (actually the only possible reason
- for this it is that the directory is full).
-
- EXAMPLE
- if ( Parse_addfunction("foo",&foobar) )
- { exit(1); }
- else
- { ... }
-
- NOTES
- Actually you can only use unary functions
- (that need only one argument).
-
- BUGS
-
- SEE ALSO
- Integra.lib/Parse_eval
- Integra.lib/Parse_evalx
-
- Integra.lib/Parse_eval Integra.lib/Parse_eval
-
- NAME
- Parse_eval - evaluate a string which contains a function
-
- SYNOPSIS
- result = Parse_eval("2+2");
-
- double Parse_eval(char *expr);
-
- FUNCTION
- Evaluates a string which contains the ascii definition of a function.
-
- INPUTS
- Expression String Sintax
-
- More or less the sintax is the one used to insert expression on
- a calculator. For example:
-
- 3*5+(2+sin(4))^2
-
- Operators as *, +, -, /, ^ (power), % (remaining of integer division)
- and functions as
-
- cos cosin
- sin sin
- tan, tg tangente
- arccos, acos arc-cosin
- arcsin, asin arc-sin
- arctan, arctg, atn, atan arc-tangente
- cosh iperbolic cosin
- sinh iperbolic sin
- tanh iperbolic tangente
- ln natural logarithm
- log, log10 10-base logarithm
- sqrt square root
- abs absolute value
- exp exponent (natural base)
- int integer part
-
- Moreover there are these predefined values:
- p pigreco
- e Nepero's number
-
- As said above, using Parse_addfunction() it is possible to add more
- unary functions.
-
- The order used when evaluating is the usual one (unary function
- first, multiplications, addition) but can be arranged using brackets.
-
- Assignments to variables are supported. In this version these
- operations are limited to constant values or other variables.
- The assignment is followed by a comma and the expression to be
- evaluated.
- For example:
-
- z=2,z^2+z^3
-
- evaluates "2^2+2^3" giving 12 as result. This kind of operation will
- probably be extended in future releases.
-
- RESULT
- result - evaluation of string
-
- At exit, variable Parse_error indicates whether there were errors
- (0 all is ok). The result is to be taken in consideration only
- if Parse_error=0.
-
- EXAMPLE
-
- NOTES
- CAVEAT: beware of unary minus. String "-1^2" gets evaluated
- as "(-1)^2", thus giving 1 as result. Instead, "5-1^2" is considered
- as "5-(1^2)" and its result is 4.
- As this behaviour is NOT STANDARD, this will probably be changed in
- future releases. Always use brackets when in doubt.
-
- BUGS
- Actually there are some cases in which the parser is unable
- to certify the string. (these, anyway, are not relevant)
-
- SEE ALSO
- Integra.lib/Parse_addfunction
- Integra.lib/Parse_evalx
-
- Integra.lib/Parse_evalx Integra.lib/Parse_evalx
-
- NAME
- Parse_evalx -- evaluates a string which contains indeterminate x
-
- SYNOPSIS
- result = Parse_evalx("x+x",valx);
-
- double Parse_evalx(char *expr, double x);
-
- double valx = 2;
-
- FUNCTION
- Evaluates a string inside which there is the indeterminate 'x'.
-
- INPUTS
- See Parse_eval() for the syntax of the expression string.
-
- x - This value will bereplaced in the expression for every
- occurrence of the x indeterminate.
-
- RESULT
- result - evaluation of string
-
- At exit, variable Parse_error indicates wether there were errors
- (0 all is ok). The result is to be taken in consideration only
- if Parse_error=0.
-
- EXAMPLE
-
- NOTES
- CAVEAT: beware of unary minus. String "-1^2" gets evaluated
- as "(-1)^2", thus giving 1 as result. Instead, "5-1^2" is considered
- as "5-(1^2)" and its result is 4.
- As this behaviour is NOT STANDARD, this will probably be changed in
- future releases. Always use brackets when in doubt.
-
- BUGS
- Actually there are some cases in which the parser is unable
- to certify the string. (these anyway are not relevant)
-
- SEE ALSO
- Integra.lib/Parse_addfunction
- Integra.lib/Parse_eval
-
-