使用 Mathematica 7 调试 Mathematica 5 上的工作程序
我目前正在阅读 Mathematica 编程指南,并试图编写这本书的第一个程序。基本上,当我运行以下程序时:
Plot3D[{Re[Exp[1/(x + I y)]]}, {x, -0.02, 0.022}, {y, -0.04, 0.042},
PlotRange -> {-1, 8}, PlotPoints -> 120, Mesh -> False,
ColorFunction -> Function[{x1, x2, x3}, Hue[Arg[Exp[1/(x1 + I x2)]]]]]
要么收到 1/0 错误和 e^\infinity 错误,要么如果我将 PlotPoints
选项降低到 60,则会出现溢出错误。虽然我有一个工作输出,但它不是它应该的样子。色调似乎从左角扩散,而它应该从原点扩散(如原始 输出)
这是显然在 Mathematica 5 上运行的原始程序(Trott,Mathematica Guidebook)用于编程):
Off[Plot3D::gval];
Plot3D[{Re[Exp[1/(x + I y)]], Hue[Arg[Exp[1/(x + I y)]]]},
{x, -0.02, 0.022}, {y, -0.04, 0.042},
PlotRange -> {-1, 8}, PlotPoints -> 120, Mesh -> False]
Off[Plot3D::gval];
但是,ColorFunction
使用这种方式(第一个 Plot3D
参数)不起作用,因此我尝试简单地适应其新的使用方式。
嗯,谢谢我猜!
I'm currently reading the Mathematica Guidebooks for Programming and I was trying to work out one of the very first program of the book. Basically, when I run the following program:
Plot3D[{Re[Exp[1/(x + I y)]]}, {x, -0.02, 0.022}, {y, -0.04, 0.042},
PlotRange -> {-1, 8}, PlotPoints -> 120, Mesh -> False,
ColorFunction -> Function[{x1, x2, x3}, Hue[Arg[Exp[1/(x1 + I x2)]]]]]
either I get a 1/0 error and e^\infinity error or, if I lower the PlotPoints
options to, say, 60, an overflow error. I have a working output though, but it's not what it's supposed to be. The hue seems to be diffusing off the left corner whereas it should be diffusing of the origin (as can be seen on the original output)
Here is the original program which apparently runs on Mathematica 5 (Trott, Mathematica Guidebook for Programming):
Off[Plot3D::gval];
Plot3D[{Re[Exp[1/(x + I y)]], Hue[Arg[Exp[1/(x + I y)]]]},
{x, -0.02, 0.022}, {y, -0.04, 0.042},
PlotRange -> {-1, 8}, PlotPoints -> 120, Mesh -> False]
Off[Plot3D::gval];
However, ColorFunction
used this way (first Plot3D
argument) doesn't work and so I tried to simply adapt to its new way of using it.
Well, thanks I guess!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对 Mathematica 的默认设置感到满意,您可以使用旧版本的代码,只需删除
, Hue[Arg[Exp[1/(x + I y)]]]
,该函数就可以正常工作。新版本代码遇到的问题似乎源于表达式
Exp[1/(x1 + I x2)]
——有时这需要对1/ 进行评估0 。至少,如果我剪掉
1/
程序(在 Mathematica 7 上)执行时不会有任何抱怨,尽管显然颜色错误。所以你可能需要重写你的颜色函数。If you are satisfied with Mathematica's defaults you can use the old version of the code, simply cut out
, Hue[Arg[Exp[1/(x + I y)]]]
and the function works fine.The problems you are having with the new version of the code seem to stem from the expression
Exp[1/(x1 + I x2)]
-- sometimes this will require the evaluation of1/0
. At least, if I cut out1/
the program executes (on Mathematica 7) without complaint, though obviously with the wrong colours. So you need to rewrite your colour function, probably.我终于找到了两种替代方法来解决我的问题。第一个是简单地使用
<<; Version5`Graphics`
命令以与 Mathematica V5 一起使用的方式使用Plot3D
函数。从书中获取的代码就像以前一样工作。但是,如果希望使用最新版本正确显示色调(即不扩散到左角),则必须使用
Rescale
函数,就像这样:我想参数Mathematica 中的函数不会自动映射到 [-Pi,Pi) 范围,因此必须将其重新缩放到该域。结果还是挺好看的,虽然和原著有一些细微的差别。
I finally found two alternative ways to solve my problem. The first one is to simply use the
<< Version5`Graphics`
command to usePlot3D
function the way it worked with Mathematica V5. The code taken from the book works just like it used to.However, if one wishes to display correctly the hue (that is, without diffusion off the left-hand corner) with the latest version, the
Rescale
function must be used, just like this:I suppose the argument function in Mathematica does not map automatically to the [-Pi,Pi) range and so it must be rescaled to this domain. The result is quite good-looking, although there are some minor differences with the original plot.