在 JSL 中循环导数函数
大家好,JMP 用户社区,我一直在努力解决 JSL 函数的问题,想联系一下大家,看看能否提供帮助。
因此,我希望脚本执行的操作基本上是从多项式回归模型中获取公式表达式,然后针对每个包含的因子构建偏导数。理想情况下,它会创建一个包含表达式公式中包含的所有因子的列表。然后循环遍历该列表,并将一个又一个的因子代入导数函数中,以计算所有偏导数公式并分别保存它们。问题是,我不知道如何创建这样一个循环,并以导数函数可以接受的方式格式化因子名称。我已经尝试了很多方法,但似乎都没有用。我附在 JSL 示例文件中的只有两种能够正确计算偏导数的方法。
有人用过这个函数吗?或者能帮我创建循环中导数函数的正确输入格式吗?非常感谢!
自动化和脚本回复:在 JSL 中循环导数函数你可以将项目评估为衍生品
Names Default To Here(1);
formula_expr = Expr(
48.5137619590147 + -5.01848924914286 * :"Factor 1"n + -6.30434548201033 * :"Factor 2"n
+4.98953779772742 * :"Factor 3"n + 4.94156314686837 * :"Factor 4"n + -8.10632041659685 *
:"Factor 5"n + -15.9138137782692 * :"Factor 1"n * :"Factor 1"n + 5.67284677635098 *
:"Factor 2"n * :"Factor 2"n
);
///// Working example 1
derivative_expr = Derivative(Name Expr(formula_expr), :Name("Factor 1"));
Show(derivative_expr);
///// Working example 2
derivative_expr = Derivative(Name Expr(formula_expr), :"Factor 1"n);
Show(derivative_expr);
//// What the loop should look like (not working)
factorList = {:"Factor 1"n, :"Factor 2"n, :"Factor 3"n, :"Factor 4"n, :"Factor 5"n};
For Each({factor_item}, factorList,
derivative_expr = Eval(EvalExpr(
Derivative(Name Expr(formula_expr), Expr(Name Expr(factor_item)));
));
Show(derivative_expr);
);
回复:在 JSL 中循环导数函数非常感谢 jthi!解决了问题:)我已在我的脚本中成功实现它。
我非常感谢你的帮助