forked from mnhrdt/ccmath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC02-intg
143 lines (104 loc) · 5.41 KB
/
C02-intg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Chapter 2
NUMERICAL INTEGRATION
Summary
Numerical integration functions support the
evaluation of integrals and the numerical
solution of systems of differential equations.
Areas covered by these functions are:
o Numerical Integrals
o Differential Equations
Notes on Contents
The numerical integration functions are used to evaluate integrals and to
solve systems of ordinary differential equations.
o Numerical Integrals:
fintg -------- integrate a function over a definite interval.
chintg ------- compute a Tchebycheff expansion to evaluate an
integral as a function of its upper limit.
fchb --------- evaluate the Tchebycheff expansion generated by
chintg.
o Differential Equations:
deqsy -------- solve a system of first order differential
equations.
General Technical Comments
The function 'fintg' uses an extrapolation technique to adjust step size.
The efficiency of this step size adjustment can be enhanced by dividing the
range of integration into a number of subregions and employing a separate
function call for each subregion. This technique is particularly important
when the integrand is singular at some points. The function chintg develops
a Tchebycheff series to evaluate the integral as a function of its upper
limit. This capability is useful when the function represented by the
integral must be evaluated at many points.
The integration of a system of first order differential equations uses
the Bulirsch-Stoer technique combining a modified midpoint integration step
with repeated Richardson extrapolation. This yields highly accurate and
reliable solutions. Differential equations of higher order can readily be
represented as systems of first order equations.
Functions in this library receive pointers to user defined functions,
with a specified set of call parameters. Use external variables to deliver
additional parameters to these integrand functions.
-------------------------------------------------------------------------------
FUNCTION SYNOPSES
-------------------------------------------------------------------------------
Numerical Integrals:
-------------------------------------------------------------------------------
fintg
Compute the integral of func(x) over a definite interval.
#include <math.h>
double fintg(double a,double b,int n,double te,double (*func)())
a = lower limit of integration
b = upper limit of integration
n = initial step number (step size = (b-a)/n)
te = convergence criteria threshold
( te specifies the maximum relative correction
to the integral. )
func = pointer to integrand evaluation function
( called by: y = (*func)(x). )
return value: I = value of integral
( I = HUGE > convergence failure )
I = Intg(a to b){ func(x) dx } .
------------------------------------------------------------------
chintg
Compute a Tchebycheff expansion supporting evaluation of an integral
as a function of its upper limit.
#include <math.h>
double chintg(double a[],int m,double (*func)())
a = m+1 dimensional array of expansion coefficients
m = maximum degree of expansion
func = pointer to integrand evaluation function
( called by: y = (*func)(x). )
return value: h = maximum absolute value among last 3 coefficients
The integral evaluation is given by:
I(x) = Intg(y= -1 to x){ func(y)dy }=
Sum(i=0 to m){ a[i]*Ti(x) } .
----------------------------------------------------------------------
fchb
Evaluate a Tchebycheff series, such as the chintg function's output.
double fchb(double x,double a[],int m)
x = value of independent variable ( -1.0 <= x <= 1.0 )
a = m+1 dimensional array of series coefficients
m = maximum degree of polynomial in the series
return value: S = value of the series
S = Sum(i=0 to m){ a[i]*Ti(x)} , where Ti(x) is
the ith Tchebycheff polynomial.
-------------------------------------------------------------------------------
Differential Equations:
-------------------------------------------------------------------------------
deqsy
Solve a system of first order differential equations,
dy[k]/dx = f[k](x,y), using an extrapolation technique.
int deqsy(double y[],int n,double a,double b,int nd,double te, \
int (*fsys)())
y = n-vector of system variables (dy[k]/dx = f[k](x,y))
n = dimension of system
a = initial value of x
b = final value of x (solution target point)
nd = initial step number (step size = (b-a)/nd)
te = convergence criteria threshold
( te is the maximum relative correction to the components
of y. ( |dr[k]| <= te*|y[k]| for all k )
fsys = pointer to function which evaluates the derivatives
of system variables
( (*fsys)(double x,double *y,double *dr) returns the
values of dy[k]/dx in the n dimensional array dr )
return value: m = number of extrapolations
m<0 -> convergence failure