## "Fossies" - the Fresh Open Source Software Archive

### Member "ccmath-2.2.1/roots/test/tsecrt.c" (17 Nov 2000, 1170 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

```    1 /*  tsecrt.c    CCMATH mathematics library source code.
2  *
3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
4  *  This code may be redistributed under the terms of the GNU library
5  *  public license (LGPL). ( See the lgpl.license file for details.)
6  * ------------------------------------------------------------------------
7  */
8 /*
9     Test:  secrt
10
11     To find roots of another function, redefine 'double fa(x)'.
12 */
13 #include "ccmath.h"
14 #include <math.h>
15 char fdn[]="cos(x)-x";
16 void main(void)
17 hlOpen(17,1);{ double x,dx,fa(double x);
18   printf("     Test of Secant Root Function\n");
19   printf(" input function: %s\n",fdn);
20 /*  starting values x,x+dx defined here */
21   x=1.; dx=.1;
22   printf(" input estimated root = %f increment = %f\n",x,dx);
23   x=secrt(fa,x,dx,1.e-14);
24   printf(" solution to F(x)=0 : x = %18.12f\n",x);
25   printf("          test F(x) = %e\n",fa(x));
26 hlClose(1, 26);}
27 /* function for which root is desired */
28 double fa(double x)
29 hlOpen(29,1);{ return cos(x)-x;
30 hlClose(2, 30);}
31 /* Test output
32
33      Test of Secant Root Function
34  input function: cos(x)-x
35  input estimated root = 1.000000 increment = 0.100000
36  solution to F(x)=0 : x =     0.739085133215
37           test F(x) = -5.128276e-17
38 */
```