My algorithm header file instructions

zhaozj2021-02-16  46

MYLIB file instructions

All library functions are compiled in Turbo C 3.0, currently a total of 72 functions, including some algorithms commonly used in mathematical models and numerical analysis, such as various random numbers, matrix classes, complex class operations, integral transformation, function graphics , The operation, various combinations, graphic algorithms, etc.

1. Function name: Error

Function: Capture error, end the program

Usage: void error (char * message)

Parameters: message: Error message

Return: None

2. Function name: _pause

Function: Waiting for the button

Usage: void _pause (void)

Parameters: no

Return: None

3. Function name: _delay

Function: delay

Usage: void _delay (double delaytime)

Parameters: delayTime: seconds (accurate to 1 microseconds)

Return: None

4. Function name: _Time

Function: Take the current system time (the total number of seconds after the day)

Usage: double _time (void)

Parameters: no

Return: The total number of seconds after the day (accurate to 1 microsecond)

5. Function name: _dif

Function: Calculate two time difference (can be used to calculate the runtime runtime)

Usage: Double_DIF (Double Start, Double End)

Parameters: Start: Start Time, End: End Time

Return: Time difference (accurate to 1 microsecond)

Example:

#include "mylib.h"

void main ()

{

Double Start, End, DIF;

START = _Time ();

_DELAY (5.00);

End = _time ();

DIF = _DIF (start, end);

Printf ("/ N% LF,% LF,% lf / n", start, end, dif);

}

6. Function name: _alloc2

Function: Assign a two-dimensional dynamic array

Usage: double ** _ alloc2 (int R, INT C)

Parameters: r: Route, C: Column number

Returns: a two-dimensional dynamic array

7. Function name: _alloc2_int

Function: Assign a two-dimensional dynamic array (integer array)

Usage: int ** _ alloc2_int (int R, INT C)

Parameters: r: Route, C: Column number

Returns: a two-dimensional dynamic array

8. Function name: _alloc2free

Function: Release a two-dimensional dynamic array

Usage: void _alloc2free (double ** x)

Parameters: a two-dimensional dynamic array

Return: None

9. Function name: _dtoa

Function: Convert a double-precision variable into a string (retain three valid decimal numbers)

Usage: void_dtoa (double value, char * string)

Parameters: Value: Double-precision variable, string: string returns: no

10. Function name: _putString

Function: Under the graphical interface, output strings

Usage: void _putString (int X, int y, char * msg, int color)

Parameters: x: Screen X Coordinate, Y: Screen Y Coordinates, MSG: String, Color, Font Color

Return: None

11. Function name: _fac

Function: Ask for a number of steps (number no more than 12)

Usage: long _fac (int N)

Parameters: N: Number

Return: step by flight

12. Function name: _fac2

Function: Seeking a whole number of steps (no more than 32767)

Usage: int _fac2 (INT N, INT * A)

Parameters: N: Number, A: One-dimensional array (number of digits after the delivery of the steps)

Returns: the number of steps

13. Function name: _random

Function: Generate a random number in (0,1) innerly distributed, to initialize the random number generator with Randomize

Usage: double _random (void)

Parameters: no

Return: Random

14. Function Name: _RAND

Function: Generate a random integer that is evenly distributed in (0, SEED)

Usage: int _rand (int seed)

Parameters: SEED: Upper

Return: Random integer

15. Function Name: _AVG

Function: Generate a random number in which evenly distributed in (A, B)

Usage: double _avg (Double A, Double B)

Parameters: a: Down, B: Upper

Return: Random

16. Function name: _STA

Function: Generate a normal distribution random number with MU mean, Sigma is variance

Usage: Double_sta (Double Mu, Double Sigma)

Parameters: MU: mean, Sigma: Various

Return: Normal distribution random

17. Function name: _STA2

Function: Generate a normal distribution random number with MU-mean, sigma varies (fast, but there is bug)

Usage: Double_sta2 (Double Mu, Double Sigma)

Parameters: MU: mean, Sigma: Various

Return: Normal distribution random

18. Function name: _kai

Function: Generate a card distribution with N-as degrees

Usage: double _kai (int N)

Parameters: N: Delivery

Returns: Card Fang Distribution Random

19. Function name: _TDIS

Function: Generate a T distribution with n as degrees of freedom

Usage: double _TDIS (int N)

Parameters: N: Delivery

Return: T Distribution Random

20. Function name: _f function: Generate a F-distribution with N1 and N2

Usage: double _f (int N1, int N2)

Parameters: N1, N2: Delivery

Return: f Distribution Random

Random number part program example:

#include "mylib.h"

void main ()

{

Double _kai (int N);

Long i;

Double R;

Double S, E, D;

s = _time ();

Randomize ();

For (i = 1; i <= 10000; i )

R = _kai (12);

e = _time ();

D = _DIF (s, e);

Printf ("% lf / n", d);

}

21. Function name: _poisson

Function: Generate a Poisson distribution with LAM parameters

Usage: Double_poisson (int K, Double LAM)

Parameters: k, lam: parameters

Return: Poisson distribution random number

22. Function name: _mean

Function: Average of a continuous part of an array

Usage: double _me (double * a, int start, int end)

Parameters: A: Array, Start: Array Start Location, End: An array end position

Return: average

23. Function name: _variance

Function: A variety of consecutive parts

Usage: Double _variance (double * a, int start, int end)

Parameters: A: Array, Start: Array Start Location, End: An array end position

Return: Various

24. Function name: _Linear

Function: linear fit

Usage: double _Linear (double * x, double * y, double * a, double * b, int N)

Parameters: x: Fitting point of the horizontal list, Y: ordinate, A: intercept, B: slope, N: Number of points

Returns: non-biasing measurement of the fit point variance

25. Function Name: _ADJ_FORM

Function: An adjacency matrix is ​​generated by the line connection table

Usage: double ** _ adj_form (double (* a) [3], int N, int m)

Parameters: A: Connection Table (the first two elements in the table are two endpoints, the third element is the weight of the side), N: summary points, M: Side

Return: Neighboring Matrix

26. Function name: _floyd

Function: FLOYD algorithm seeks the shortest path between two points

Usage: double _floyd (int I, int J, int K, double ** d)

Parameters: i, j: two points tag, K: Number of nodes minus one

Return: the shortest path

Example:

#include "mylib.h"

#define max INT_MAX

#define n 7

Double di [n] [n] = {

{MAX, 2.0, 5.0, 3.0, Max, Max, Max},

{2.0, Max, 2.0, Max, Max, 7.0, Max}, {5.0, 2.0, Max, 1.0, 3.0, 5.0, Max},

{3.0, Max, 1.0, Max, 5, Max, Max},

{MAX, MAX, 3.0, 5.0, Max, 1.0, 7.0},

{MAX, 7.0, 5.0, Max, 1.0, Max, 5.0},

{Max, Max, Max, Max, 7.0, 5.0, Max}

}

Void main (void)

