Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Cool example with ContourPlot+EvaluationMonitor
Replies: 9   Last Post: Mar 23, 2012 2:35 AM

 Messages: [ Previous | Next ]
Re: Cool example with ContourPlot+EvaluationMonitor
Posted: Mar 20, 2012 3:25 AM

Hi Ralph,
Well, the thing is that most Mathematica functions are sort of a "black box", ie you supply a set of functions and parameters and it produces a result. In this case you never see the intermediate steps/results, the source code is obviously not available and even if it was, according to the documentation in many cases it's not even human readable (for efficiency reasons).

Therefore, this example illustrates how one of the functions (ContourPlot) operates in real time: first it makes a grid in the 2D space specified by the user, eg {x, -1.5, 1.5} & {y, -1.5, 1.5}, and then it picks values of (x,y) close to the actual contour: my guess is it chooses the ones close to where Abs[x^2+y^2-1]<dr, where dr is a small number say 0.2 (of course this is just a guess). I'm posting some (quick and dirty) code below that illustrates this.

I hope this helps!

Cheers

PS Of course I have to mention that Mathematica also checks the corners of the region etc but that's another story ;)

--- Code ---

(* grab the data from ContourPlot *)
data = {};
ContourPlot[x^2 + y^2 == 1, {x, -1.5, 1.5}, {y, -1.5, 1.5},
EvaluationMonitor :> AppendTo[data, {x, y}]];

(* just take the grid *)
qq = data[[1 ;; 15*15]];

(* evaluate Abs[x^2+y^2-1] and take the ones <0.2, then plot *)
qq1 = Table[{Abs[qq[[i, 1]]^2 + qq[[i, 2]]^2 - 1], qq[[i, 1]],
qq[[i, 2]]}, {i, 1, Length[qq]}] // Sort;
qq1 = qq1[[1 ;; 32]][[All, {2, 3}]];
ListPlot[{qq, qq1}, PlotStyle -> {Blue, Red}, AspectRatio -> 1]

Date Subject Author
3/18/12 Murta
3/19/12 Ralph Dratman
3/20/12 David Kahle
3/20/12 Kevin J. McCann
3/23/12 David Park