Skip to content

Commit

Permalink
convert ln to log for matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Jul 15, 2024
1 parent 7cb5e5c commit 1c8400a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/matlab-export/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Expression.prototype.toMatlabString = function(substituteByDefinitions = true) {
if (node.type==='FunctionNode' && node.fn.name==='log2') {
return `(log(${node.args[0].toString(options)})/log(2))`;
}
if (node.type==='FunctionNode' && node.fn.name==='ln') {
return `log(${node.args[0].toString(options)})`;
}
if (node.type==='SymbolNode' && node.name === 't') {
return 'time';
}
Expand Down
4 changes: 4 additions & 0 deletions test/core/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ describe('Expession exports', () => {
let expr = Expression.fromString('exp(-kel*t)');
expect(expr.toMatlabString()).to.be.equal('exp(-kel * time)');
});
it('toMatlabString() for "ln(x)"', () => {
let expr = Expression.fromString('ln(x)');
expect(expr.toMatlabString()).to.be.equal('log(x)');
});
});

0 comments on commit 1c8400a

Please sign in to comment.