ARTS  2.3.1285(git:92a29ea9-dirty)
math_funcs.cc File Reference
#include "math_funcs.h"
#include <cmath>
#include <iostream>
#include <stdexcept>
#include "array.h"
#include "logic.h"
#include "mystring.h"

Go to the source code of this file.

Functions

Numeric fac (const Index n)
 fac More...
 
Index integer_div (const Index &x, const Index &y)
 integer_div More...
 
Numeric LagrangeInterpol4 (ConstVectorView x, ConstVectorView y, const Numeric a)
 Lagrange Interpolation (internal function). More...
 
Numeric last (ConstVectorView x)
 last More...
 
Index last (const ArrayOfIndex &x)
 last More...
 
void linspace (Vector &x, const Numeric start, const Numeric stop, const Numeric step)
 linspace More...
 
void nlinspace (Vector &x, const Numeric start, const Numeric stop, const Index n)
 nlinspace More...
 
void nlinspace (VectorView x, const Numeric start, const Numeric stop, const Index n)
 
void nlogspace (Vector &x, const Numeric start, const Numeric stop, const Index n)
 nlogspace More...
 
Numeric AngIntegrate_trapezoid (ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
 AngIntegrate_trapezoid. More...
 
Numeric AngIntegrate_trapezoid_opti (ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, ConstVectorView grid_stepsize)
 AngIntegrate_trapezoid_opti. More...
 
Numeric AngIntegrate_trapezoid (ConstVectorView Integrand, ConstVectorView za_grid)
 AngIntegrate_trapezoid. More...
 
Numeric sign (const Numeric &x)
 sign More...
 
void mgd (VectorView psd, const Vector &x, const Numeric &n0, const Numeric &mu, const Numeric &la, const Numeric &ga)
 
void mgd_with_derivatives (VectorView psd, MatrixView jac_data, const Vector &x, const Numeric &n0, const Numeric &mu, const Numeric &la, const Numeric &ga, const bool &do_n0_jac, const bool &do_mu_jac, const bool &do_la_jac, const bool &do_ga_jac)
 
void delanoe_shape_with_derivative (VectorView psd, MatrixView jac_data, const Vector &x, const Numeric &alpha, const Numeric &beta)
 ! Shape functions for normalized PSD. More...
 
Numeric mod_gamma_dist (Numeric x, Numeric N0, Numeric Lambda, Numeric mu, Numeric gamma)
 Generalized Modified Gamma Distribution. More...
 
void unitl (Vector &x)
 unitl More...
 
void flat (VectorView x, ConstMatrixView X)
 flat More...
 
void flat (VectorView x, ConstTensor3View X)
 flat More...
 
void reshape (Tensor3View X, ConstVectorView x)
 reshape More...
 
void reshape (MatrixView X, ConstVectorView x)
 reshape More...
 
void calculate_weights_linear (Vector &x, Vector &w, const Index nph)
 calculate_weights_linear More...
 

Variables

const Numeric DEG2RAD
 
const Numeric PI
 

Detailed Description

Author
Patrick Eriksson Patri.nosp@m.ck.E.nosp@m.rikss.nosp@m.on@c.nosp@m.halme.nosp@m.rs.s.nosp@m.e
Date
2000-09-18

Contains basic mathematical functions.

Definition in file math_funcs.cc.

Function Documentation

◆ AngIntegrate_trapezoid() [1/2]

Numeric AngIntegrate_trapezoid ( ConstMatrixView  Integrand,
ConstVectorView  za_grid,
ConstVectorView  aa_grid 
)

AngIntegrate_trapezoid.

Performs an integration of a matrix over all directions defined in angular grids using the trapezoidal integration method.

Parameters
IntegrandThe Matrix to be integrated
za_gridThe zenith angle grid
aa_gridThe azimuth angle grid
Returns
The resulting integral

Definition at line 296 of file math_funcs.cc.

References DEG2RAD, i, is_size(), n, and ConstVectorView::nelem().

Referenced by AngIntegrate_trapezoid_opti(), doit_scat_fieldCalc(), doit_scat_fieldCalcLimb(), doit_scat_fieldNormalize(), get_stepwise_scattersky_source(), scat_dataCheck(), and scat_dataReduceT().

◆ AngIntegrate_trapezoid() [2/2]

Numeric AngIntegrate_trapezoid ( ConstVectorView  Integrand,
ConstVectorView  za_grid 
)

AngIntegrate_trapezoid.

Performs an integration of a matrix over all directions defined in angular grids using the trapezoidal integration method. The integrand is independant of the azimuth angle. The integration over the azimuth angle gives a 2*PI

Parameters
IntegrandInput : The vector to be integrated
za_gridInput : The zenith angle grid
Author
Claas Teichmann
Date
2003-05-13
Returns
The resulting integral

Definition at line 393 of file math_funcs.cc.

References DEG2RAD, i, is_size(), n, ConstVectorView::nelem(), and PI.

◆ AngIntegrate_trapezoid_opti()

Numeric AngIntegrate_trapezoid_opti ( ConstMatrixView  Integrand,
ConstVectorView  za_grid,
ConstVectorView  aa_grid,
ConstVectorView  grid_stepsize 
)

AngIntegrate_trapezoid_opti.

Performs an integration of a matrix over all directions defined in angular grids using the trapezoidal integration method.

In addition to the "old fashined" integration method, it checks whether the stepsize is constant. If it is, it uses a faster method, if not, it uses the old one.

Parameters
IntegrandInput : The Matrix to be integrated
za_gridInput : The zenith angle grid
aa_gridInput : The azimuth angle grid
grid_stepsizeInput : stepsize of the grid
Returns
The resulting integral
Author
Claas Teichmann claas.nosp@m.@sat.nosp@m..phys.nosp@m.ik.u.nosp@m.ni-br.nosp@m.emen.nosp@m..de
Date
2003/05/28

Definition at line 340 of file math_funcs.cc.

References AngIntegrate_trapezoid(), DEG2RAD, i, is_size(), n, ConstVectorView::nelem(), and temp.

Referenced by doit_scat_fieldCalc(), doit_scat_fieldCalcLimb(), and test_AngIntegrate_trapezoid_opti().

◆ calculate_weights_linear()

void calculate_weights_linear ( Vector x,
Vector w,
const Index  nph 
)

calculate_weights_linear

Function to set the evaluation points and the corresponding weights for numerical integration on the domain from [-1,1]

Parameters:

Parameters
[out]xevaluation points [out] w integration weights
[in]nphnumber of evaluation points per hemisphere

Definition at line 813 of file math_funcs.cc.

References i, N, ConstVectorView::nelem(), nlinspace(), and Vector::resize().

Referenced by AngularGridsSetFluxCalc().

◆ delanoe_shape_with_derivative()

void delanoe_shape_with_derivative ( VectorView  psd,
MatrixView  jac_data,
const Vector x,
const Numeric alpha,
const Numeric beta 
)

! Shape functions for normalized PSD.

This function implements the shape function F(X, alpha, beta) from as proposed by Delanoe et al. in "Normalized particle size distribution for remote sensing application".

Parameters

Definition at line 619 of file math_funcs.cc.

References i, ConstVectorView::nelem(), and pow().

Referenced by psdDelanoeEtAl14().

◆ fac()

◆ flat() [1/2]

void flat ( VectorView  x,
ConstMatrixView  X 
)

flat

Flattens a matrix to a vector

The matrix is read from front, i.e. rows are looped first. In Matlab this equals x=X(:).

Parameters
[out]xThe vector. Should already be sized
[in]XThe matrix.
Author
Patrick Eriksson
Date
2015-09-09

Definition at line 707 of file math_funcs.cc.

References i, ConstMatrixView::ncols(), ConstVectorView::nelem(), and ConstMatrixView::nrows().

Referenced by xaStandard().

◆ flat() [2/2]

void flat ( VectorView  x,
ConstTensor3View  X 
)

flat

Converts Tensor3 to a vector

The matrix is read from front, i.e. pages are looped first, followed by rows. In Matlab this equals x=X(:).

Parameters
[out]xThe vector. Should already be sized
[in]XThe tensor.
Author
Patrick Eriksson
Date
2015-09-09

Definition at line 733 of file math_funcs.cc.

References i, ConstTensor3View::ncols(), ConstVectorView::nelem(), ConstTensor3View::npages(), and ConstTensor3View::nrows().

◆ integer_div()

Index integer_div ( const Index x,
const Index y 
)

integer_div

Performs an integer division.

The function asserts that the reminder of the division x/y is 0.

Returns
The quotient
Parameters
xNominator
yDenominator
Author
Patrick Eriksson
Date
2002-08-11

Definition at line 87 of file math_funcs.cc.

References is_multiple().

◆ LagrangeInterpol4()

Numeric LagrangeInterpol4 ( ConstVectorView  x,
ConstVectorView  y,
const Numeric  a 
)

Lagrange Interpolation (internal function).

This function calculates the Lagrange interpolation of four interpolation points as described in Lagrange Interpolating Polynomial.
The input are the four x-axis values [x0,x1,x2,x3] and their associated y-axis values [y0,y1,y2,y3]. Furthermore the x-axis point "a" at which the interpolation should be calculated must be given as input. NOTE that the relation x2 =< x < x3 MUST hold!

Parameters
xx-vector with four elements [x0,x1,x2,x3]
yy-vector with four elements: yj = y(xj), j=0,1,2,3
ainterpolation point on the x-axis with x1 =< a < x2
Returns
FIXME
Author
Thomas Kuhn
Date
2003-11-25

Definition at line 113 of file math_funcs.cc.

References i, ConstVectorView::nelem(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

◆ last() [1/2]

Numeric last ( ConstVectorView  x)

last

Returns the last value of a vector.

Returns
The last value of x.
Parameters
xA vector.
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 165 of file math_funcs.cc.

References ConstVectorView::nelem().

Referenced by chk_scat_data(), find_effective_channel_boundaries(), mixer_matrix(), pos2refell_r(), scat_data_singleTmatrix(), ScatSpeciesExtendTemperature(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseMixer(), and ySimpleSpectrometer().

◆ last() [2/2]

Index last ( const ArrayOfIndex x)

last

Returns the last value of an index array.

Returns
The last value of x.
Parameters
xAn index array.
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 180 of file math_funcs.cc.

References Array< base >::nelem().

◆ linspace()

void linspace ( Vector x,
const Numeric  start,
const Numeric  stop,
const Numeric  step 
)

linspace

Linearly spaced vector with specified spacing.

The first element of x is always start. The next value is start+step etc. Note that the last value can deviate from stop. The step can be both positive and negative. (in Matlab notation: start:step:stop)

Size of result is adjusted within this function!

Parameters
xOutput: linearly spaced vector
startfirst value in x
stoplast value of x <= stop
stepdistance between values in x
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 204 of file math_funcs.cc.

References i, n, and Vector::resize().

◆ mgd()

void mgd ( VectorView  psd,
const Vector x,
const Numeric n0,
const Numeric mu,
const Numeric la,
const Numeric ga 
)

Modified gamma distribution

Uses all four free parameters (n0, mu, la, ga) to calculate psd(D) = n0 * D^mu * exp( -la * x^ga )

Reference: Eq 1 of Petty & Huang, JAS, (2011).

Parameters
psdParticle number density per x-interval. Sizing of vector should be done before calling the function.
xMass or size.
n0See above.
muSee above.
laSee above.
gaSee above.
Author
Jana Mendrok, Patrick Eriksson
Date
2017-06-07

Definition at line 451 of file math_funcs.cc.

References ConstVectorView::nelem(), pow(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

◆ mgd_with_derivatives()

void mgd_with_derivatives ( VectorView  psd,
MatrixView  jac_data,
const Vector x,
const Numeric n0,
const Numeric mu,
const Numeric la,
const Numeric ga,
const bool &  do_n0_jac,
const bool &  do_mu_jac,
const bool &  do_la_jac,
const bool &  do_ga_jac 
)

Modified gamma distribution, and derivatives

As mgd, but this version can also return the derivate of psd with respect to the four parameters.

Parameters
psdParticle number density per x-interval. Sizing of vector should be done before calling the function.
jac_dataContainer for returning jacobian data. Shall be a matrix with four rows, where the rows match n0, mu, la and ga. Number of columns same as length of psd.
xMass or size.
n0See above.
muSee above.
laSee above.
gaSee above.
do_n0_jacFlag to actually calculate d_psd/d_n0
do_mu_jacFlag to actually calculate d_psd/d_mu
do_la_jacFlag to actually calculate d_psd/d_la
do_ga_jacFlag to actually calculate d_psd/d_ga
Author
Patrick Eriksson
Date
2017-06-07

Definition at line 530 of file math_funcs.cc.

References ConstMatrixView::ncols(), ConstVectorView::nelem(), ConstMatrixView::nrows(), pow(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

Referenced by psd_mgd_mass_and_something(), psdModifiedGamma(), and psdModifiedGammaMass().

◆ mod_gamma_dist()

Numeric mod_gamma_dist ( Numeric  x,
Numeric  N0,
Numeric  Lambda,
Numeric  mu,
Numeric  gamma 
)

Generalized Modified Gamma Distribution.

Returns number density per unit of 'x' as function of 'x'.

Returns
dN Number density as function of x.
Parameters
xNumeric
N0Numeric, Scaling parameter
LambdaNumeric, Shape parameter
muNumeric, Shape parameter
gammaNumeric, Shape parameter
Author
Manfred Brath
Date
2015-01-19

Definition at line 653 of file math_funcs.cc.

References dN, pow(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

Referenced by psd_MY05().

◆ nlinspace() [1/2]

void nlinspace ( Vector x,
const Numeric  start,
const Numeric  stop,
const Index  n 
)

nlinspace

Linearly spaced vector with specified length.

Returns a vector equally and linearly spaced between start and stop of length n. (equals the Matlab function linspace)

The length must be > 1.

Parameters
xOutput: linearly spaced vector
startfirst value in x
stoplast value of x <= stop
nlength of x
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 231 of file math_funcs.cc.

Referenced by AngularGridsSetFluxCalc(), AntennaConstantGaussian1D(), calc_ssp_fixed_test(), calc_ssp_random_test(), calculate_weights_linear(), DOAngularGridsSet(), doit_scat_fieldCalcLimb(), DoitScatteringDataPrepare(), f_gridFromSensorAMSU(), f_gridFromSensorHIRS(), fillSpeciesAuxDataWithPartitionFunctionsFromSpeciesData(), FouComp_1ScatElem(), gaussian_response_autogrid(), get_angs(), iyHybrid(), iyHybrid2(), pha_mat_sptFromDataDOITOpt(), pha_mat_sptFromMonoData(), pnd_fieldZero(), sensor_responseFillFgrid(), test_ecs20(), test_mpm20(), VectorNLinSpace(), and xml_read_from_stream().

◆ nlinspace() [2/2]

void nlinspace ( VectorView  x,
const Numeric  start,
const Numeric  stop,
const Index  n 
)

Definition at line 241 of file math_funcs.cc.

References i, and Zeeman::start().

◆ nlogspace()

void nlogspace ( Vector x,
const Numeric  start,
const Numeric  stop,
const Index  n 
)

nlogspace

Logarithmically spaced vector with specified length.

Returns a vector logarithmically spaced vector between start and stop of length n (equals the Matlab function logspace)

The length must be > 1.

Parameters
xOutput: logarithmically spaced vector
startfirst value in x
stoplast value of x <= stop
nlength of x
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 267 of file math_funcs.cc.

References i, Vector::resize(), and Zeeman::start().

Referenced by VectorNLogSpace().

◆ reshape() [1/2]

void reshape ( Tensor3View  X,
ConstVectorView  x 
)

reshape

Converts vector to Tensor3

The tensor is filled from front, i.e. pages are looped first, followed by rows. In Matlab this equals X = reshape( x, [ X.npages(), X.nrows(), X.ncols() ]

Parameters
[out]XThe tensor. Should already be sized
[in]xThe vector.
Author
Patrick Eriksson
Date
2015-09-10

Definition at line 761 of file math_funcs.cc.

References i, ConstTensor3View::ncols(), ConstVectorView::nelem(), ConstTensor3View::npages(), and ConstTensor3View::nrows().

Referenced by AtmFieldPerturb(), and x2artsAtmAndSurf().

◆ reshape() [2/2]

void reshape ( MatrixView  X,
ConstVectorView  x 
)

reshape

Converts vector to Matrix

The matrix is filled from front, i.e. rows are looped first, followed by cols. In Matlab this equals X = reshape( x, [ X.nrows(), X.ncols() ]

Parameters
[out]XThe matrix. Should already be sized
[in]xThe vector.
Author
Patrick Eriksson
Date
2015-09-10

Definition at line 789 of file math_funcs.cc.

References i, ConstMatrixView::ncols(), ConstVectorView::nelem(), and ConstMatrixView::nrows().

◆ sign()

Numeric sign ( const Numeric x)

sign

Returns the sign of a numeric value.

The function returns 1 if the value is greater than zero, 0 if it equals zero and -1 if it is less than zero.

Returns
The sign of x (see above).
Parameters
xA Numeric.
Author
Patrick Eriksson
Date
2000-06-27

Definition at line 423 of file math_funcs.cc.

Referenced by error_if_limb_ppath(), binostream::float2ieee_double(), binostream::float2ieee_single(), geompath_from_r1_to_r2(), binistream::ieee_double2float(), binistream::ieee_single2float(), poslos2cart(), r_crossing_2d(), raytrace_2d_linear_basic(), specular_losCalc(), specular_losCalcNoTopography(), and surfaceSemiSpecularBy3beams().

◆ unitl()

void unitl ( Vector x)

unitl

Normalises a vector to have unit length.

The standard Euclidean norm is used (2-norm).

param x In/Out: A vector.

Author
Patrick Eriksson
Date
2012-02-12

Definition at line 687 of file math_funcs.cc.

References i, ConstVectorView::nelem(), and sqrt().

Variable Documentation

◆ DEG2RAD

◆ PI

const Numeric PI

Referenced by AngIntegrate_trapezoid().