gctl/lib/maths/mathfunc.h

217 lines
7.8 KiB
C
Raw Permalink Normal View History

2024-09-10 15:45:07 +08:00
/********************************************************
*
*
*
*
*
*
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_MATHFUNC_H
#define _GCTL_MATHFUNC_H
// library's head files
#include "../core/macro.h"
#include "../core/spmat.h"
#include "mathfunc_t.h"
// system's head files
#include "cmath"
#include "random"
#include "vector"
namespace gctl
{
/**
2024-09-13 10:08:41 +08:00
* @brief Return a random number in the range [low, hig]
*
* @note Call srand(seed) to initiate the random squence before using this function.
*
* @param low Lower bound
* @param hig Higher bound
2024-09-22 12:11:17 +08:00
* @return Random value
2024-09-13 10:08:41 +08:00
*/
int random(int low, int hig);
/**
* @brief Return a random number in the range [low, hig]
*
* @note Call srand(seed) to initiate the random squence before using this function.
*
* @param low Lower bound
* @param hig Higher bound
2024-09-22 12:11:17 +08:00
* @return Random value
2024-09-13 10:08:41 +08:00
*/
double random(double low, double hig);
2024-09-22 12:11:17 +08:00
/**
* @brief Return a random number in the range [low, hig]
*
* @note Call srand(seed) to initiate the random squence before using this function.
*
* @param low Lower bound
* @param hig Higher bound
* @return Random value
*/
std::complex<double> random(std::complex<double> low, std::complex<double> hig);
2024-09-13 10:08:41 +08:00
/**
2024-09-10 15:45:07 +08:00
* @brief eps eps 1e-109
*
* @param f
* @param v
* @param eps
* @return true
* @return false
*/
bool isequal(double f, double v, double eps = GCTL_ZERO);
/**
* @brief
*
* @param[in] a
*
* @return 1 -1 00
*/
double sign(double a);
/**
* @brief n次方根
*
* @param[in] val
* @param[in] order
* @param[in] eps
*
* @return
*/
double sqrtn(double val, int order, double eps = 1e-5);
2024-09-12 07:05:41 +08:00
/**
* @brief
*
* @param lon1
* @param lon2
* @param lat1
* @param lat2
* @param R
* @return
*/
double geographic_area(double lon1, double lon2, double lat1, double lat2, double R);
2024-09-12 07:13:02 +08:00
/**
* @brief
*
* @param lon1
* @param lon2
* @param lat1
* @param lat2
* @param R
* @return
*/
double geographic_distance(double lon1, double lon2, double lat1, double lat2, double R);
2024-09-10 15:45:07 +08:00
/**
* @brief
*
* @param[in] x_len x方向半径
* @param[in] y_len y方向半径
* @param[in] arc x轴正方向的夹角
* @param[in] x_arc x轴正方向绕原点逆时针旋转的角度
*
* @return
*/
double ellipse_radius_2d(double x_len, double y_len, double arc, double x_arc = 0.0);
/**
* @brief
*
* 线线
*
*
* @param x_len x方向半径
* @param y_len y方向半径
* @param arc x轴正方向的夹角
* @param elev
* @param out_arc
* @param out_rad
* @param x_arc x轴正方向绕原点逆时针旋转的角度 0
*/
void ellipse_plus_elevation_2d(double x_len, double y_len, double arc, double elev,
double &out_arc, double &out_rad, double x_arc = 0.0);
/**
* @brief
*
* @param[in] x_len x方向半径
* @param[in] y_len y方向半径
* @param[in] z_len z方向半径
* @param[in] phi x轴正方向的夹角
* @param[in] theta z轴正方向的夹角
*
* @return
*/
double ellipsoid_radius(double x_len, double y_len, double z_len, double phi, double theta);
/**
* @brief 使
*
*
*
* @param[in] in_mat
* @param inverse_mat
* @param[in] epsilon
* @param[in] iter_times 10
* @param[in] initiate
*
* @return
*/
double newton_inverse(const _2d_matrix &in_mat, _2d_matrix &inverse_mat,
double epsilon = 1e-8, int iter_times = 10, bool initiate = true);
/**
* @brief 使
*
*
*
* @param[in] in_mat
* @param inverse_mat
* @param[in] epsilon
* @param[in] iter_times 10
* @param[in] initiate
*
* @return
*/
double newton_inverse(const spmat<double> &in_mat, _2d_matrix &inverse_mat,
double epsilon = 1e-8, int iter_times = 10, bool initiate = true);
/**
* @brief 使线a转换为标准正交向量组e
*
* @note
*
* @param[in] a a_s的线性无关的向量组的指针
* @param e
* @param[in] a_s
*/
void schmidt_orthogonal(const array<double> &a, array<double> &e, int a_s);
}
#endif // _GCTL_MATHFUNC_H