dart data
dart data is a fast and space efficient library to deal with data in dart, flutter and the web. as of today this mostly includes data structures and algorithms for vectors and matrices, but at some point might also include graphs and other mathematical structures.
this library is open source, stable and well tested. development happens on . feel free to report issues or create a pull-request there. general questions are best asked on stackoverflow.
the package is hosted on dart packages. up-to-date class documentation is created with every release.
tutorial
below are step-by-step instructions of how to use this library. more elaborate examples are included with the examples.
installation
follow the installation instructions on dart packages.
import the core-package into your dart code using:
import 'package:data/data.dart';
how to solve a linear equation?
solve ‘a * x = b’, where ‘a’ is a matrix and ‘b’ a vector:
final a = matrix<double>.fromrows(datatype.float64, [
[2, 1, 1],
[1, 3, 2],
[1, 0, 0],
]);
final b = vector<double>.fromlist(datatype.float64, [4, 5, 6]);
final x = a.solve(b.columnmatrix).column(0);
print(x.format(valueprinter: printer.fixed()); // prints '6 15 -23'
how to find the eigenvalues of a matrix?
find the eigenvalues of a matrix ‘a’:
final a = matrix<double>.fromrows(datatype.float64, [
[1, 0, 0, -1],
[0, -1, 0, 0],
[0, 0, 1, -1],
[-1, 0, -1, 0],
]);
final decomposition = a.eigenvalue;
final eigenvalues = vector<double>.fromlist(
datatype.float64, decomposition.realeigenvalues);
print(eigenvalues.format(valueprinter: printer.fixed(precision: 1))); // prints '-1.0 -1.0 1.0 2.0'
how to find all the roots of a polynomial?
to find the roots of x^5 + -8x^4 + -72x^3 + 242x^2 + 1847x + 2310
:
final polynomial = polynomial.fromcoefficients(datatype.int32, [1, -8, -72, 242, 1847, 2310]);
final roots = polynomial.roots;
print(roots.map((root) => root.real)); // [-5, -3, -2, 7, 11]
print(roots.map((root) => root.imaginary)); // [0, 0, 0, 0, 0]
Comments are closed.