yaeos__math Module

Mathematical methods for yaeos

Description

This module provides all the relevant mathematical functions used in this library. Most important ones are:

  • newton: Newton solving method
  • solve_system: Solving linear system Ax = b
  • continuation: Continuation method for line tracing

Examples

Squared error calculation

 use yaeos__math, only: sq_error
 real(pr) :: x = 2.5, y = 3.0, error
 print *, sq_error(2.5, 3.0)
------------------------------------
 use yaeos__math, only: sq_error
 real(pr) :: x = [2.5, 5.0], y = [3.0, 4.5], error
 ! It also works with arrays
 print *, sq_error(x, y)


Interfaces

public interface newton

  • public subroutine newton_1d(f, x, tol, max_iters)

    Arguments

    Type IntentOptional Attributes Name
    procedure(f_1d) :: f
    real(kind=pr), intent(inout) :: x
    real(kind=pr), intent(in) :: tol
    integer, intent(in) :: max_iters

Abstract Interfaces

abstract interface

  • public subroutine f_1d(x, f, df)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=pr), intent(in) :: x
    real(kind=pr), intent(out) :: f
    real(kind=pr), intent(out) :: df

Functions

public function derivative_d2xk_dnidnj(n) result(d2xk_dnidnj)

Calculate the mole fraction second derivatives respect to mole numbers

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=pr), intent(in) :: n(:)

Return Value real(kind=pr), (size(n),size(n),size(n))

public function derivative_dxk_dni(n) result(dxk_dni)

Calculate the mole fraction first derivatives respect to mole numbers

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=pr), intent(in) :: n(:)

Return Value real(kind=pr), (size(n),size(n))

public function dx_to_dn(x, dx) result(dn)

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 https://chemicals.readthedocs.io/chemicals.utils.html?highlight=dxs_to_dns#chemicals.utils.dxs_to_dns

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=pr), intent(in) :: x(:)
real(kind=pr), intent(in) :: dx(:)

Return Value real(kind=pr), (size(x))

public elemental function interpol(x1, x2, y1, y2, x_obj) result(y)

Linear interpolation.

Read more…

Arguments

Type IntentOptional 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

Return Value real(kind=pr)

y value at x_obj

public elemental function sq_error(exp, pred)

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=pr), intent(in) :: exp
real(kind=pr), intent(in) :: pred

Return Value real(kind=pr)


Subroutines

public subroutine newton_1d(f, x, tol, max_iters)

Arguments

Type IntentOptional Attributes Name
procedure(f_1d) :: f
real(kind=pr), intent(inout) :: x
real(kind=pr), intent(in) :: tol
integer, intent(in) :: max_iters