# ahkab.gear¶

About the method: This is an implicit method, it means that to compute dx(n+1)/dt the value of x in (n+1) is required. We don’t know it, since it’s our objective). This method, as all other implicit methods, allows us to write the derivative as:

dx(n+1)/dt = x_coeff * x(n+1) + const (ii)

The get_df method returns those two vectors.

Gear’s LMS interpolates the solution in a number of points equal to its order. Since it’s a implicit method, one of these is x(n+1). The values x(n), x(n-1)... x(n-(order+2)) need to be supplied to the method. We can write x(t) as:

x(t) = a0 + a1*(t(n+1) - t ) + a2*( t(n+1) - t )^2 + ... (i)

The equation has <order> a coefficients, which we need to determine. For this reason, we write a system of “order” equations in this way:

x(n+1) = a0 + a1*(t(n+1) - t(n+1)) + a2*(t(n+1) - t(n+1))^2 + ... x(n) = a0 + a1*(t(n+1) - t(n) ) + a2*( t(n+1) - t(n) )^2 + ... x(n-1) = a0 + a1*(t(n+1) - t(n-1)) + a2*(t(n+1) - t(n-1))^2 + ...

Which may be rewritten as:

z = A * a

z is the vector of known values of x A is a time dependant matrix a is a vector made of the a* coeffiecients

We don’t need to explicit ALL of the a* coeffiecients. What we are really looking for is the derivative of x in t(n+1), dx(n+1)/dt in short. If we differentiate the relation (i):

dx(t)/dt = -a1 - 2*a2*( t(n+1) - t ) - 3*a3*( t(n+1) - t )^2 ...
Which evaluated in t = t(n+1) gives:
dx(n+1)/dt = -1 * a1

Our objective is then a1. From the previsious system we write:

a = A^-1 * z
a1 is a[1,0], which may be extracted in this way:
et = [0 1 0 0 0 0 ...] (order elements) a1 = et * a = et * A^-1 * z

Because of the associative prperty of matrix multiplication, we can write:

P = et * A^-1 a1 = P[1, :] * z

But, we don’t know z[0,0] = x(n+1), we can split the above relation:

a1 = P[1, 0] * x(n+1) + P[1, 1:] * z[1:, 0]
We arrived to the relation written above (ii)
dx(n+1)/dt = x_coeff * x(n+1) + const = -1*a1
So:
x_coeff = -1 * P[1, 0] const = -1 * P[1, 1:] * z[1:, 0]

This module uses a faster way to compute the values that doesn’t require to invert the matrix. Anyway, from a theorical point of view, the above applies.

get_df(pv_array, suggested_step, predict=False)[source]

The array must be built in this way: It has to be an array of arrays. Each of them has the following structure:

[time, np_matrix, np_matrix]

Hence the pv_array[k] element is made of: _ time is the time in which the solution is valid: t(n-k) _ The first np_matrix is x(n-k) _ The second is d(x(n-k))/dt Values that are not needed may be set to None and they will be disregarded.

if predict == True, it needs one more point to give a prediction of x at the suggested step.

Returns: None if the incorrect values were given, or quits. Otherwise returns an array: _ the [0] element is the np matrix of coeffiecients (Nx1) of x(n+1) _ the [1] element is the np matrix of constant terms (Nx1) of x(n+1) The derivative may be written as: d(x(n+1))/dt = ret[0]*x(n+1) + ret[1]

get_required_values()[source]

This returns two python arrays built this way: [ max_order_of_x, max_order_of_dx ] Where: Both the values are int, or None if max_order_of_x is set to k, the df method needs all the x(n-i) values of x, where i<=k (the value the function assumed i+1 steps before the one we will ask for the derivative). The same applies to max_order_of_dx, but regards dx(n)/dt None means that NO value is required.

The first array has to be used if no prediction is required, the second are the values needed for prediction.

has_ff()[source]
is_implicit()[source]