gpt4 book ai didi

javascript - mathjs 评估错误 : (intermediate value)(intermediate value)(intermediate value) is not a function

转载 作者:行者123 更新时间:2023-11-30 20:14:56 30 4
gpt4 key购买 nike

如果我运行一段代码:

    obj = {};
obj['number'] = 1;
obj['expressionS'] = 'Sin(0.5 * c1)';
obj['compiledExpressionS'] = null;

let cnr = 'c' + obj.number;
let params = {};
params[cnr] = 2;

var parsedExpressionS = math.parse(obj.expressionS);
obj.compiledExpressionS = parsedExpressionS.compile();
let value = obj.compiledExpressionS.eval(params);

我会得到一个错误(在最后一行抛出):(中间值)(中间值)(中间值)不是函数。这里使用 Mathjs 库(文档:http://mathjs.org/docs/expressions/parsing.html)。我不知道为什么会出现错误。

最佳答案

问题是你没有遵守值(value),

obj.compiledExpressionS = parsedExpressionS.compile(math);

Sin 应该小写

工作 fiddle :http://jsfiddle.net/oxb3sp5o/414/

工作代码

obj = {};
obj['number'] = 1;
obj['expressionS'] = 'sin(0.5 * c1)';
obj['compiledExpressionS'] = null;

let cnr = 'c' + obj.number;
let params = {};
params[cnr] = 2;

var parsedExpressionS = math.parse(obj.expressionS);
obj.compiledExpressionS = parsedExpressionS.compile(math);
let value = obj.compiledExpressionS.eval(params);
console.log(value);

关于javascript - mathjs 评估错误 : (intermediate value)(intermediate value)(intermediate value) is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52018195/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com