data: ^0.5.1 copied to clipboard
A time and space efficient collection of data structures and algorithms to deal with data in Dart.
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.
Below are step by step instructions of how to use this library. More elaborate examples are included with the examples.
Follow the installation instructions on dart packages.
Import the packages into your Dart code using:
import 'package:data/matrix.dart'; import 'package:data/vector.dart'; import 'package:data/type.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'
The MIT License, see LICENSE.
The matrix decomposition algorithms are a direct port of the JAMA: A Java Matrix Package, that is released under public domain.