k1lib.graphEqn module

This module is for creating dynamic graphs using plain old equations. For example:

from k1lib.imports import *
x = graphEqn.Variable()
y = x * 3 + 5
z = y ** 5

z(2) # returns 161051 (from (2 * 3 + 5) ** 5)

Point is, x is an unknown, y is a “function” of x. z depends on y, but is also a function of x.

Remember that you can go pretty wild with this:

x2 = k1lib.inverse(z)
x2(161051) # returns 2.0

Here, x2 is actually a function x(z).

For simple functions like this, it should take 200us to solve it. You can also declare a bunch of variables early on, and then resolve them one by one like this:

a = Variable(); b = Variable()
c = a + b + 2; a.value = 6
c(5) # returns 13

b.value = 7
c() # returns 15
class k1lib.graphEqn.Variable[source]

Bases: object

property value: Optional[float]

Actual float value of Variable. When setting this, if the new value’s not None, the object would act like a constant in every future equations. To turn it back into a Variable, simply set this to None.

property resolved

Whether this variable has been resolved or not.

property leaves
__call__(x: Optional[float] = None) Optional[float][source]

Tries to solve this variable given the independent variable x.

Parameters

x – if nothing is specified, you have to be sure that all variables already have a value.