#include <time.h>
#include <math.h>
#include <stdexcept>
#include "arts.h"
#include "math_funcs.h"
#include "make_vector.h"
#include "array.h"
Go to the source code of this file.
Functions | |
Numeric | first (ConstVectorView x) |
Gives the first value of a vector. | |
Numeric | last (ConstVectorView x) |
Gives the last value of a vector. | |
bool | any (const ArrayOfIndex &x) |
True if any element of a boolean vector, b, is not 0. | |
void | linspace (Vector &x, const Numeric start, const Numeric stop, const Numeric step) |
Linearly spaced vector with specified spacing. | |
void | nlinspace (Vector &x, const Numeric start, const Numeric stop, const Index n) |
Linearly spaced vector with specified length. | |
void | nlogspace (Vector &x, const Numeric start, const Numeric stop, const Index n) |
Logarithmically spaced vector with specified length. | |
Vector | nlogspace (const Numeric start, const Numeric stop, const Index n) |
Logarithmically spaced vector with specified length (return version). | |
Index | interp_check (ConstVectorView x, ConstVectorView xi, const Index n_y) |
Local help function to check input grids. | |
void | interp_lin_vector (VectorView yi, ConstVectorView x, ConstVectorView y, ConstVectorView xi) |
Multiple linear interpolation of a vector. | |
void | interp_lin_matrix (MatrixView Yi, ConstVectorView x, ConstMatrixView Y, ConstVectorView xi) |
Multiple linear interpolation of matrix rows. | |
Numeric | interp_lin (ConstVectorView x, ConstVectorView y, const Numeric xi) |
Single linear interpolation of a vector (return version). | |
void | check_if_bool (const Index &x, const String &x_name) |
Checks if an integer is 0 or 1. | |
void | check_if_in_range (const Numeric &x_low, const Numeric &x_high, const Numeric &x, const String &x_name) |
Checks if a numeric variable is inside a specified range. | |
void | check_lengths (const Vector &x1, const String &x1_name, const Vector &x2, const String &x2_name) |
Checks that two vectors have the same length. | |
void | check_length_nrow (const Vector &x, const String &x_name, const Matrix &A, const String &A_name) |
Checks that the length of a vector and the number of rows of a matrix match. | |
void | check_length_ncol (const Vector &x, const String &x_name, const Matrix &A, const String &A_name) |
Checkss that the length of a vector and the number of columns of a matrix match. | |
void | check_ncol_nrow (const Matrix &A, const String &A_name, const Matrix &B, const String &B_name) |
Checks that the number of columns of the first matrix is the same as the number of rows of the second matrix. |
Example on types of functions: {enumerate} First and last element of a vector Boolean functions Creation of common vectors Interpolation routines Check of function input {enumerate}
Definition in file math_funcs.cc.
bool any | ( | const ArrayOfIndex & | x | ) |
True if any element of a boolean vector, b, is not 0.
x | a vector |
Definition at line 104 of file math_funcs.cc.
Checks if an integer is 0 or 1.
A runtime error is thrown if the integer is not a boolean.
x | an integer | |
x_name | the name of the integer |
Definition at line 467 of file math_funcs.cc.
void check_if_in_range | ( | const Numeric & | x_low, | |
const Numeric & | x_high, | |||
const Numeric & | x, | |||
const String & | x_name | |||
) |
Checks if a numeric variable is inside a specified range.
A runtime error is thrown if the variable is outside the range.
x_low | lower limit | |
x_high | upper limit | |
x | a numeric | |
x_name | the name of the numeric |
Definition at line 494 of file math_funcs.cc.
void check_length_ncol | ( | const Vector & | x, | |
const String & | x_name, | |||
const Matrix & | A, | |||
const String & | A_name | |||
) |
Checkss that the length of a vector and the number of columns of a matrix match.
A runtime error is thrown if the length of the vectors differs from the number of columns.
x | a vector | |
x_name | the name of the vector | |
A | a matrix | |
A_name | the name of the matrix |
Definition at line 591 of file math_funcs.cc.
void check_length_nrow | ( | const Vector & | x, | |
const String & | x_name, | |||
const Matrix & | A, | |||
const String & | A_name | |||
) |
Checks that the length of a vector and the number of rows of a matrix match.
A runtime error is thrown if the length of the vectors differs from the number of rows.
x | a vector | |
x_name | the name of the vector | |
A | a matrix | |
A_name | the name of the matrix |
Definition at line 558 of file math_funcs.cc.
void check_lengths | ( | const Vector & | x1, | |
const String & | x1_name, | |||
const Vector & | x2, | |||
const String & | x2_name | |||
) |
Checks that two vectors have the same length.
A runtime error is thrown if the lengths of the vectors differ.
x1 | vector 1 | |
x1_name | the name of vector1 | |
x2 | vector 2 | |
x2_name | the name of vector2 |
Definition at line 526 of file math_funcs.cc.
void check_ncol_nrow | ( | const Matrix & | A, | |
const String & | A_name, | |||
const Matrix & | B, | |||
const String & | B_name | |||
) |
Checks that the number of columns of the first matrix is the same as the number of rows of the second matrix.
A runtime error is thrown otherwise.
A | first Matrix | |
A_name | the name of the first Matrix | |
B | second matrix | |
B_name | the name of the second matrix |
Definition at line 621 of file math_funcs.cc.
Numeric first | ( | ConstVectorView | x | ) |
Gives the first value of a vector.
x | a vector |
Definition at line 70 of file math_funcs.cc.
Index interp_check | ( | ConstVectorView | x, | |
ConstVectorView | xi, | |||
const Index | n_y | |||
) |
Local help function to check input grids.
Tolerates the new grid to extend half a grid distance outside the original grid.
Definition at line 259 of file math_funcs.cc.
Numeric interp_lin | ( | ConstVectorView | x, | |
ConstVectorView | y, | |||
const Numeric | xi | |||
) |
Single linear interpolation of a vector (return version).
The vector x specifies the points at which the data y is given.
x | the x grid | |
y | the function to interpolate | |
xi | interpolation point |
Definition at line 434 of file math_funcs.cc.
void interp_lin_matrix | ( | MatrixView | Yi, | |
ConstVectorView | x, | |||
ConstMatrixView | Y, | |||
ConstVectorView | xi | |||
) |
Multiple linear interpolation of matrix rows.
Works with subranges inside the argument. Use the transpose(A) function if you want to interpolate columns of A instead of rows.
The vector x specifies the points at which the data y is given.
Interpolation works also for new grid points just outside the original grid range.
Yi | interpolated values (matrix) |
x | the x grid (vector) | |
Y | the function to interpolate (matrix) | |
xi | interpolation points (vector) |
Definition at line 382 of file math_funcs.cc.
void interp_lin_vector | ( | VectorView | yi, | |
ConstVectorView | x, | |||
ConstVectorView | y, | |||
ConstVectorView | xi | |||
) |
Multiple linear interpolation of a vector.
Because Views are used, you can use matrix rows or columns, or vector sub-ranges inside the argument of this function.
The vector x specifies the points at which the data y is given. It must be strictly monotonically increasing. (No two x values must be the same.)
The size of yi has to be the same as for xi.
Interpolation works also for new grid points just outside the original grid range.
yi | interpolated values |
x | the x grid | |
y | the function to interpolate | |
xi | interpolation points |
Definition at line 328 of file math_funcs.cc.
Numeric last | ( | ConstVectorView | x | ) |
Gives the last value of a vector.
x | a vector |
Definition at line 83 of file math_funcs.cc.
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!
x | linearly spaced vector |
start | first value in x | |
stop | last value of x <= stop | |
step | distance between values in x |
Definition at line 139 of file math_funcs.cc.
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.
x | linearly spaced vector |
start | first value in x | |
stop | last value of x <= stop | |
n | length of x |
Definition at line 168 of file math_funcs.cc.
Logarithmically spaced vector with specified length (return version).
Returns a vector logarithmically spaced vector between start and stop of length n (equals the Matlab function logspace)
The length must be > 1.
start | first value in x | |
stop | last value of x <= stop | |
n | length of x |
Definition at line 234 of file math_funcs.cc.
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.
x | logarithmically spaced vector |
start | first value in x | |
stop | last value of x <= stop | |
n | length of x |
Definition at line 198 of file math_funcs.cc.