General::ivar: ... 不是有效变量
我一直试图破译这个输出的含义,但我似乎无法弄清楚。有人知道这是怎么回事吗?
我什至尝试过逐行运行这些行,只有当最后一行(显示)为被执行。
I have been trying to decipher what this output means, but I just can't seem to figure it out. Does anybody know what is going on here?
I have even tried running the lines one by one and the errors only show up when the final line (show) is executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单独单步执行这些行不会告诉您发生了什么,您必须拆开给您带来麻烦的语句:在本例中,
Show[p1, p2[1,1]
。就其本身而言,p1
和Show
都不会给您带来麻烦,因此得出的结论是它一定是p2[1,1]
。这是通过单独运行它而产生的,它会产生相同的错误。由于
Plot
、Plot3D
等如何评估函数参数,这会生成错误。一般来说,它们本质上是对函数文本进行替换,并且可能不会扩展函数调用。一个简单的修复方法是重写p2
来消除错误。
Evaluate
确保在Plot3D
获取函数之前对函数进行符号求值,从而避免任何误处理。我希望我能更好地了解在这些情况下何时使用 Evaluate,但如果一般来说,如果您从此类绘图函数中收到错误,那么很可能是对该函数的处理不当。Stepping through the lines individually by themselves would not show you what is going on, you have to take apart the statement that is giving you the trouble: in this case,
Show[p1, p2[1,1]
. By themselves, neitherp1
norShow
should give you trouble, which leads to the conclusion that it must bep2[1,1]
. This is born out by running that by itself, which generates the same error.This generates an error because of how
Plot
,Plot3D
, etc evaluate the function argument. In general, they essentially do aReplace
on the text of the function and may not expand function calls. A simple fix is to rewritep2
aswhich gets rid of the errors.
Evaluate
ensures that function is evaluated symbolically beforePlot3D
gets a hold of it avoiding any mishandling. I wish I had a better idea of when to useEvaluate
in these cases, but if in general if you are getting errors from a plotting function like these, then it is most likely mishandling the function.