Mathematica 9 中语句不显示错误,不运行结果?For[n = 1,n {"x/a","\!\(\*FractionBox[\(a\),\(2\)]\)|\[Psi]\!\(\*SuperscriptBox[\(|\\),\(2\)]\)"},PlotLabel -> "n=4",AspectRatio -> 1/3]]

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/04 10:47:01
Mathematica 9 中语句不显示错误,不运行结果?For[n = 1,n { "n=4",AspectRatio -> 1/3]]" />
xS]OA+[m>}ƅl&l%!Q55UTTj1"1M"ȟ]Egv4M֗3޹3cZd%C KcZUVEchmܕ]ntyVigMrLFu^ƹar D@pO'u)l(Qi4 0a@~* 6d=`EԷ"Q#P}`"ac4Á8Kͽt*)( J8W|vRᙽMF\WTZ~igQ㢉2) IjG"~nc'N& 0qq%*B2n8W(C˄֩}fZ{ݡRJNwNmt H\ѧbPߜ1¾1JaSY s3d),*zʨtZYZUh*eKj7,D\އQ Gldx 4vRJ9$|}@GZ-T_{]Gvis <(*)`B|=< /K^@w"!y E|)֫ĭ *F`%\yxvEoFm;;0'gKJ]ђH܂ ߜ䩽ZQ`=N 4Iu{

Mathematica 9 中语句不显示错误,不运行结果?For[n = 1,n {"x/a","\!\(\*FractionBox[\(a\),\(2\)]\)|\[Psi]\!\(\*SuperscriptBox[\(|\\),\(2\)]\)"},PlotLabel -> "n=4",AspectRatio -> 1/3]]
Mathematica 9 中语句不显示错误,不运行结果?
For[n = 1,n {"x/a",
"\!\(\*FractionBox[\(a\),\(2\)]\)|\[Psi]\!\(\*SuperscriptBox[\(|\
\),\(2\)]\)"},PlotLabel -> "n=4",AspectRatio -> 1/3]]

Mathematica 9 中语句不显示错误,不运行结果?For[n = 1,n {"x/a","\!\(\*FractionBox[\(a\),\(2\)]\)|\[Psi]\!\(\*SuperscriptBox[\(|\\),\(2\)]\)"},PlotLabel -> "n=4",AspectRatio -> 1/3]]

原因是,除非使用明确的 Return,否则由 For 返回的最后的值是Null.所以,在循环完之后,没有返回值作为Out输出.一个简单的方法是,在Plot函数外套一个Print函数.

另外程序中PlotLabel -> "n=4"要改成PlotLabel -> StringForm["n=``", n],否则n不能传递到字符串中.

但是,这不是Mathematica的做事风格.Mathematica的风格是函数式编程,而不是过程式编程,因此,将上述代码变成

Table[Plot[Sin[n*\[Pi]*x]^2, {x, 0, 1}, 
  AxesLabel -> {"x/a", 
    "\!\(\*FractionBox[\(a\), \
\(2\)]\)|\[Psi]\!\(\*SuperscriptBox[\(|\), \(2\)]\)"}, 
  PlotLabel -> StringForm["n=``", n], AspectRatio -> 1/3], {n, 1, 5}]

更自然一些