Dart 数据

Dart Data 是一个用于处理 Dart、Flutter 和 Web 中数据的快速且节省空间的库。截至今日,它主要包括用于向量和矩阵的数据结构和算法,但将来也可能包括图和其他数学结构。

该库是开源的、稳定的且经过充分测试。开发在 GitHub 上进行。欢迎在此报告问题或创建拉取请求。一般问题最好在 StackOverflow 上提问。

该软件包托管在 dart packages 上。每次发布都会生成最新的 类文档

教程

以下是如何使用此库的分步说明。更详细的示例包含在 示例 中。

安装

请遵循 dart packages 上的安装说明。

使用以下方法将核心包导入您的 Dart 代码

import 'package:data/data.dart';

如何解线性方程?

求解 'A * x = b',其中 'A' 是矩阵,'b' 是向量

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'

如何找到矩阵的特征值?

查找矩阵 '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'

如何找到多项式的所有根?

查找 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]

GitHub

https://github.com/renggli/dart-data