Simple math functions.
use Jstewmc\Fx;
(new Constant(1))(3); // returns 1
(new Equality())(3); // returns 3
(new Linear(1, 2))(3); // returns 5 (1 * 3 + 2)
(new Quadratic(1, 2, 3))(4); // returns 27 (1 * 4 ^ 2 + 2 * 4 + 3)
(new Power(1, 2))(3); // returns 9 (1 * 3 ^ 2)
(new Exponential(1))(2); // returns 1 (1 ^ 2)
This library supports the following functions:
- constant,
c = x
- equality,
y = x
- linear,
y = mx + b
- quadratic,
y = ax2 + bx + c
- power,
y = cxp
- exponential,
y = bx
A constant function where c = x
:
use Jstewmc\Fx
$fx = new Constant(1);
$fx(1); // returns 1
$fx(2); // returns 1
$fx(3); // returns 1
An equality where y = x
:
use Jstewmc\Fx;
$fx = new Equality();
$fx(1); // returns 1
$fx(2); // returns 2
$fx(3); // returns 3
A linear function is y = mx + b
, where m
is the slope and b
is the y-intercept:
use Jstewmc\Fx;
$fx = new Linear(1, 2);
$fx(1); // returns 3 (1 * 1 + 2)
$fx(2); // returns 4 (1 * 2 + 2)
$fx(3); // returns 5 (1 * 3 + 2)
A univariate, standard-form quadratic function is y = ax2 + bx + c
, where a
, b
, and c
are constants (aka, the quadratic coefficient, the linear coefficient, and the constant, respectively):
use Jstewmc\Fx;
$fx = new Quadratic(1, 2, 3);
$fx(1); // returns 5 (1 * 1 ^ 2 + 2 * 1 + 3)
$fx(2); // returns 11 (1 * 2 ^ 2 + 2 * 2 + 3)
$fx(3); // returns 18 (1 * 3 ^ 2 + 2 * 3 + 3)
A power function is y = cxp
, where c
is a constant, and p
is the power:
use Jstewmc\Fx;
$fx = new Power(1, 2);
$fx(1); // returns 1 (1 * 1 ^ 2)
$fx(2); // returns 4 (1 * 2 ^ 2)
$fx(3); // returns 9 (1 * 3 ^ 2)
An exponential function is y = bx
, where b
is a constant:
use Jstewmc\Fx;
$fx = new Exponential(2);
$fx(1); // returns 2 (2 ^ 1)
$fx(2); // returns 4 (2 ^ 2)
$fx(3); // returns 8 (2 ^ 3)
That's it!
- Major release
- Update
composer.json
- Update
Fx
parent class to be an interface
- Add
Fx
parent class
- Update README examples
- Add
Equality
function - Add
Constant
function
- Initial release