# Code Documentation¶

class base.Foundation[source]

This class contains common features of all modules.

DetSymEnv()[source]

Returns a list. The list consists of all symbolic tools present among ‘sympy’,’sage’ and ‘symengine’.

class measure.Measure(dom, w=None)[source]
An instance of this class is a measure on a given set supp. The support is either
• a python variable of type set, or
• a list of tuples which represents a box in euclidean space.
Initializes a measure object according to the inputs:
• dom must be either
• a list of 2-tuples
• a non-empty dictionary
• w must be a
• a function if dom defines a region
• left blank (None) if dom is a dictionary
boxCheck(B)[source]

Checks the structure of the box B. Returns True id B is a list of 2-tuples, otherwise it returns False.

check(dom, w)[source]

Checks the input types and their consistency, according to the __init__ arguments.

integral(f)[source]

Returns the integral of f with respect to the currwnt measure over the support.

measure(S)[source]

Returns the measure of the set S. S must be a list of 2-tuples.

norm(p, f)[source]

Computes the norm-p of the f with respect to the current measure.

sample(num)[source]

Samples from the support according to the measure.

class orthsys.OrthSystem(variables, var_range, env='sympy')[source]

OrthogonalSystem class produces an orthogonal system of functions according to a suggested basis of functions and a given measure supported on a given region.

This basically performs a ‘Gram-Schmidt’ method to extract the orthogonal basis. The inner product is obtained by integration of the product of functions with respect to the given measure (more accurately, the distribution).

To initiate an instance of this class one should provide a list of symbolic variables variables and the range of each variable as a list of lists var_range.

To initiate an orthogonal system of functions, one should provide a list of symbolic variables variables and the range of each these variables as a list of lists var_range.
Basis(base_set)[source]

To specify a particular family of function as a basis, one should call this method with a list base_set of linearly independent functions.

FormBasis()[source]

Call this method to generate the orthogonal basis corresponding to the given basis via Basis method. The result will be stored in a property called OrthBase which is a list of function that are orthogonal to each other with respect to the measure measure over the given range Domain.

FourierBasis(n)[source]

Generates a Fourier basis from variables consisting of all $$sin$$ & $$cos$$ functions with coefficients at most n.

PolyBasis(n)[source]

Generates a polynomial basis from variables consisting of all monomials of degree at most n.

Series(f)[source]

Given a function f, this method finds and returns the coefficients of the series that approximates f as a linear combination of the elements of the orthogonal basis.

SetMeasure(M)[source]

To set the measure which the orthogonal system will be computed, simply call this method with the corresponding distribution as its parameter dm; i.e, the parameter is d(m) where m is the original measure.

SetOrthBase(base)[source]

Sets the orthonormal basis to be the given base.

TensorPrd(Bs)[source]

Takses a list of symbolic bases, each one a list of symbolic expressions and returns the tensor product of them as a list.

inner(f, g)[source]

Computes the inner product of the two parameters with respect to the measure measure.

project(f, g)[source]

Finds the projection of f on g with respect to the inner product induced by the measure measure.

class interpolation.Interpolation(var, env='sympy')[source]

The Interpolation class provides polynomial interpolation routines in multi variate case.

var is the list of symbolic variables and env is the the symbolic tool.

Delta(idx=-1)[source]

Construct the matrix corresponding to idx‘th point, if idx>0 Otherwise returns the discriminant.

Interpolate(points, vals)[source]

Takes a list of points points and corresponding list of values vals and return the interpolant.

Since in multivariate case, there is a constraint on the number of points, it checks for the valididty of the input. In case of failure, describes the type of error occured according to the inputs.

MinNumPoints()[source]

Returns the minimum number of points still required.

Monomials()[source]

Generates the minimal set of monomials for interpolation.

class collocation.Collocation(variables, ufunc, env='sympy')[source]

The Collocation class tries to approximate the solutions of a system of partial differential equations with respect to an orthogonal system of functions.

To initiate an instance of this class one needs to provide two set of parameters:
1. List of independent symbolic variables variables;
2. List of unknown functions to be found that depend on the independent variables ufunc.
CollPoints(pnts)[source]

