Skip to content

analysis

Camillo Ballandt edited this page Jan 8, 2022 · 3 revisions

Avmath analysis documentation

The avmath.analysis submodule provides functionalities for analysis. It can be imported in the following way:

# pip install avmath
from avmath import analysis

Contents



Point

The Point class is the return type of some Function methods. It inherites from algebra.Tuple and defines this extra method:


Point methods

Point.__init__(x, y)

Implemented in v1.0.0 | Last change v3.0.0

Initialisation of point.


Point.negative_y()

Implemented in v3.1.0 | Last change v3.1.0

Returns point with negative y coordinate.



Function

The Function class provides functionalities for mathematical functions.

It has got the following attributes and methods:

Function attributes

Attribute Usage Implemented in Last change
self.term Stores the function term as string v1.0.0 v3.0.0
self._arg_scope Stores the scope given to eval v2.0.0 v2.0.0

Function methods

Function.__init__(arg)

Implemented in v1.0.0 | Last change in v3.0.0

The constructor takes a string argument. This shall be the function term. Because of the _arg_scope there can be given functions of avmath without the module name. As definition variable x must be used. It also provides some easy to use coefficient and polynom features.

from avmath import analysis

# Polynoms can be given in intentional form
f1 = analysis.Function("2*x**2 + 3*x - 4")
f2 = analysis.Function("2x^2 + 3x - 4")

# avmath functions
g = analysis.Function("sin(x)")
h = analysis.Function("artanh(x)")

Function.__repr__()

Implemented in v1.0.0 | Last change in v3.0.0

Gives string representation of function.

from avmath import analysis

f = analysis.Function("3x^2 + sin(x)")
print(f)

gives the output

f(x) = 3x^2 + sin(x)

Function.__add__(other)

Implemented in v1.0.0 | Last change in v3.1.0

Adds two formulas.


Function.__sub__(other)

Implemented in v1.0.0 | Last change in v3.0.0

Subtracts two formulas. The entire second formula is set in brackets.


Function.__mul__(other) / Function.__rmul__(other)

Implemented in v1.0.0 | Last change in v3.1.0

Multiplies two formulas or Function with REAL. Both are set in brackets.


Function.__truediv__(other)

Implemented in v1.0.0 | Last change in v3.1.0

Divides two formulas or a formula by a REAL. Both are set in brackets.


Function.__rtruediv__(other)

Implemented in v3.1.0 | Last change in v3.1.0

Divides a REAL by a formula. Both are set in brackets.


Function.__neg__()

Implemented in v1.0.0 | Last change in v3.0.0

Returns negative formula. Formula is just set in brackets and preceded by a - sign.


Function.replace(value)

Implemented in v1.0.0 | Last change in v3.1.0

Function replacing the intuitive elements (shown in __init__) with the correct syntax and setting given value for x.

from avmath import analysis

f = analysis.Function("3x^2 + sin(x)")
print(f.replace(5))

gives the output

3*(-5)**2 + sin((-5))

Function.set_scope(scope)

Implemented in v2.0.0 | Last change in v3.0.0

Sets new scope for eval.


Function.append_scope(scope)

Implemented in v2.0.0 | Last change in v3.0.0

Appends scope dictionary to scope.


Function.at(value)

Implemented in v1.0.0 | Last change in v3.0.0

Returns the y-value of a function at a given x-value.


Function.max(xmin, xmax [, steps=1000])

Implemented in v2.0.0 | Last change in v3.1.0

Function returning the maxima of a function in a given x domain. steps are the iterative steps made to find a change in the signum. Than uses Newton-method derivative to find the maxima. Returns list of Point values.


Function.min(xmin, xmax [, steps=1000])

Implemented in v2.0.0 | Last change in v3.1.0

Opposite of max. Returns minima in a given x domain.


Function.root(xmin, xmax [, step=1000])

Implemented in v3.0.0 | Last change in v3.0.0

Returns the roots of function in given x domain. Uses Newton-method to approach roots. Gives list of x-values back.

! WARNING: Due to backward compatibility last parameter remains step not steps like in max and min.


Function.newton_method(x_n [, steps=50])

Implemented in v3.0.0 | Last change in v3.1.0

Returns result of steps times executed Newton-method.


Function.newton_method_extrema(x_n [, steps=50])

Implemented in v3.1.0 | Last change in v3.1.0

Executes derivative of Newton method: x_{n+1} = f'(x_n) / f''(x_n).


Function.derivative(x [, h=None])

Implemented in v3.1.0 | Last change in v3.1.1

Returns the derivative of the function at a given x. If no h specified, calculates a height, but this may not be the optimal one.


Function.second_derivative(x_n [, h=1e-5])

Implemented in v3.1.0 | Last change in v3.1.0

Returns second derivative of the function at given x. h is set to 1e-5 what is mostly a good compromise of arithmetic error and numeric error.


Function.integral(a, b [, n=1000][, option=None])

Implemented in v3.1.0 | Last change in v3.1.0

Calculates the integral of the function between a and b with n steps. With no option specified, uses rectangular formula. If option="trapeze", uses trapeze formula.


Function.num_dif(x [, h=1e-5])

Implemented in v1.0.0 | Last change in v3.0.0

Returns numeric differentiation of the function at given x.

! WARNING: INACTIVE: Use Function.derivative instead.


Function.second_num_dif(x [, h=1e-5])

Implemented in v3.0.0 | Last change in v3.0.0

Returns numerically calculated second differentiation at given x.

! WARNING: INACTIVE: Use Function.second_derivative instead.


Function.num_int(a, b [, n=1000])

Implemented in v1.0.0 | Last change in v3.1.0

Numerically calculated integral between a and b with n steps.

! WARNING: INACTIVE: Use Function.integral instead.


Function.tangent(x)

Implemented in v3.1.0 | Last change in v3.1.0

Returns a linear function in the form y = ax + b that lies tangent to the function graph at a given x.


Function.normal(x)

Implemented in v3.1.0 | Last change in v3.1.0

Returns a linear function in the form y = ax + b that lies normal to the function graph at a given x.