使用 Mathematica 7 调试 Mathematica 5 上的工作程序 [英] Debugging a working program on Mathematica 5 with Mathematica 7

查看:28
本文介绍了使用 Mathematica 7 调试 Mathematica 5 上的工作程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读 Mathematica 编程指南,并且我正在尝试制定这本书的第一个程序.基本上,当我运行以下程序时:

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)]]]]]

要么我得到 1/0 错误和 e^infinity 错误,要么如果我将 PlotPoints 选项降低到 60,就会出现溢出错误.虽然我有一个工作输出,但它不是它应该的样子.色调似乎从左角扩散,而它应该从原点扩散(如原始 输出)

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)

这是显然在 Mathematica 5 上运行的原始程序(Trott,Mathematica 编程指南):

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];

然而,ColorFunction 使用这种方式(第一个 Plot3D 参数)不起作用,所以我试图简单地适应它的新使用方式.

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.

好吧,谢谢!

推荐答案

我终于找到了两种替代方法来解决我的问题.第一个是简单地使用 <<Version5`Graphics` 命令以在 Mathematica V5 中使用 Plot3D 函数的方式使用.书中的代码和以前一样工作.

I finally found two alternative ways to solve my problem. The first one is to simply use the << Version5`Graphics` command to use Plot3Dfunction the way it worked with Mathematica V5. The code taken from the book works just like it used to.

但是,如果希望使用最新版本正确显示色调(即,左角没有扩散),则必须使用 Rescale 功能,就像这样:

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:

Plot3D[Evaluate[Re[f[x, y]]], {x, -.02, .022}, {y, -0.04, 0.042},
PlotRange -> {-1, 2}, PlotPoints -> 120, Mesh -> False,
ColorFunction -> Function[{x, y, z}, Hue@Rescale[Arg[f[x, y]], {-π, π}]],
ColorFunctionScaling -> False,
ClippingStyle -> None]

我想 Mathematica 中的参数函数不会自动映射到 [-Pi,Pi) 范围,因此必须重新调整到这个域.结果还是挺好看的,虽然和原图有一些细微的差别.

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.

这篇关于使用 Mathematica 7 调试 Mathematica 5 上的工作程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