Accepts alist of collocation point pnts, to form the algebraic system of equations and find the coefficients of the orthogonal functions from OrthSystem.OrthBase. Each point must be either a list or a tuple.

Condition(eq, val)[source]

List of initial and boundary conditions.

Equation(eq)[source]

To enter the system of equations, use this meyhod with a list of equations as input.

FindDomain()[source]

Finds the region that all variables are defined.

PlugPoints()[source]

Internal use: plug in collocation points to elliminate independent variables and keep the coefficients.

SetOrthSys(obj, func)[source]

To approximate the solutions of the system of pdes, the class requires an orthogonal system of functions OrthSystem. This method accepts such a system.

Solve()[source]

Solves the collocation equations and keep a dictionary of coefficients in self.Coeffs and returns a list of functions in the span of orthoginal system.

collocate()[source]

Internal use: generates the system of equations for coefficients to be used via collocation points.

setSampleMeasure(meas)[source]

Sets the measure over the domain for sampling collocation points in case of necessity.

setSolver(solver, optn='lm')[source]

Currently only two solvers are supported:

1. the sages defult solver for rather simple system of algebraic equations.

2. the scipys fsolves to handel more complex and larger systems. It also supports the following solvers from scipy:

• hybr
• lm (defauls)
• broyden1
• broyden2
• anderson
• krylov
• df-sane
class subregion.SubRegion(collsys, num_parts=[])[source]

The SubRegion class partitions the region into sub-regions, solve the system of Integro-differential equations on each and glue them together.

It takes:
1. a collocation instance collsys;
2. an optional list of positive integers num_parts which shows the number of equal length partitions for each variable.
AnalyseConditions()[source]

Associates boundary conditions to each sub-collocation system. Starting from one corner, associates boundary conditions to all adjacent subregions based on the solution of the current subregion.

ClosedForm(func)[source]

Compiles a piece-wise defined symbolic function from the solution for func which is an unknown from the original collocation system.

InitMiniSys()[source]

Initializes a set of collocation systems for all subregions.

Solve()[source]

Solves the collocation system for each region and generates boundary conditions for adjacent regions.

corners(tpl)[source]

Generates end corner points of the region represented tpl as collocation points (used internally).

class graphics.Graphics(env='numeric', numpoints=50)[source]

This class tends to provide basic graphic tools based on matplotlib and mayavi.

Accepts one optional argument env which determines the types of the function to be visualized:

• numeric: is a numerical function (regular python functions)
• sympy: Sympy symbolic function
• sage: Sage symbolic function
ParamPlot2D(funcs, rng, color='blue', legend='', thickness=1)[source]

Appends a parametric curve to the Graphics object. The parameters are as follows:

• funcs: the tupleof functions to be plotted,
• rng: a triple of the form (t, a, b), where t is the funcs‘s independents variable, over the range [a, b],
• color: the color of the current curve,
• legend: the text for the legend of the current crve.
Plot2D(func, xrng, color='blue', legend='', thickness=1)[source]

Appends a curve to the Graphics object. The parameters are as follows:

• func: the function to be plotted,
• xrng: a triple of the form (x, a, b), where x is the func‘s independents variable, over the range [a, b],
• color: the color of the current curve,
• legend: the text for the legend of the current crve.
Plot3D(func, xrng, yrng)[source]

Sets a surface to the Graphics object. The parameters are as follows:

• func: the function to be plotted,
• xrng: a triple of the form (x, a, b), where x is the first funcs independents variable, over the range [a, b],
• yrng: a triple of the form (y, c, d), where x is the second func‘s independents variable, over the range [c, d].
Point(pnts, color='blue', marker='o', legend='')[source]

Adds a list of points to the plot.

SetLabelX(lbl)[source]

Sets the label for X axis

SetLabelY(lbl)[source]

Sets the label for Y axis

SetLabelZ(lbl)[source]

Sets the label for Z axis

SetTitle(ttl)[source]

Sets the title of the graph.

interact()[source]

Shows an interavtive demo of the 3D surface, using mayavi, so it requires mayavi for python to be installed.

save(fname='fig.png')[source]

Saves the outpu of the Graphics object to the file fname.