Updated docs and examples

This commit is contained in:
Eric 2015-08-06 13:34:12 +00:00
parent dfbc575bc1
commit 4f6cc1254b
4 changed files with 54 additions and 17 deletions

View File

@ -20,9 +20,10 @@ Temperature | kelvin (K), celsius (degC), fahrenheit (degF), rankine (de
Amount of substance | mole (mol)
Luminous intensity | candela (cd)
Force | newton (N), dyne (dyn), poundforce (lbf)
Energy | J, erg, Wh, BTU
Power | W, hp
Energy | joule (J), erg, Wh, BTU, electronvolt (eV)
Power | watt (W), hp
Pressure | Pa, psi, atm
Electricity and Magnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
Binary | bit (b), byte (B)
Note that all relevant units can also be written in plural form, for example `5 meters` instead of `5 meter` or `10 seconds` instead of `10 second`.

View File

@ -83,3 +83,26 @@ console.log('h = ');
print(h);
console.log('v = (2 g h) ^ 0.5 =');
print(v);
console.log();
console.log('electrical power consumption:');
print(math.eval('460 V * 20 A * 30 days to kWh')); // 6624 kWh
console.log();
console.log('circuit design:');
print(math.eval('24 V / (6 mA)')); // 4 kΩ
console.log();
console.log('operations on arrays:');
var B = math.eval('[1, 0, 0] T');
var v = math.eval('[0, 1, 0] m/s');
var q = math.eval('1 C');
var F = math.multiply(q, math.cross(v, B));
console.log('B (magnetic field strength) = ');
print(B);
console.log('v (particle velocity) = ');
print(v);
console.log('q (particle charge) = ');
print(q);
console.log('F (force) = q (v cross B) = ');
print(F);

View File

@ -1969,6 +1969,13 @@ function factory (type, config, load, typed) {
prefixes: PREFIXES.SHORT,
value: 1,
offset: 0
},
joule: {
name: 'joule',
base: BASE_UNITS.ENERGY,
prefixes: PREFIXES.SHORT,
value: 1,
offset: 0
},
erg: {
name: 'erg',
@ -2014,6 +2021,13 @@ function factory (type, config, load, typed) {
prefixes: PREFIXES.SHORT,
value: 1,
offset: 0
},
watt: {
name: 'W',
base: BASE_UNITS.POWER,
prefixes: PREFIXES.LONG,
value: 1,
offset: 0
},
hp: {
name: 'hp',
@ -2099,7 +2113,6 @@ function factory (type, config, load, typed) {
value: 1,
offset: 0
},
/*
Ω: {
name: 'Ω',
base: BASE_UNITS.ELECTRIC_RESISTANCE,
@ -2107,7 +2120,6 @@ function factory (type, config, load, typed) {
value: 1,
offset: 0
},
*/
// Electric inductance
henry: {
name: 'henry',
@ -2248,13 +2260,13 @@ function factory (type, config, load, typed) {
gradients: 'grad',
cycles: 'cycle',
joules: 'joule',
watts: 'watt',
BTUs: 'BTU',
watts: 'watt',
joules: 'joule',
amperes: 'ampere',
coulombs: 'coulomb',
volts: 'volts',
volts: 'volt',
ohms: 'ohm',
farads: 'farad',
webers: 'weber',
@ -2291,7 +2303,7 @@ function factory (type, config, load, typed) {
ELECTRIC_CHARGE: {unit: UNITS.C, prefix: PREFIXES.SHORT['']},
ELECTRIC_CAPACITANCE: {unit: UNITS.F, prefix: PREFIXES.SHORT['']},
ELECTRIC_POTENTIAL: {unit: UNITS.V, prefix: PREFIXES.SHORT['']},
ELECTRIC_RESISTANCE: {unit: UNITS.ohm, prefix: PREFIXES.SHORT['']},
ELECTRIC_RESISTANCE: {unit: UNITS.Ω, prefix: PREFIXES.SHORT['']},
ELECTRIC_INDUCTANCE: {unit: UNITS.H, prefix: PREFIXES.SHORT['']},
ELECTRIC_CONDUCTANCE: {unit: UNITS.S, prefix: PREFIXES.SHORT['']},
MAGNETIC_FLUX: {unit: UNITS.Wb, prefix: PREFIXES.SHORT['']},

View File

@ -706,15 +706,16 @@ describe('unit', function() {
describe('UNITS', function() {
it('should be of the correct value and dimension', function() {
assert.equal(new Unit(1, 's A'), new Unit(1, 'C'));
assert.equal(new Unit(1, 'W/A'), new Unit(1, 'V'));
assert.equal(new Unit(1, 'V/A'), new Unit(1, 'ohm'));
assert.equal(new Unit(1, 'C/V'), new Unit(1, 'F'));
assert.equal(new Unit(1, 'J/A'), new Unit(1, 'Wb'));
assert.equal(new Unit(1, 'Wb/m^2'), new Unit(1, 'T'));
assert.equal(new Unit(1, 'Wb/A'), new Unit(1, 'H'));
assert.equal(new Unit(1, 'ohm^-1'), new Unit(1, 'S'));
assert.equal(new Unit(1, 'eV'), new Unit(1.602176565e-19, 'J'));
assert.equal(new Unit(1, 's A') .equals(new Unit(1, 'C')) , true);
assert.equal(new Unit(1, 'W/A') .equals(new Unit(1, 'V')) , true);
assert.equal(new Unit(1, 'V/A') .equals(new Unit(1, 'ohm')), true);
assert.equal(new Unit(1, 'C/V') .equals(new Unit(1, 'F')) , true);
assert.equal(new Unit(1, 'J/A') .equals(new Unit(1, 'Wb')) , true);
assert.equal(new Unit(1, 'Wb/m^2').equals(new Unit(1, 'T')) , true);
assert.equal(new Unit(1, 'Wb/A') .equals(new Unit(1, 'H')) , true);
assert.equal(new Unit(1, 'ohm^-1').equals(new Unit(1, 'S')) , true);
assert.equal(new Unit(1, 'eV') .equals(new Unit(1.602176565e-19, 'J')), true);
});
});
});