Skip to main content
deleted 2 characters in body; edited tags; edited title
Source Link
rm -rf
  • 89.3k
  • 21
  • 296
  • 478

How Plot[] works in Mathematicadoes Plot work?

I considered the following function:

sin[x_] := Module[{},
  Print["x=", x];
  Sin[x]
  ]

in Mathematica. Next, I tried to plot it using:

Plot[sin[t], {t, 0, 2 Pi}]

Surprisingly, the first three lines of output are:

x=0.000128356
x=t
x=1.28228*10^-7

Can someone explain this behavior? In this case it doesn't cause a problem, but in my "real" case it does.

Summary

acl's answer below offers, at its very beginning a solution to the specific problem. In very-short, the reason that this x=t appears is hidden somewhere in the way Mathematica evaluates the functions. The answers below provide interesting insight into the way it works.

The interested reader should read all the answers and details below, they are invaluable, although might be behind the reach of some of the readers (like, partially, in my case).

How Plot[] works in Mathematica

I considered the following function:

sin[x_] := Module[{},
  Print["x=", x];
  Sin[x]
  ]

in Mathematica. Next, I tried to plot it using:

Plot[sin[t], {t, 0, 2 Pi}]

Surprisingly, the first three lines of output are:

x=0.000128356
x=t
x=1.28228*10^-7

Can someone explain this behavior? In this case it doesn't cause a problem, but in my "real" case it does.

Summary

acl's answer below offers, at its very beginning a solution to the specific problem. In very-short, the reason that this x=t appears is hidden somewhere in the way Mathematica evaluates the functions. The answers below provide interesting insight into the way it works.

The interested reader should read all the answers and details below, they are invaluable, although might be behind the reach of some of the readers (like, partially, in my case).

How does Plot work?

I considered the following function:

sin[x_] := Module[{},
  Print["x=", x];
  Sin[x]
]

in Mathematica. Next, I tried to plot it using:

Plot[sin[t], {t, 0, 2 Pi}]

Surprisingly, the first three lines of output are:

x=0.000128356
x=t
x=1.28228*10^-7

Can someone explain this behavior? In this case it doesn't cause a problem, but in my "real" case it does.

Summary

acl's answer below offers, at its very beginning a solution to the specific problem. In very-short, the reason that this x=t appears is hidden somewhere in the way Mathematica evaluates the functions. The answers below provide interesting insight into the way it works.

The interested reader should read all the answers and details below, they are invaluable, although might be behind the reach of some of the readers (like, partially, in my case).

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Dror
  • 1.9k
  • 17
  • 19

How Plot[] works in Mathematica

I considered the following function:

sin[x_] := Module[{},
  Print["x=", x];
  Sin[x]
  ]

in Mathematica. Next, I tried to plot it using:

Plot[sin[t], {t, 0, 2 Pi}]

Surprisingly, the first three lines of output are:

x=0.000128356
x=t
x=1.28228*10^-7

Can someone explain this behavior? In this case it doesn't cause a problem, but in my "real" case it does.

Summary

acl's answer below offers, at its very beginning a solution to the specific problem. In very-short, the reason that this x=t appears is hidden somewhere in the way Mathematica evaluates the functions. The answers below provide interesting insight into the way it works.

The interested reader should read all the answers and details below, they are invaluable, although might be behind the reach of some of the readers (like, partially, in my case).