{

Double Temp, ** g;

INT I, J;

G = _alloc2 (n, n);

For (i = 0; i

For (j = 0; j

G [i] [j] = di [i] [j];

Temp = _floyd (0, 6, n-1, g);

Printf ("/ N% LF", TEMP);

}

27. Function name: _dijkstra

Function: Dijkstra algorithm for the shortest path between two points

Usage: double _dijkstra (graph ** g, int N, int s, int ince, int * path, int * count)

Parameters: g: Neighboring matrix, N: Number of nodes, S: Start Node, T: End Node, Path: Shortest Path Table, Count: Path

Return: the shortest path

Example:

#include "mylib.h"

#define n 9

#define m 32767

void main ()

{

Graph a [n] [n] = {

M, 4, M, M, M, M, M, 8, M,

4, M, 8, M, M, M, M, 11, M,

M, 8, m, 7, m, 4, m, m, 2,

M, M, 7, M, 9, 14, M, M, M,

M, M, M, 9, M, 10, M, M, M,

M, M, 4, 14, 10, m, 2, m, m,

M, M, M, M, M, 2, M, 1, 6,

8, 11, m, m, m, m, 1, m, 7,

M, M, 2, M, M, M, 6, 7, M,

}

INT * PATH, W, I, J, ** G, COUNT;

Path = (int *) malloc (n * sizeof (int));

G = _alloc2_int (n, n);

For (i = 0; i

For (j = 0; j

G [i] [j] = a [i] [j];

W = _dijkstra (G, N, 0, 6, Path, & count);

Printf ("/ n% d / n", w);

For (i = 0; i

{Printf ("% d", * path); Path ;

}

28. Function name: _0618

Function: 0.618 Function Split function minimum

Usage: double _0618 (double x) (Double X), Double START, DOUBLE END, DOUBLE EPS

Parameters: F: Function name, start, end: left and right intervals, EPS: accuracy

Return: Minimum

Example:

#include "mylib.h"

Double F (double X)

{

RETURN X * X X * 16.0 3.0;

}

void main ()

{

Double F (double x);

Double A, B, R, EPS;

A = -10.0; b = 8.0; EPS = 0.001; R = _0618 (F, A, B, EPS);

Printf ("% lf / n", r);

}

29. Function name: _2div

Function: All single real roots with two-point legal equation

Usage: int _2div (double x), Double A, Double B, Double H, Double EPS,

Double * x, int N, int * m)

Parameters: F: Function name, A, B: left and right intervals, h: step size, eps: accuracy, x: output parameters, store all single real roots, N: estimated values ​​of the roots of equation, M: actual results Number of equation roots

Return: function execution status

Example:

#include "mylib.h"

Double F (double X)

{

Return sin (x);

}

void main ()

{

INT I, N, M;

Double A, B, H, EPS, * X;

n = 3;

X = (double *) Calloc (n, sizeof (double));

IF (x == NULL) exit (1);

A = -2;

B = 7;

H = 0.1;

EPS = 1e-10;

_2DIV (F, A, B, H, EPS, X, N, & M);

Printf ("M =% D / N", M);

For (i = 0; i

Printf ("% E / N", x [i]);

Free (x);

}

30. Function name: _INTEGRAL

Function: Class parabolic method curve points

Usage: double _INTEGRAL (Double X) (Double X), Double Start, Double End, Int N)

Parameters: F: Function name, start, end: left and right intervals, N: number (even)

Return: points value

31. Function name: _INTEGRAL2

Function: Trapezoidal Curve Credits

Usage: double _INTEGRAL2 (Double X), Double START, DOUBLE END, INT DIV

Parameters: f: Function name, start, end: left and right intervals, DIV: The number of partition rooms

Return: points value

32. Function name: _comb

Function: combination

Usage: long _comb (int N, int M)

Parameters: n, m

Return: combination

33. Function name: _rank

Function: arrangement

Usage: long _rank (int N, int M)

Parameters: n, m

Back: Arrangement

34. Function name: _ALLCOMB_DG

Function: Recommend all combinations (called _ALLCOMB)

Usage: void _allcomb_dg (int * ps, int * pe, int elems, int buf [], int bufsz, int ** comb, int * iCount)

parameter:

Return: None

35. Function name: _ALLCOMB

Function: See all combinations

Usage: void_allcomb (int * list, int N, int elems, int **)

Parameters: List: Combination table, N: Number of tables, ELEMS: Number of combined numbers, COMB: All combinations

Return: None

Sample: (including _comb and _rank function)

#include "mylib.h"

void main ()

{

LONG C, D;

INT I, J;

INT ELEM = 3, N = 6, M;

int List [] = {1, 2, 3, 4, 5, 6};

Int ** Comb;

CLRSCR ();

Comb = _alloc2_int (_COMB (N, ELEM), ELEM);

_ALLCOMB (List, N, Elem, COMB);

For (i = 0; i <_comb (n, elem); i )

{

For (j = 0; j

Printf ("% D", Comb [i] [j]);

Printf ("/ n");

}

Printf ("Total:% D / N", _ COMB (n, elem);

n = 12; m = 7;

C = _rank (n, m);

D = _comb (n, m);

Printf ("% ld% ld / n", c, d);

}

36. Function name: _allrank_dg

Function: Hand-arranged problems of M elements (called _allrank)

Usage: void _allrank_dg (int M, INT K, INT S, INT * A, INT * FLAG, INT * iCOUNT, INT ** RANK)

parameter:

Return: None

37. Function name: _allrank

Function: Qualification of M elements

Usage: void _allrank (int M, int ** rank)

Parameters: M: Elements, Rank: All Right Lines

Return: None

Example:

#include "mylib.h"

void main ()

{

Int ** rank, i, j;

CLRSCR ();

Rank = _alloc2_int (120, 5);

_allrank (5, rank);

For (i = 0; i <120; i )

{

For (j = 0; j <5; j )

Printf ("% d", rank [i] [j]);

Printf ("/ n");

IF (i% 20 == 0) getCH ();

}

}

38. Function name: _bolziman

Function: Annealing Algorithm BOLZIMAN Function or Bolziman Machine Learning Rule Function

Usage: int _bolziman (Double de, Double T)

Parameters: DE: Energy difference, T: Current temperature

Returns: Do you accept

39. Function name: _isprime

Function: Judging whether a number is a lot

Usage: int _isprime (long P)

Parameters: P: The number to be judged

Returns: Is it a lot?

40. Function name: _prime function: value of nth quality

Usage: long _prime (int N)

Parameters: n

Back: Number N

Example:

#include "mylib.h"

void main ()

{

Long P = 65537;

INT Prime = 1, N = 12000;

Long PP;

Prime = _ISprime (p);

Printf ("% d / n", prime);

PP = _Prime (n);

Printf ("% ld / n", pp);

}

41. Function name: _Swapi

Function: Exchange two integer data

Usage: void _swapi (int * a, int * b)

Parameters: a, b: Two integer data

Return: None

42. Function name: _SWAPL

Function: Exchange two long integer data

Usage: void _Swapl (long * a, long * b)

Parameters: a, b: Two long integer data

Return: None

43. Function name: _SWAPD

Function: Exchange two double precision type data

Usage: void _swapd (double * a, double * b)

Parameters: a, b: Two double intensive data

Return: None

44. Function name: _inv

Function: Transposition of a one-dimensional array

Usage: void _inv (int * x, int N)

Parameters: x: One-dimensional array, N: number of array elements

Return: None

45. Function name: _sort

Function: Sprinkler

Usage: void _sort (double * x, int N)

Parameters: x: One-dimensional array, N: number of array elements

Return: None

46. ​​Function name: _max2

Function: ask two larger values

Usage: long_max2 (long n, long m)

Parameters: N, M: Long integer

Return: larger value

47. Function name: _min2

Function: Sign in two numbers

Usage: long_min2 (long n, long m)

Parameters: N, M: Long integer

Return: Smaller

48. Function name: _max

Function: Ask for a maximum of the number, and return this location

Usage: double _max (double * array, int n, int * id)

Parameters: Array: One-dimensional array, N: Element number, ID: The location where the maximum value is returned

Return: maximum

49. Function name: _min

Function: Ask for a maximum of the number, and return this location

Usage: double _min (double * array, int n, int * id)

Parameters: array: One-dimensional array, N: element, ID: The location of the minimum value

Return: Minimum

50. Function name: _gcd

Function: See the number of two numbers

Usage: long _gcd (long M, long n) parameters: m, n

Return: the largest number of conventions

51. Function name: _lcm

Function: ask two minimal multiple

Usage: long _lcm (long M, long n)

Parameters: M, N

Return: Minimum male

52. Function name: _initgraph

Function: Initialization Graphics Interface

Usage: void _initgraph (void)

Parameters: no

Return: None

53. Function name: _SetPlotDefault

Function: Set the default drawing interface

Usage: void _setPlotDefault (void)

Parameters: no

Return: None

54. Function name: _plot

Function: draw a function curve

Usage: void _plot (double x) (double x), double st, double end

Parameters: f: Function equation, start, end: left and right intervals

Return: None

Example:

#include "mylib.h"

Double F (double X)

{

RETURN -X * X 8 * x 10;

}

void main ()

{

_INITGRAPH ();

_Plot (f, 2, 10);

While (bioskey (1) == 0);

Closegraph ();

}

55. Function name: _line_equation

Function: Linear equation

Usage: double _line_equation (double x, double a, double b)

Parameters: x: horizontal coordinate, A: intercept, B: slope

Returns: ordinate

56. Function name: _fit

Function: Linear fitted by graphical

Usage: void _fit (double * x, double * y, int N)

Parameters: x: The horizontal scale of the fitting point, Y: ordinate table, N: Number of fitting points

Return: None

Example:

#include "mylib.h"

void main ()

{

Double x [] = {2.0, 3.0, 4.0, 4.5, 5.0, 6.0, 7.2, 8.3, 8.9, 10.0, 14.2},

Y [] = {4.2, 5.5, 7.3, 9.6, 10.1, 12.3, 14.6, 16.9, 19.0, 21.0, 24.9};

_INITGRAPH ();

_Fit (x, y, 11);

While (bioskey (1) == 0);

Closegraph ();

}

57. Function name: _CPLUS

Function: Multiple additional operation

Usage: Complex_Cplus (Complex Z1, Complex Z2)

Parameters: Z1, Z2: Two plural

Returns: the complex number

58. Function name: _cminus

Function: Multiple subtraction operation

Usage: Complex_Cminus (Complex Z1, Complex Z2)

Parameters: Z1, Z2: Two plural

Returns: the complex number

59. Function Name: _cmul Features: Multiplication Multiplication

Usage: Complex_cmul (Complex Z1, Complex Z2)

Parameters: Z1, Z2: Two plural

Returns: the complex number

60. Function name: _CDIV

Function: plural division operation

Usage: Complex_CDIV (Complex Z1, Complex Z2)

Parameters: Z1, Z2: Two plural

Returns: the complex number

61. Function name: _CABS

Function: Module

Usage: double _CABS (Complex Z)

Parameters: z: Multiple

Return: model

62. Function name: _croot

Function: Roots of complexes

Usage: void _croot (Complex Z1, INT N, Complex * Z)

Parameters: z1: Multiple, N: N times, z: Store N roots

Return: None

63. Function name: _cpow

Function: Power Operation

Usage: Complex_cpow (Complex Z1, Double W)

Parameters: Z1: Multiple, W: Power

Return: Multiple power

64. Function name: _lag

Function: LagRange interpolation calculation

Usage: double _lag (double * x, double * y, double t, int N)

Parameters: x: Interpolated Sidal Table, Y: Disposal Point of Interpolated Point, T: Trouble Point, N: Interpolated Point

Returns: Function value of interpolated points

Example:

#include "mylib.h"

void main ()

{

Int n;

Double * x, * y, t, sum;

T = 0.15;

n = 6;

X = (double *) Calloc (n, sizeof (double));

IF (x == NULL) exit (1);

Y = (double *) Calloc (n, sizeof (double));

IF (y == NULL) EXIT (1);

X [0] = 0; x [1] = 0.1; x [2] = 0.195; x [3] = 0.3; x [4] = 0.401; x [5] = 0.5;

y [0] = 0.39894; y [1] = 0.39695; y [2] = 0.39142; y [3] = 0.38138; y [4] = 0.36812; y [5] = 0.35206;

SUM = _LAG (x, y, t, n);

Printf ("% lf / n", sum);

Free (x);

Free (y);

}

65. Function name: _newt

Function: Newton interpolation calculation

Usage: double _newt (double * x, double * y, int N, double t)

Parameters: x: Interpolated Sidal Table, Y: Longitudinal Table of Interpolation Point, N: Interpolated Point, T: Trouble Point

Returns: Function value of interpolated points

66. Function name: _MGAUSS

Function: GAUSS Element Fixation Solution Linear Equation Group Try: Int_Mgauss (Double ** A, Double * B, INT N, DOUBLE EP)

Parameters: A: Coefficient Matrix, B: Wheel Value, N: Equator Number, EP: Accuracy

Returns: Do you have a solution?

Example:

#include "mylib.h"

void main ()

{

INT I, N;

Double ** a, * b, EP;

n = 3;

a = _alloc2 (n, n);

B = (double *) Calloc (n, sizeof (double));

IF (b == NULL) exit (1);

EP = 1e-12;

A [0] [0] = 1; A [0] [1] = - 1; a [0] [2] = 1;

A [1] [0] = 5; A [1] [1] = - 4; A [1] [2] = 3;

A [2] [0] = 2; A [2] [1] = 1; A [2] [2] = 1;

B [0] = - 4; B [1] = - 12; B [2] = 11;

IF (! _ mgauss (A, B, N, EP))

{

Printf ("failed! / n");

Exit (1);

}

For (i = 0; i <= 2; i )

Printf ("x [% d] =% f / n", i 1, b [i]);

_ALLOC2FREE (A);

Free (b);

}

67. Function name: _MGAUSS2

Function: Solving the multiplier of the matrix (AX = B)

Usage: int _mgauss2 (double ** a, double ** b, int N, int m, double ep)

Parameters: A: Matrix A, B: Matrix B, N: The order of equation, M: Right end column vector, EP: accuracy

Returns: Do you have a solution?

68. Function name: _MDJN

Function: Decomposition of linear symmetric equations

Usage: int _mdjn (double ** a, double ** C, INT N, INT M)

Parameters: A: Matrix A, C: Matrix C, N: The order of equation, M: Right end column vector

Returns: Do you have a solution?

69. Function Name: _NOR

Function: Normal distribution function (| x | <= 3.5 is approximated when | x |> 3.5 is approximated)

Usage: double _nor (double x, int L)

Parameters: x: Variable, L: L = 1 Calculate the integral of negative infinity to x, l = -1 calculates X to an infinite integration

Return: points value

Example:

#include "mylib.h"

void main ()

{

Double X;

For (x = 0; x <= 5; x = 0.5)

Printf ("% E / T% E / T% E / N", X, _NOR (X, 1), _ NOR (X, -1));

}

70. Function name: _mdet

Function: Severe value of matrix

Usage: double _mdet (double ** a, int N)

Parameters: A: A matrix of N * N, N: Route Returns: Value

71. Function name: _MINV

Function: Reverse of matrix

Usage: int _minv (double tt, double * t, double * tt, int N, int m, double ** b)

parameter:

return:

72. Function name: _FFT

Function: FFT transformation

Usage: void _fft (double * fr, double * fi, int n, int flag)

Parameters: fr: Digital Table of the Sample Point, Fi: Digital Table of Sample Point, N: Sample Number, Flag: Flag = 0 Indicates Fourier Transform, Flag = 1 Indicates the reverse Fourier transformation

Return: None

转载请注明原文地址:https://www.9cbs.com/read-26797.html

New Post(0)