1.0.15 • Published 5 years ago
exec-mathexpress v1.0.15
##js解析数学公式
const execMathExpress=require('exec-mathexpress');
console.log(execMathExpress('(1/2)*(2/3)/((1/2)*(2/3)+(1/2)*(2/3)))'))
//贝叶斯 条件概率 SW=WS*S/(WS*S+WH*H);(只用于二分类)
console.log(execMathExpress('WS*S/(WS*S+WH*H)',{
WS:'1/2',
S:'1/4',
WH:'1/2',
H:'3/4'
}))
//->Fraction { num: 1, den: 4 }
//贝叶斯联合概率(只用于二分类)
console.log(execMathExpress('P0*P1*P2/(P0*P1*P2+(1-P0)*(1-P1)*(1-P2))',
{ P0: '1/2', P1: '2/3', P2: '3/4' }
))
//->Fraction { num: 6, den: 7 }