在循环中定义参数嗨,
我使用以下代码在我的表中的“响应预测公式”列中定义公式。从代码中可以看出,公式中定义了一个名为“调整”的参数。现在,我必须在公式中定义k个参数,而不是1个参数,例如tuning1,tuning2,... tuningk。有没有办法可以使用for循环来做到这一点?请告诉我。谢谢!!!
Eval(
Substitute(
Expr(
:Response Prediction Formula << set formula(tuning=1,b0=1,b1=1; b0+b1*f11)
:Response Prediction Formula << setFormula( Parameter( {tuning = initialValueTBD,b0 = 0,b1 = 1}, b0+b1*f11 ) ),
),
Expr(initialValueTBD), 1,
Expr(f11), evalexpr(f11)
)
);
Re:在循环中定义参数这样可行!!谢谢大卫!! 
Re:在循环中定义参数下面是一些示例代码,它使用循环来爬行参数的列表表达式,然后将其插入到表达式中以设置公式:
// build a list of tuning parameters
lstInitialTuningValues = {1,1,1,2,2}; // for example, 5 tuning params with these initial values
lstParams = {};
For (i=1,i<=NItems(lstInitialTuningValues),i++,
Eval(Parse(EvalInsert("\[
value = lstInitialTuningValues[i];
InsertInto(lstParams, Expr( tuning^i^=^value^ ) )
]\")));
);
show(lstParams); // verify the tuning params are defined correctly
// add the parameters b0,b1
InsertInto(lstParams,Expr(b0=1));
InsertInto(lstParams,Expr(b1=1));
show(lstParams); // final list of parameters
// set the formula ...
fml = "b0 + b1*f11";
str = Eval(Parse(EvalInsert("\[
:Response Prediction Formula << Set Formula( Parameter( ^lstParams^ , ^fml^ ) )
]\")));
这是结果:
