yaeosThis module provides all the relevant mathematical functions used in this library. Most important ones are:
use yaeos__constants, only: pr
use yaeos__math, only: sq_error
print *, sq_error(2.5_pr, 3.0_pr)
use yaeos__constants, only: pr
use yaeos__math, only: sq_error
real(pr) :: x(2) = [2.5_pr, 5.0_pr], y(2) = [3.0_pr, 4.5_pr]
! It also works with arrays
print *, sq_error(x, y)
Find a root of a scalar function by damped Newton iteration. Each step is halved until its magnitude is at most half the current iterate’s magnitude. This is a step-size safeguard, not a residual line search.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| procedure(f_1d) | :: | f |
Function and derivative callback. |
|||
| real(kind=pr), | intent(inout) | :: | x |
Initial guess, replaced by the root estimate. |
||
| real(kind=pr), | intent(in) | :: | tol |
Absolute tolerance for residual and step size. |
||
| integer, | intent(in) | :: | max_iters |
Maximum Newton iterations. |
||
| logical, | intent(out) | :: | failed |
True when the iteration limit is exhausted. |
Callback interface for a scalar residual and its derivative.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | x |
Current scalar iterate. |
||
| real(kind=pr), | intent(out) | :: | f |
Residual value . |
||
| real(kind=pr), | intent(out) | :: | df |
Derivative . |
Represents the single point of a line segment.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | i |
Index of the first line segment |
|||
| integer, | public | :: | j |
Index of the second line segment |
|||
| real(kind=pr), | public | :: | x |
X coordinate |
|||
| real(kind=pr), | public | :: | y |
Y coordinate |
Approximate the Jacobian of a vector function by centered differences.
Column i is evaluated using a perturbation ; thus
this routine requires nonzero entries in x for finite differences.
| Type | Intent | Optional | Attributes | Name | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public function f(x)Vector-valued function differentiated by Arguments
Return Value real(kind=pr), (size(x))Function output vector. |
||||||||||||||||||||
| real(kind=pr), | intent(in) | :: | x(:) |
Evaluation point. |
||||||||||||||||
| real(kind=pr), | intent(in) | :: | eps |
Relative finite-difference step multiplier. |
||||||||||||||||
Approximate Jacobian matrix.
Calculate the mole fraction second derivatives respect to mole numbers
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | n(:) |
Component mole amounts. |
, indexed (k,i,j).
Calculate the mole fraction first derivatives respect to mole numbers
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | n(:) |
Component mole amounts. |
, indexed (k,i).
Convert the mole fraction derivatives of a quantity (calculated so they do not sum to 1) to mole number derivatives (where the mole fractions do sum to one). Requires the derivatives and the mole fractions of the mixture. From Chemicals (Python)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | x(:) |
Mole-fraction vector. |
||
| real(kind=pr), | intent(in) | :: | dx(:) |
Derivative of the property with respect to mole fractions. |
Linear interpolation.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | x1 |
First point x value |
||
| real(kind=pr), | intent(in) | :: | x2 |
Second point x value |
||
| real(kind=pr), | intent(in) | :: | y1 |
First point y value |
||
| real(kind=pr), | intent(in) | :: | y2 |
Second point y value |
||
| real(kind=pr), | intent(in) | :: | x_obj |
Desired x value to interpolate |
y value at x_obj
Find the intersections of a single line with itself.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | lx(:) |
X coordinates of the polyline vertices. |
||
| real(kind=pr), | intent(in) | :: | ly(:) |
Y coordinates of the polyline vertices. |
Detected non-adjacent segment intersections.
Returns the squared relative error . exp
must be nonzero; the result is dimensionless and elementally
applicable to scalar or array values.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | exp |
Reference or expected value; must be nonzero. |
||
| real(kind=pr), | intent(in) | :: | pred |
Predicted value being compared with |
Calculate the intersection between two line segments.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=pr), | intent(in) | :: | x1 |
X coordinate of the first endpoint of segment 1. |
||
| real(kind=pr), | intent(in) | :: | x2 |
X coordinate of the second endpoint of segment 1. |
||
| real(kind=pr), | intent(in) | :: | x3 |
X coordinate of the first endpoint of segment 2. |
||
| real(kind=pr), | intent(in) | :: | x4 |
X coordinate of the second endpoint of segment 2. |
||
| real(kind=pr), | intent(in) | :: | y1 |
Y coordinate of the first endpoint of segment 1. |
||
| real(kind=pr), | intent(in) | :: | y2 |
Y coordinate of the second endpoint of segment 1. |
||
| real(kind=pr), | intent(in) | :: | y3 |
Y coordinate of the first endpoint of segment 2. |
||
| real(kind=pr), | intent(in) | :: | y4 |
Y coordinate of the second endpoint of segment 2. |
||
| real(kind=pr), | intent(out) | :: | s |
Normalized position along segment 1; |
||
| real(kind=pr), | intent(out) | :: | t |
Normalized position along segment 2. |
Solve a nonlinear least-squares system with MINPACK’s lmdif1.
The routine updates X and returns residuals and MINPACK status.
| Type | Intent | Optional | Attributes | Name | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public subroutine fun(m, n, x, fvec, iflag)funDescriptionMINPACK residual callback for rectangular least-squares systems. Arguments
|
||||||||||||||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(in) | :: | tol |
Convergence tolerance passed to MINPACK. |
||||||||||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(inout) | :: | X(:) |
Variables vector |
||||||||||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(out) | :: | F(:) |
Function values at solved point |
||||||||||||||||||||||||||||||||||||||||||||
| integer, | intent(inout) | :: | info |
MINPACK termination code. |
||||||||||||||||||||||||||||||||||||||||||||
Find a root of a scalar function by damped Newton iteration. Each step is halved until its magnitude is at most half the current iterate’s magnitude. This is a step-size safeguard, not a residual line search.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| procedure(f_1d) | :: | f |
Function and derivative callback. |
|||
| real(kind=pr), | intent(inout) | :: | x |
Initial guess, replaced by the root estimate. |
||
| real(kind=pr), | intent(in) | :: | tol |
Absolute tolerance for residual and step size. |
||
| integer, | intent(in) | :: | max_iters |
Maximum Newton iterations. |
||
| logical, | intent(out) | :: | failed |
True when the iteration limit is exhausted. |
Solve a square nonlinear system with MINPACK’s Powell hybrid method.
| Type | Intent | Optional | Attributes | Name | |||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public subroutine fun(n, x, fvec, iflag)funDescriptionMINPACK residual callback for a square nonlinear system. Arguments
|
|||||||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(in) | :: | tol |
Convergence tolerance passed to MINPACK. |
|||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(inout) | :: | X(:) |
Variables vector |
|||||||||||||||||||||||||||||||||||||
| real(kind=pr), | intent(out) | :: | F(:) |
Function values at solved point |
|||||||||||||||||||||||||||||||||||||
| integer, | intent(out) | :: | info |
MINPACK termination code. |
|||||||||||||||||||||||||||||||||||||