# Strange spikes in my surface

I'm getting strange spikes in my surface S with the code below. PlotPoints seems to help, but it doesn't solve the problem. Any explanation and solution would be much appreciated.

a := {x, y, 1 - x}
b := {x, y, x}
S := Inner[Times,
Transpose[Inner[Times, {1 - x, x}, {{a /. {x -> 0, y -> 0}, b /. {x -> 0, y -> 1}},
{a /. {x -> 1, y -> 0}, b /. {x -> 1, y -> 1}}}, Plus]], {1 - y, y}, Plus]
ParametricPlot3D[S, {x, 0, 1}, {y, 0, 1}]
ParametricPlot3D[S, {x, 0, 1}, {y, 0, 1}, PlotPoints -> 100]
Expand[S]
ParametricPlot3D[{x, y, 1 - x - y + 2 x y}, {x, 0, 1}, {y, 0, 1}]


EDIT: It seems that y -> is somehow responsible.

• I can't see your spikes with Mma 9.0 WinXP Commented Apr 25, 2013 at 18:24
• I can see them (9.0.1 on Mac) Commented Apr 25, 2013 at 18:26
• Thanks for checking. I'm on Win8 with MMA 9.0.1. I briefely edited out the y -> 0 here because I thought it was redundant for my MWE. Now it's back in. It does matter in full code. Without y -> , I also don't get spikes. Strange.
– u17
Commented Apr 25, 2013 at 18:32
• I can see spikes on Vista (Mathematica 9.0). Conclusions: Expand helps ? A related problem where Expand had helped in version 8.0 : mathematica.stackexchange.com/questions/3568/…. However that bug has been fixed in ver. 9.0. Commented Apr 25, 2013 at 18:38
• @Frank Same here Commented Apr 25, 2013 at 18:41

The reason for the strange behavior is the "strange" definition of S. Compare:

Block[{x, y},
x = 0.6; y = 0.4;
S]
(* {0.6, 0.4, 0.24} *)

S /. {x -> 0.6, y -> 0.4}
(* {0.6, 0.4, 0.48} *)


Plot does something like the first one. What happens is that every x is replaced by 0.6 and every y is replaced by 0.4. So a = {x, 0, 1 - x} becomes {0.6, 0, 0.4}, and the rules {x -> 0, y -> 0} become {0.6 -> 0, 0.4 -> 0}. When applied to a, we get {0, 0, 0} instead of {0, 0 1}.

The following is a possible workaround:

ParametricPlot3D[Evaluate @ S, {x, 0, 1}, {y, 0, 1}]


[Edit: Forgot to put the Evaluate in.]