Based on the original Rocket Workbench on SourceForge in CVS at: https://sourceforge.net/projects/rocketworkbench
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.0 KiB

  1. /* num.h - Library of numerical method
  2. * $Id: num.h,v 1.3 2001/02/22 19:47:37 antoine Exp $
  3. * Copyright (C) 2000
  4. * Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
  5. *
  6. * Licensed under the GPL
  7. */
  8. #ifndef num_h
  9. #define num_h
  10. /* NOTE on matrix representation
  11. * -----------------------------
  12. * All matrix should be allocate the following way
  13. *
  14. * matrix = (double *) malloc (sizeof(double) * line * column)
  15. *
  16. * to access the value at line 2, column 4, you do it like that
  17. *
  18. * matrix[2 + 4*line]
  19. */
  20. /* This type is used as function pointer for the
  21. * sysnewton algorithm.
  22. */
  23. typedef double (*func_t)(double *x);
  24. typedef struct status
  25. {
  26. int itn;
  27. } status_t;
  28. #define NO_CONVERGENCE 1
  29. #define NO_SOLUTION 2
  30. /* Find the solution of linear system of equation using the
  31. * LU factorisation method as explain in
  32. * 'Advanced engineering mathematics' bye Erwin Kreyszig.
  33. *
  34. * This algorithm will also do column permutation to find
  35. * the larger pivot.
  36. *
  37. * ARGUMENTS
  38. * ---------
  39. * matrix: the augmented matrix of coefficient in the system
  40. * with right hand side value.
  41. *
  42. * solution: the solution vector
  43. *
  44. * neq: number of equation in the system
  45. *
  46. * Antoine Lefebvre
  47. * february 6, 2000 Initial version
  48. * october 20, 2000 revision of the permutation method
  49. */
  50. int NUM_lu(double *matrix, double *solution, int neq);
  51. //int old_lu(double *matrix, double *solution, int neq);
  52. /* This function print the coefficient of the matrix to
  53. * the screen.
  54. *
  55. * matrix: should be an augmented matrix
  56. * neq : number of equation
  57. */
  58. int NUM_print_matrix(double *matrix, int neq);
  59. /* Print the coefficient of the square matrix to the screen
  60. */
  61. int NUM_print_square_matrix(double *matrix, int neq);
  62. /* This function print the contents of the vector to
  63. * the screen.
  64. *
  65. * vec: vector containing neq element
  66. */
  67. int NUM_print_vec(double *vec, int neq);
  68. /**************************************************************
  69. FUNCTION: This function solve systems of ODE of the first order
  70. with the Runge-Kutta method of the fourth order.
  71. PARAMETER: The first parameter is a pointer to the function we
  72. we want to solve. This function take five parameter
  73. neq is the number of equations in the system
  74. time is the time at which we want to evaluate
  75. y is an array containing an initial value
  76. dy will store the result of the function
  77. ierr any error field
  78. step is the time variation
  79. duration is the total time of the simulation
  80. ic are the initial conditions
  81. **y is an array containing all the data
  82. void * is nay user data
  83. COMMENTS: **y must be properly allocated, [number of points]X[neq]
  84. It could be interesting to add a tolerance and use
  85. variable step to reach our tolerance instead of using a
  86. fixed step.
  87. AUTHOR: Antoine Lefebvre
  88. DATE: February 11
  89. *****************************************************************/
  90. int NUM_rk4(int (*f)(int neq, double time, double *y, double *dy, void *data),
  91. int neq, double step, double duration, double *ic,
  92. double **y, void *data );
  93. int NUM_rkf(int (*f)(int neq, double time, double *y, double *dy, void *data),
  94. int neq, double step, double duration, double *ic,
  95. double **y, double epsil, void *data);
  96. /* this function return the nearest integer to a */
  97. /* it is a replacement of rint which is not ANSI complient */
  98. int Round(double a);
  99. double epsilon(void);
  100. int NUM_sec(double (*f)(double x), double x0, double x1, int nmax,
  101. double epsilon, double *ans);
  102. int NUM_newton(double (*f)(double x), double (*df)(double x), double x0,
  103. int nmax, double epsilon, double *ans);
  104. int NUM_ptfix(double (*f)(double x), double x0,
  105. double nmax, double epsilon, double *ans);
  106. int NUM_sysnewton(func_t *Jac, func_t *R, double *x, int nvar,
  107. int nmax, double eps);
  108. int trapeze(double *data, int n_point, int col, int off, double *integral);
  109. int simpson(double *data, int n_point, int col, int off, double *integral);
  110. int create_spline(double *data, int n_point, double *spline);
  111. #endif