[Go to site: main page, start]

equations 6.0.0 copy "equations: ^6.0.0" to clipboard
equations: ^6.0.0 copied to clipboard

An equation-solving library that supports complex numbers.

example/README.md

Examples #

Here is a quick overview of the main features of the equations package. For more information about solving equations and examples on how to use the classes from this package, see the articles on the repository's Wiki pages:

Algebraic (Polynomial) equations #

// f(x) = ix^3 + (-2 + 5i)x + 7
final equation = Cubic(
  a: const Complex.i(),
  c: const Complex(-2, 5),
  d: const Complex.fromReal(7),
);
final solutions = equation.solutions();

/// -1.0447245173314328 + 1.7792977920746025i 
/// 0.3113353509227148 - 2.7574534545940717i
/// 0.733389166408717 + 0.9781556625194701i
print(solutions);

Nonlinear equations #

// f(x) = x^e - cos(x)
final newtonRaphson = Newton(function: 'x^e-cos(x)', x0: 0.5)
final result = newtonRaphson.solve();

// 0.856055...
print(result.guesses.last);

Systems of equations #

// [1.0, 0.0, 1.0 | 6.0]
// [0.0, 2.0, 0.0 | 5.0]
// [1.0, 0.0, 3.0 | -2.0]
final solver = LUSolver(
  matrix: RealMatrix.fromData(
    rows: 3,
    columns: 3,
    data: const [
      [1, 0, 1],
      [0, 2, 0],
      [1, 0, 3],
    ],
  ),
  knownValues: [6, 5, -2],
);
final solutions = solver.solve();

// 10.0
// 2.5
// -4.0
print(solutions);