Example: API documentation

Numerical Programming API

#include "myNM.h"

Non-Linear Solver

newtonRaphson()

Solves the non-linear problem using Newton-Raphson method

double newtonRaphson(double x0, double tol);

Parameters

  • x0: initial value.

  • tol: tolerance error

Example code

double tol = 0.00001;
double x0 = 3;
double NR_result;
​
NR_result = newtonRaphson(x0, tol);

Linear Solver

gaussElim()

solves for vector x from Ax=b, a linear system problem Using Gauss Elimination

Parameters

  • A: Matrix A in structure Matrix form. Should be (nxn) square.

  • B: vector b in structure Matrix form. Should be (nx1)

  • U: Matrix U in structure Matrix form. Should be (nxn) square.

  • B_out: vector B_out in structure Matrix form. Should be (nx1)

Example code

inv()

Find the inverse Matrix.

Parameters

  • A: Matrix A in structure Matrix form. Should be (nxn) square.

  • Ainv: Matrix Ainv in structure Matrix form. Should be (nxn) square.

Example code

Numerical Differentiation

gradient1D()

Solve for numerical gradient (dy/dt) from a 1D-array form.

Parameters

  • x[]: input data vector x in 1D-array .

  • y[]: input data vector y in 1D-array.

  • dydx[]: output vector dydx in 1D-array.

  • m: length x and y.

Example code

See full example code: TutorialDifferentiation.cpp

Integration

integral()

Integral using Simpson 1/3 Method.

Parameters

  • func: Function func is defined.

  • a is starting point of x.

  • b is ending point of x.

  • n is the length between a and b

Example code

ODE-IVP

odeEU()

Solve the 1st-order ODE using Euler's Explicit Method.

Parameters

  • func: Function func is defined.

  • y[]: Solution of ODE in structure 1D-array form.

  • t0 is starting point.

  • tf is ending point.

  • h is length of step.

  • y0 is initial value of y[].

Example code

-------------------------------------------------------------------------------------------------------

Class or Header name

Function Name

Parameters

  • p1

  • p2

Example code

Last updated

Was this helpful?