我已经嵌入了用于求解块中方程组的计算步骤。然后,我使用一个定义为Block及其输出的函数(见下文)传递该代码块的局部变量值。这一切都很好,除了当我尝试使用Table为一系列参数值评估此函数时,我得到错误顺序的返回值。
代码如下。我没有包含评估所需的所有功能,因为问题必须在于我定义evaluatefun的方式,对于更高级的Mathematica用户来说可能是显而易见的。但是,如果需要所有功能,我很乐意添加它们。
evalfun[nn_, naa_, qap_, qbp_, outvar_] :=
Block[{n = nn, na = naa, qa = qap, qb = qbp, p = .1, \[Delta] = .9,
out = outvar},
yeffafunMlit[yb_, xba_, Baeff_, Bb_] = NSolve[(u[yeffa, 0, Baeff, qa, p]) == (\[Delta] vam[yeffa, yeff[yb], xba, Baeff, Bb + yeff[yb] - yb, qa, p, n, na]), yeffa][[1]][[1]][[2]];
xbafunMlit[Baeff_, Bb_] = NSolve[u[yeff[0], xba, Bb + yeff[0], qa, p] == \[Delta] vam[yeffafunMlit[0, xba, Baeff, Bb], yeff[0], xba, Baeff, Bb + yeff[0], qa, p, n, na], xba][[1]][[1]][[2]];
Baeffsol = FindArgMax[u[yeffafunMlit[0, xbafunMlit[Baeff, Bb], Baeff, Bb],
Baeff - yeffafunMlit[0, xbafunMlit[Baeff, Bb], Baeff, Bb],
Baeff, qa, p] /. {Bb -> 1}, Baeff][[1]];
Bbsol = FindArgMax[u[yeff[0],
Bb - yeff[0] - na pcfun[n, na] xbafunMlit[Baeffsol, Bb],
Bb + yeff[0], qb, p], Bb][[1]];
Bbsoleff = Bbsol + yeff[0];
xbaMOlit = xbafunMlit[qa/(2 p), Bbsol];
yaeffMOlit = yeffafunMlit[0, xbaMOlit, qa/(2 p), Bbsol];
ybeffMOlit = yeff[0];
(*output desired outvar *)
outvar ]
(*Now evaluate evalfun for a range of values of qa output yaeffMOlit*)
Table[evalfun[21, 13, qi, -.5, yaeffMOlit], {qi,12,16}]
(* I get a return list with values in the wrong order *)