finesse.symbols.Variable

Overview

class finesse.symbols.Variable(name)[source]

Bases: Symbol

Makes a variable symbol that can be used in symbolic math. Values must be substituted in when evaluating an expression.

Parameters:
valuefloat, int

Value of constant

namestr, optional

Name of the constant to use when printing

Examples

Using some variables to make an expression and evaluating it:

>>> import numpy as np
>>> x = Variable('x')
>>> y = Variable('y')
>>> z = 4*x**2 - np.cos(y)
>>> print(f"{z} = {z.eval(subs={x:2, y:3})} : x={2}, y={3}")
(4*x**2-y) = 13 : x=2, y=3

Properties

Variable.name

Methods

Variable.__init__(name)

Variable.eval([subs, keep])

Evaluates this variable and returns either itself or a numeric value.