JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
mt.h File Reference

数学関数ヘッダ mt.h More...

#include "common.h"
#include <math.h>
Include dependency graph for mt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef double(* PTR_DFFUNC) (double)
 ニュートン法で解を求める場合の関数の型
 

Functions

double comb (int n, int i)
 
double perm (int n, int i)
 
double fact (int n)
 
double power (double x, double y)
 
int newton_method (PTR_DFFUNC fn, PTR_DFFUNC df, double *t, double e)
 ニュートン法で解を求める
 

Variables

double EPS
 

Detailed Description

Author
Fumi.Iseki (C)

Definition in file mt.h.

Typedef Documentation

◆ PTR_DFFUNC

typedef double(* PTR_DFFUNC) (double)

Definition at line 20 of file mt.h.

Function Documentation

◆ comb()

double comb ( int n,
int m )

double comb(int n, int m)

コンビネーション nCm を計算する.

Definition at line 64 of file mt.cpp.

65{
66 int i;
67 double c, p;
68
69 if (m>n || n<=0 || m<=0) return 0.;
70
71 p = c = 1.0;
72 for (i=n-m+1; i<=n; i++) p = p*(double)i;
73 for (i=1; i<=m; i++) c = c*(double)i;
74
75 return p/c;
76}

◆ fact()

double fact ( int n)

double fact(int n)

nの階乗 n! を計算する.n>0 でない場合は 1.0 を返す.

Definition at line 30 of file mt.cpp.

31{
32 int i;
33 double ret = 1.0;
34
35 if (n>0) for (i=1; i<=n; i++) ret = ret*(double)i;
36 return ret;
37}

◆ newton_method()

int newton_method ( PTR_DFFUNC func,
PTR_DFFUNC dfunc,
double * t0,
double eps )

int newton_method(PTR_DFFUNC func, PTR_DFFUNC dfunc, double* t0, double eps)

ニュートン法で func()==0 の点を求める.
関数の形は double func(double)

Parameters
funcdouble func(double) 型の関数へのポインタ
dfuncfunc()の導関数へのポインタ.
[in,out]t0in: 探索開始点(xの初期値), out: 解.
eps誤差.1に対して 1.0e-8 など.
Returns
解を求めるまでの繰り返し回数.0 の場合は失敗.
See also
PTR_DFFUNC, MAX_ITRTN_NEWTON_METHOD

Definition at line 95 of file mt.cpp.

96{
97 double tt = *t0;
98 double ff = (*func)(tt);
99
100 int n = 1;
101 while (n<MAX_ITRTN_NEWTON_METHOD && Xabs(ff)>eps) {
102 //
103 double df = (*dfunc)(tt);
104 if (Xabs(df)<eps) return 0;
105
106 tt = tt - ff/df;
107 ff = (*func)(tt);
108 n++;
109 }
110
111 if (n==MAX_ITRTN_NEWTON_METHOD) return 0;
112 *t0 = tt;
113 return n;
114}
#define Xabs(x)
Definition common.h:257
#define MAX_ITRTN_NEWTON_METHOD
ニュートン法で解を求める際の,最大繰り返し回数.
Definition mt.cpp:79

References MAX_ITRTN_NEWTON_METHOD, and Xabs.

◆ perm()

double perm ( int n,
int m )

double perm(int n, int m)

パームテーション nPm を計算する.

Definition at line 45 of file mt.cpp.

46{
47 int i;
48 double p;
49
50 if (m>n || n<=0 || m<=0) return 0.;
51
52 p = 1.0;
53 for (i=n-m+1; i<=n; i++) p = p*(double)i;
54
55 return p;
56}

◆ power()

double power ( double x,
double y )

double power(double x, double y)

xの y乗 x^yを計算する.

Definition at line 17 of file mt.cpp.

18{
19 if (y==0.0) return 1.0;
20 else if (x==0.0) return 0.0;
21 else return exp((y)*log(x));
22}

Variable Documentation

◆ EPS

double EPS
extern

Definition at line 9 of file mt.cpp.

Referenced by unit_ivector(), and unit_vector().