linalg 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new61

CI Pub Coverage Status

linalg

A Simple Linear Algebra Package.

This package is intended to be a portable, easy to use linear algebra package. It does not have any dependencies outside of Dart itself, thus making it portable and easy to integrate.

Our goal is to keep the code readable, documented and maintainable.

Short Example

Just a quick example on how to do matrix multiplication.

final Matrix a = Matrix([[1, 2], [3, 4]]);
final Vector b = Vector.column([2, 3]);
final Matrix e = Matrix([[8], [18]]);
Matrix result = a * b;
print(result);
print(result == e);

This prints

[[8.0], [18.0]]
true

Complete Example

A more extensive example with various matrix operations. See the Matrix API and Vector API for the full details.

import 'package:linalg/linalg.dart';

void example() {
	// *****************************
	// Lets solve a linear equation.
	// *****************************
	//
	// A * B = E
	//
	// We have B and E, we have to find A.
	//
	// A * B * B' = E * B'
	//
	// Were B' = inverse of B.
	//
	// A * I = E * B'
	//
	// Where I = identity matrix
	//
	// A = E * B'
	final Matrix B = Matrix([[2, 0], [1, 2]]);
	final Matrix E = Matrix([[4, 4], [10, 8]]);


	Matrix Bi = B.inverse();
	Matrix A_calc = E * Bi;

	final Matrix A = Matrix([[1, 2], [3, 4]]);
	print("The calculated A_calc = $A_calc, the expected A is $A, they are ${A_calc==A?'':'not'} the same.");
	// Expected: The calculated A = [[1.0, 2.0], [3.0, 4.0]], the expected A is [[1.0, 2.0], [3.0, 4.0]], they are  the same.



	// *****************************
	// Lets do some more matrix math
	// *****************************
	//
	// Next let multiply Matrix A by 3.
	Matrix Am = A * 3.0;
	print(Am);
	// Expecting: [[3.0, 6.0], [9.0, 12.0]]

	// Now add matrix B to A
	Matrix AmPlusB = Am + B;
	print(AmPlusB);
	// Expecting: [[5.0, 6.0], [10.0, 14.0]]

	// What is the determinant of the A matrix?
	print("The determinant of A = ${A.det()}");
	// Expecting The determinant of A = -2.0
}

Installation

Add linalg as a dependency to your flutter project.

dependencies:
  linalg: ^0.1.1

and at the top of your dart file add:

import 'package:linalg/linalg.dart';

Attribution

Original code came from: https://pub.dartlang.org/packages/toaster_linear

We ended up rewriting considerable parts of the code and adding tests and documentation.

[0.10.1] -- 11/27/2018

  • Documentation updates
  • Added Matrix.trace, Vector.crossProduct and Vector.dotProduct

[0.10.0] -- 11/26/2018

  • Slight documentation modifications.

[0.0.6] -- 11/26/2018

  • Added Vector class.

[0.0.5] -- 11/21/2018

  • Dart minimum back to 2.0.0 fixed linter errors.

[0.0.4] -- 11/21/2018

  • Increased Dart minimum to 2.1.0 to allow int to double assignments.

[0.0.3] -- 11/21/2018

  • Removed flutter dependency

[0.0.2] - 11/21/2018

  • Added examples
  • Added Travis CI
  • Improved readme

[0.0.1] - 11/21/2018.

  • Initial release

example/example.dart

import 'package:linalg/linalg.dart';

void readMeExample() {
  final Matrix a = Matrix([
    [1, 2],
    [3, 4]
  ]);
  final Vector b = Vector.column([2, 3]);
  final Matrix e = Matrix([
    [8],
    [18]
  ]);
  Matrix result = a * b;
  print(result);
  print(result == e);
}

/// Example code for using the Matrix class.
void main() {

  readMeExample();

  // *****************************
  // Lets solve a linear equation.
  // *****************************
  //
  // A * B = E
  //
  // We have B and E, we have to find A.
  //
  // A * B * B' = E * B'
  //
  // Were B' = inverse of B.
  //
  // A * I = E * B'
  //
  // Where I = identity matrix
  //
  // A = E * B'
  final Matrix B = Matrix([
    [2.0, 0.0],
    [1.0, 2.0]
  ]);
  final Matrix E = Matrix([
    [4.0, 4.0],
    [10.0, 8.0]
  ]);

  Matrix Bi = B.inverse();
  Matrix A_calc = E * Bi;

  final Matrix A = Matrix([
    [1.0, 2.0],
    [3.0, 4.0]
  ]);
  print(
      "The calculated A = $A_calc, the expected A is $A, they are ${A_calc == A ? '' : 'not'} the same.");
  // Expected: The calculated A = [[1.0, 2.0], [3.0, 4.0]], the expected A is [[1.0, 2.0], [3.0, 4.0]], they are  the same.

  // *****************************
  // Lets do some more matrix math
  // *****************************
  //
  // Next let multiply Matrix A by 3.
  Matrix Am = A * 3.0;
  print(Am);
  // Expecting: [[3.0, 6.0], [9.0, 12.0]]

  // Now add matrix B to A
  Matrix AmPlusB = Am + B;
  print(AmPlusB);
  // Expecting: [[5.0, 6.0], [10.0, 14.0]]

  // What is the determinant of the A matrix?
  print("The determinant of A = ${A.det()}");
  // Expecting The determinant of A = -2.0
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  linalg: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:linalg/linalg.dart';
  
Version Uploaded Documentation Archive
0.1.1 Nov 27, 2018 Go to the documentation of linalg 0.1.1 Download linalg 0.1.1 archive
0.1.0 Nov 26, 2018 Go to the documentation of linalg 0.1.0 Download linalg 0.1.0 archive
0.0.6 Nov 26, 2018 Go to the documentation of linalg 0.0.6 Download linalg 0.0.6 archive
0.0.5 Nov 22, 2018 Go to the documentation of linalg 0.0.5 Download linalg 0.0.5 archive
0.0.4 Nov 22, 2018 Go to the documentation of linalg 0.0.4 Download linalg 0.0.4 archive
0.0.3 Nov 22, 2018 Go to the documentation of linalg 0.0.3 Download linalg 0.0.3 archive
0.0.2 Nov 22, 2018 Go to the documentation of linalg 0.0.2 Download linalg 0.0.2 archive
0.0.1 Nov 21, 2018 Go to the documentation of linalg 0.0.1 Download linalg 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:linalg/linalg.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
coverage ^0.12.3
coveralls ^4.3.0
grinder ^0.8.3
test ^1.5.0