Linear Expressions#

class cake.expressions.linear.LinearExpression(m: M, c: C)[source]#

Bases: PolynomialExpression, Generic[M, C]

Represents a basic linear expression, this expression can also be expressed as y = mx + c.

Parameters:
  • m (Any[Like[cake.BasicNode]]) – Gradient of expression

  • c (Any[Like[cake.BasicNode]]) – Intercept of expression

as_expression() Expression[source]#

Returns a Expression in the form of a LinearExpression

differentiate() M[source]#

Differentiates a polynomial expression

classmethod from_expression(expr: Expression) LinearExpression[source]#

Creates a LinearExpression from a Expression.

Parameters:

expr (Expression) – Expression to use, must be in the form Add(variable, Any, ...) Any values after Any will expressed as Add(Any, ...)

Raises:

TypeError – Invalid expression was given, either operation was not Add or it didn’t match the valid pattern.

classmethod from_points(point1: cake.geometry.Point2D, point2: cake.geometry.Point2D, /) LinearExpression[source]#

Returns a linear expression from 2 given 2D points

Parameters:
  • point1 (geometry.Point2D) – A 2D point to use

  • point2 (geometry.Point2D) – A 2D point to use

classmethod generic() LinearExpression[source]#

Returns a generic linear expression

property gradient: M#

Returns the gradient of the expression

integrate() cake.expressions.QuadraticExpression[source]#

Integrates a polynomial expression

property intercept: C#

Returns the intercept of the expression

r_solve(y: Any, **kwds) Any[source]#

Returns a value for when y is given, kwargs for other values may be passed as well but y is always overwritten

>>> y = LinearExpression(2, 10)
>>> y
2*x + 10
>>> y.r_solve(y=10)
0
>>> y.r_solve(y=3)
-3.5
roots() Tuple[Any, ...][source]#

Returns roots of polynomial

solve(x: Any, **kwds) Any[source]#

Returns a value for when x is given, kwargs for other values may be passed as well but x is always overwritten.

>>> y = LinearExpression(Real(0.5), 10)
>>> y
0.5*x + 10
>>> y.solve(x=5)
12.5
classmethod through_origin(m: Any) LinearExpression[source]#

Returns a linear expression which passes through the origin

Parameters:

m (Any[Like[cake.BasicNode]]) – Gradient of the expression