# equation-balancer

> > A very simple CLI chemical equation balancer

Latest version **0.1.1** (published 2017-10-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install equation-balancer
pnpm add equation-balancer
yarn add equation-balancer
bun add equation-balancer
```

Provides the command `equation-balancer`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-10-09 |
| First published | 2017-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+5 in 2 direct dependencies) |
| Install scripts | no |
| Author | Rico Kahler |
| Maintainers | ricokahler |

## Links

- npm: https://www.npmjs.com/package/equation-balancer
- Repository: https://github.com/ricokahler/equation-balancer
- Homepage: https://github.com/ricokahler/equation-balancer#readme
- Issues: https://github.com/ricokahler/equation-balancer/issues
- npm.io page: https://npm.io/package/equation-balancer

## Dependencies (3)

- [npm](https://npm.io/package/npm.md) ^5.4.2
- [rref](https://npm.io/package/rref.md) ^0.0.1
- [mathjs](https://npm.io/package/mathjs.md) ^3.16.4

## Recent versions

- 0.1.1 (latest) — 2017-10-09
- 0.1.0 — 2017-10-09

## README

# Equation balancer

> A very simple CLI chemical equation balancer

## Install

```
npm install -g equation-balancer
```

Requires Node 8.

## Usage

Call `equation-solver` with no arguments to get a loop that prompts for an equation:

```
balance > Fe + H2SO4 -> Fe2(SO4)3 + H2
2, 3, 1, 3
```

or call `equation-solver` with a single argument of the equation you want balanced **in quotes**.

```
equation-balancer "Fe + H2SO4 -> Fe2(SO4)3 + H2"
2, 3, 1, 3
```

Separate terms with `+` and use `->` to separate the reactants from the products. Capitalization matters.

## Library

You can also use the function programmatically,

```js
const balance = require('equation-balancer/balance');
balance('Fe + H2SO4 -> Fe2(SO4)3 + H2') // [2, 3, 1, 3]
``` 

## How does it work?

It parses the input into a set of terms and places them into a matrix.

For example, the equation

    Fe + H2SO4 -> Fe2(SO4)3 + H2

Gets parsed into:

```js
const matrix = [
  [ 1, 0, -2, 0 ],    // Fe 
  [ 0, 4, -12, 0 ],   // O
  [ 0, 2, 0, -2 ],    // H
  [ 0, 1, -3, 0 ],    // S
];
```

And then that gets row reduced into:

```js
const reduceMatrix = [
  [ 1, 0, 0, -0.6666666666666666 ],
  [ 0, 1, 0, -1 ],
  [ 0, 0, 1, -0.3333333333333333 ],
  [ 0, 0, 0, 0 ]
];
```

The last column of rows in the matrix get converted to fractions and then the LCM is applied to give the final result:

    2, 3, 1, 3

---
_Source: https://npm.io/package/equation-balancer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
