File: newton.c

package info (click to toggle)
src2tex 2.12h-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,136 kB
  • sloc: ansic: 5,679; sh: 405; makefile: 95; lisp: 46; sed: 39
file content (76 lines) | stat: -rw-r--r-- 2,151 bytes parent folder | download | duplicates (5)
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
/* {\hrulefill} *

{\bf Newton-Raphson ˡ}

 $f(x)=0$ 򤯤ˤϡ

$\displaystyle\qquad
	x_0=a,\quad x_{n+1}=x_n-{f(x_n)\over f'(x_n)}
	\qquad\cdots\cdots\ (\star)$

Ŭʽ $a$ ФƲ򤤤ơ $\{x_n\}$ 롣
 $a$ ޤͿСοϾҤ
Ĥβ $\alpha$ ˡ«뤳ȤΤƤ, {\it i.e.},

$\displaystyle\qquad
	\exists\ \alpha=\lim_{n\to\infty}x_n
	\quad such\ that\quad f(\alpha)=0\ .$

 $(\star)$ ΰ̣Ȥμ«ͻҤϡοޤȼ򸫤
Ǥ롣

{\special{epsfile=newton.eps hscale=.7 vscale=.7 hoffset=25}
\vskip 12cm}

$\displaystyle\qquad
	y-f(x_n)=f'(x_n)(x-x_n)
	\qquad\cdots\cdots\ \hbox{}\ (x_n,f(x_n))\ \hbox{̤}$

$\displaystyle\qquad
	x_n-{f(x_n)\over f'(x_n)}
	\qquad\cdots\cdots\ \hbox{嵭}\ x\ \hbox{Ȥθ}
	\ x\ \hbox{ɸ}$

 $\{x_n\}$ μ«ξӼ«Υɾϡ
ۤɴñʤȤǤϤʤ$\epsilon$-$\delta$ ˡȲϳؤ˴ؤ
μɬפȤ롣̣ΤˤϡʸҲ𤹤롣

ʲC newton.c ϡ

$\qquad\displaystyle x^2-5=0$

βΣĤ $\sqrt{5}$ Ǥ뤳ȤܤơNewton-Raphson ˡ $\sqrt{5}$
ץǤ롣{\tt A, F(X), DF(X)} 򤤤
Ѥơƿͤǿͼ¸ԤäƤߤ褦

* {\hrulefill} */


/* {\hrulefill\ newton.c\ \hrulefill} */


#include <stdio.h>
#define A 4.				/*  {\hfill} */
#define F(X) ((X)*(X)-5.)		/* Ϳ줿ؿ {\hfill} */
#define DF(X) (2.*(X))			/* Ƴؿ {\hfill} */

main()
{
    double x, y;			/* ٤Ƿ׻ {\hfill} */

    x = A;				/* $\displaystyle x_0=a$ {\hfill} */
    printf("%.16f\n", x);		/* $x_0$ ɽ {\hfill} */
    y = x - F(x) / DF(x); 		/* $\displaystyle
				   	x_1=x_0 - {f(x_0)\over f'(x_0)}$
					{\hfill} */
    printf("%.16f\n", y);		/* $x_1$ ɽ {\hfill} */
    while (x != y)			/* {\ iteration äƤ
					   ͤѤʤʤä齪λ
					   \hfill} */
    {
	x = y;
	y = x - F(x) / DF(x); 		/* $\displaystyle x_{n+1}=x_n
				   	- {f(x_n)\over f'(x_n)}$ {\hfill} */
	printf("%.16f\n", y);		/* $x_{n+1}$ ɽ {\hfill} */
    }
}