Topic: Expressions

Online Help

## Numerical methods

Calcpad has a built in "**Solver**" module, which can solve more difficult problems using numerical methods. It can work only with real numbers but not complex. It includes the following functions:

#### Root finding

`$Root{`

**f**(`x`) = const @ `x` = `a` : `b`}

`$Root{`

**f**(`x`) @ `x` = `a` : `b`}

It finds a single root for an equation of type **f**(`x`) = const within the interval [`a`, `b`]. If "const" is zero, you can omit "= const". The program uses hybrid iterative method that "brackets" the root in sufficiently small interval. If no roots exist inside the initial interval, the program will return an error. If there are several roots, it will find only one of them. In such case, it is better to plot the function first. Then, you can see the approximate location of roots and divide the interval into several parts - one for each root. Finally, you can call the function for each separate interval to find all the roots. In some cases, it is possible to develop an automated procedure for interval splitting.

#### Minimum

`$Inf{`

**f**(`x`) @ `x` = `a` : `b`}

It finds the smallest value for a function **f**(`x`) within the specified interval [`a`, `b`]. The golden section search method is applied for that purpose. If the function contains a local minimum within the interval, it will be returned as a result. Otherwise, the function will return the smaller of the values at the ends of the interval: **f**(`a`) or **f**(`b`). If there are several local minimums, the program will return only one of them, but not necessarily the smallest one. In such cases, it is better to split the interval. The value of `x` where the minimum is found is stored into a variable `x`_{inf}. If you use different name for the argument, instead of `x`, it will add "_inf" at the end of that name.

#### Maximum

`$Sup{`

**f**(`x`) @ `x` = `a` : `b`}

It works like the minimum finding function, but it finds the greatest value instead. The value of `x` where the maximum is located is stored in a variable named `x`_{sup}.

#### Numerical integration

`$Area{`

**f**(`x`) @ `x` = `a` : `b`}

It calculates the value of the definite integral of a function **f**(`x`) within the specified interval [`a`, `b`]. Adaptive Gauss-Lobbato quadrature with Kronrod extension is applied for that purpose (Gander & Gautschi, 2000).

`$Integral{`

**f**(`x`) @ `x` = `a` : `b`}

This command is similar to the above, but it uses the Tanh-Sinh quadrature (Takahasi & Mori, 1974) which has been additionally improved by Michashki & Mosig (2016) and Van Engelen (2022). Further improvements has been made in Calcpad, by precomputing and caching the abscissas and weights. This algorithm significantly outperforms `$Area`

for **continuous** and **smooth** functions. However, if the function does not satisfy these requirements, you **should not** use the `$Integral`

method. Then, you have two options:

- Divide the interval [
`a`,`b`] into smaller parts, by using the points of discontinuities, apply the method for each part separately, and sum the results; - If you are not sure where the discontinuities are, use the
`$Area`

method instead.

#### Numerical differentiation

`$Slope{`

**f**(`x`) @ `x` = `a`}

It finds the value of the first derivative of a function **f**(`x`) at `x` = `a`. The derivative represents the slope of the tangent to the function at the respective point. The Richardson extrapolation method is used on a two point stencil.

#### General recommendations

For all of the above commands, **f**(`x`) must be continuous and smooth, except for root finding. The latest requires the function to be continuous only and to have opposite signs at the ends of the interval. According to the Boltzano's theorem, at least one root must exist in this case.

Unlike the plotting command, you can include numerical methods in expressions. They return values which can be used for further calculations. For example, you can store the result into a variable:

`y`_{min} = $Inf{**f**(`x`) @ `x` = `a` : `b`}

Similarly to standard functions, "`x`" is local for all numerical methods and its global value is not modified after the method is called.