在循環中定義參數嗨,
我使用以下代碼在我的表中的“響應預測公式”列中定義公式。從代碼中可以看出,公式中定義了一個名為“調整”的參數。現在,我必須在公式中定義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^ ) )
]\")));
這是結果:
