npm install math-helper --save
- General
- isPrime(n: number): boolean
- nextPrime(n: number): number
- isEven(num: number): boolean
- isEvenBitwise(num: number): boolean
- log(base: number, value: number): number
- powerOfTwo(num: number): boolean
- isDivisibleByPowOf2(num: number, divisor: number): boolean
- isDivisible(num: number, divisor: number): boolean
- bitForNumberByBase(num: number, base: number, n_bits: number): number
- factorial(num: number, tmp_fact?: number): number
- Chaining (W.I.P.)
- Geometry
- plane(a:number, b:number, c:number, d:number):Polynomial3D
- projectOnPlane(polynomial:Polynomial2D, plane:Polynomial3D):Polynomial3D
- parabola(a:number, b:number, c:number):Polynomial2D
- parabolaParametric(a:number, from:number, to:number, step:number):Array<Array>
- ellipse(cx:number, cy:number, a:number, b:number):Polynomial2D
- ellipseParametric(cx:number, cy:number, a:number, b:number, rad:number): Array<Array>
- Chaining (W.I.P.)
- Statistic
- arithmeticMean(data:Array):number
- arithmeticWeightedMean(data:Array<Array>):number
- linearRegression(data:Array<Array>):Array<Array>
- binomialCoefficient(n:number, m:number):number
- howManyPermutationsR(data:Array):number
- howManyPermutations(data:Array):number
- howManyDispositionsR(data:Array, m:number):number
- howManyDispositions(data:Array, m:number):number
- howManyCombinationsR(data:Array, m:number):number
- howManyCombinations(data:Array, m:number):number
- Chaining (W.I.P.)
- Trigonometry
- Common (W.I.P.)
import * as MH from 'math-helper';
let is_prime:boolean = MH.General.isPrime(13);
console.log(is_prime); // true
let is_not_prime:boolean = MH.General.isPrime(14);
console.log(is_not_prime); // false
import * as MH from 'math-helper';
let next_prime:number = MH.General.nextPrime(12);
console.log(next_prime); // 13
import * as MH from 'math-helper';
console.log(MH.General.isEven(1223)); // false
console.log(MH.General.isEven(1222)); // true
Come la precedente ma utilizza operazioni bitwise, utile nel caso di grandi iterazioni
import * as MH from 'math-helper';
let log:number = MH.General.isEven(12, 144);
console.log(log); // 2
È possibile specificare una base arbitraria (N.B.: non sono ancora presenti controlli su base e argomento)
import * as MH from 'math-helper';
let result:number = MH.General.powerOfTwo(12);
console.log(result); // 4096
Calcole le potenze di due specificando l'esponente, con operazioni bitwise
import * as MH from 'math-helper';
let is_divisible: boolean = MH.General.isDivisibleByPowOf2(1234, 16);
console.log(is_divisible); // false
Controlla se un numero è divisibile per una potenza di 2 con operazioni bitwise, non funziona correttamente se si passa un divisore che non sia potenza di 2
Come il precedente ma usa solo l'operatore % e non ha limitazioni per i dati in ingresso
import * as MH from 'math-helper';
let nbit:number = MH.General.bitForNumberByBase(1234, 16); // 1234 -> 0x4D2
console.log(nbit); // 3
Fornisce il numero di bit necessari a rappresentare il numero in ingresso in funzione dalla base fornita
import * as MH from 'math-helper';
let factorial:number = MH.General.factorial(17);
console.log(factorial); // 355687428096000
Calcolo con funzione tail recursive
import * as MH from 'math-helper';
MH.General.chain(3);
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let plane:Array<number> = MH.Geometry.plane(2, 3, 4)(data);
console.log(plane);
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let plane:MH.Polynomial3D = MH.Geometry.plane(2, 3, 4);
let parabola:MH.Polynomial2D = MH.Geometry.parabola(2, 3, 4);
let projection:Array<number> = MH.Geometry.projectOnPlane(parabola, plane)(data);
console.log(projection);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let parabola:Array<number> = MH.Geometry.parabola(2, 3, 4)(data);
console.log(parabola);
import * as MH from 'math-helper';
let parabola:Array<number> = MH.Geometry.parabolaParametric(2, 0, 100, 0.01);
console.log(parabola);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let ellipse:Array<number> = MH.Geometry.ellipse(2, 3, 4, 5)(data);
console.log(ellipse);
import * as MH from 'math-helper';
let ellipse:Array<number> = MH.Geometry.ellipseParametric(2, 3, 4, 5, 0.1);
console.log(ellipse);
import * as MH from 'math-helper';
MH.Geometry.chain(3);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let mean:Array<number> = MH.Statistic.arithmeticMean(data);
console.log(mean);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let mean:Array<number> = MH.Statistic.arithmeticWeightedMean(data);
console.log(mean);
import * as MH from 'math-helper';
let data:Array<Array<number>> = Array.from({length: 100}, () => [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)]);
let regression:Array<Array<number>> = MH.Statistic.linearRegression(data);
console.log(regression);
import * as MH from 'math-helper';
let bc:Array<Array<number>> = MH.Statistic.binomialCoefficient(5, 2);
console.log(bc); // 10
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let permutations:number = MH.Statistic.howManyPermutationsR(data);
console.log(permutations);
Permutazioni con ripetizione
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let permutations:number = MH.Statistic.howManyPermutations(data);
console.log(permutations);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let dispositions:number = MH.Statistic.howManyDispositionsR(data);
console.log(dispositions);
Disposizioni con ripetizione
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let dispositions:number = MH.Statistic.howManyDispositions(data);
console.log(dispositions);
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let combinations:number = MH.Statistic.howManyCombinationsR(data);
console.log(combinations);
Combinazioni con ripetizione
import * as MH from 'math-helper';
let data:Array<number> = Array.from({length: 100}, () => Math.floor(Math.random() * 100));
let combinations:number = MH.Statistic.howManyCombinations(data);
console.log(combinations);
import * as MH from 'math-helper';
MH.Statistic.chain(3);
import * as MH from 'math-helper';
let sin:number = MH.Trigonometry.sinWithAmplitude(Math.PI/6, 3);
console.log(sin);
import * as MH from 'math-helper';
let sin:number = MH.Trigonometry.sinWithShift(Math.PI/6, 3);
console.log(sin);
import * as MH from 'math-helper';
let cos:number = MH.Trigonometry.cosWithAmplitude(Math.PI/6, 3);
console.log(cos);
import * as MH from 'math-helper';
let cos:number = MH.Trigonometry.cosWithShift(Math.PI/6, 3);
console.log(cos);
import * as MH from 'math-helper';
MH.Trigonometry.chain(3);
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.chainWith<MH.Geometry, MH.GeometryChain>(MH.Geometry, Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.switchTo(MH.Geometry)
.chain(Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()
import * as MH from 'math-helper';
MH.General
.chain(3)
.bitForNumberByBase(6, 8)
.switchTo(MH.Geometry)
.chain(Math.PI/12)
.ellipseParametric(3, 2,4,5)
.done()