RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
fsolve.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
3  * 2020 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
23 #include "vector.h"
24 #include "matrix.h"
25 #include "fsolve.h"
26 #include "newton_raphson.h"
27 #include "damped_newton_raphson.h"
28 
29 uint8_t fsolve(uint8_t f_length, uint8_t x0_length, vector_t x0_arr[],
30  enum NON_LIN_ALGORITHM algo, vector_t est_x_arr[],
31  void (*get_non_lin_sys)(vector_t x_arr[], vector_t f_vec[]),
32  void (*get_jacobian)(vector_t x_arr[], matrix_t J[][x0_length]))
33 {
34  double tol = 1e-9;
35  uint8_t max_it_num = 77;
36  uint8_t iter_num = 0;
37 
38  switch (algo) {
39  case Newton_Raphson:
40  iter_num = newton_raphson(f_length, x0_length, x0_arr, tol,
41  max_it_num,
42  est_x_arr, get_non_lin_sys, get_jacobian);
43  break;
44 
46  {
47  double min_lamda = 4.8828125e-04;
48  iter_num = damped_newton_raphson(f_length, x0_length, x0_arr,
49  min_lamda,
50  tol, max_it_num, est_x_arr,
51  get_non_lin_sys, get_jacobian);
52  break;
53  }
54 
55  default:
56  iter_num = newton_raphson(f_length, x0_length, x0_arr, tol,
57  max_it_num,
58  est_x_arr, get_non_lin_sys, get_jacobian);
59  }
60 
61  return iter_num;
62 }
newton_raphson.h
Implement the Newton–Raphson algorithm.
fsolve.h
Solve multi-variant nonlinear equation systems.
vector_t
#define vector_t
Define the data type of the vector elements.
Definition: vector.h:33
damped_newton_raphson
uint8_t damped_newton_raphson(uint8_t f_length, uint8_t n, vector_t x0_arr[], double min_lamda, double eps, uint8_t max_it_num, vector_t est_x_arr[], void(*get_non_lin_sys)(vector_t x_arr[], vector_t f_vec[]), void(*get_jacobian)(vector_t x_arr[], matrix_t J[][n]))
Implements the damped Newton–Raphson algorithm.
Definition: damped_newton_raphson.c:32
NON_LIN_ALGORITHM
NON_LIN_ALGORITHM
Possible algorithms to solve multi-variant nonlinear equation systems.
Definition: fsolve.h:30
Damped_Newton_Raphson
Damped Newton–Raphson algorithm.
Definition: fsolve.h:32
matrix.h
Matrix computations.
damped_newton_raphson.h
Implement the damped Newton–Raphson algorithm.
newton_raphson
uint8_t newton_raphson(uint8_t f_length, uint8_t n, vector_t x0_arr[], double eps, uint8_t max_it_num, vector_t est_x_arr[], void(*get_non_lin_sys)(vector_t x_arr[], vector_t f_vec[]), void(*get_jacobian)(vector_t x_arr[], matrix_t J[][n]))
Implements the Newton–Raphson algorithm.
Definition: newton_raphson.c:28
Newton_Raphson
Newton–Raphson algorithm.
Definition: fsolve.h:31
matrix_t
#define matrix_t
Define the data type of the matrix elements.
Definition: matrix.h:38
vector.h
Vector computations.
fsolve
uint8_t fsolve(uint8_t f_length, uint8_t x0_length, vector_t x0_arr[], enum NON_LIN_ALGORITHM algo, vector_t est_x_arr[], void(*get_non_lin_sys)(vector_t x_arr[], vector_t f_vec[]), void(*get_jacobian)(vector_t x_arr[], matrix_t J[][x0_length]))
Solve systems of multi-variant nonlinear equations.
Definition: fsolve.c:29