Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a function $F$ that maps the xyz space to a set of reals, more clearly:

$c = F[x,y,z]$

Where $c$,$x$,$y$ and $z$ are reals.

What are the possible ways of visualizing this 3d function in Mathematica? (if possible, please post a how-to-do-it)

share|improve this question
    
I have something that could be interesting. I'll put it up tomorrow. –  rcollyer Feb 14 '13 at 3:09
    
@h3now you could check en.wikipedia.org/wiki/Parallel_coordinates to get some other ideas? –  Lou Feb 14 '13 at 8:29
add comment

2 Answers 2

up vote 18 down vote accepted

One possible way is to use Graphics3D with Point and color points by function value so it's like density plot 3d. For example,

xyz = Flatten[
         Table[{i, j, k}, {i, 1, 10, .35}, {j, 1, 10, .35}, {k, 1, 
          10, .35}], 2];

f[x_, y_, z_] := x^2 y Cos[z]

Graphics3D[
       Point[data, VertexColors -> (Hue /@ Rescale[f[##] & @@@ data])], 
 Axes -> True, AxesLabel -> {x, y, z}]

enter image description here

Another possible choice is just thinking one parameter as time variable and use Manipulate:

Manipulate[Plot3D[f[x, y, z], {x, 1, 10}, {y, 1, 10}], {z, 1, 10}]

enter image description here

There should be many other way to visualize 4d data, but it's really depending on what you want to see and how you want to visualize.

Like amr suggested, you can also use Image3D or Raster3D:

values = Rescale[
    Table[f[i, j, k], {i, 1, 10, .2}, {j, 1, 10, .2}, {k, 1, 10, .2}]];

Graphics3D[Raster3D[values, ColorFunction -> Hue]]

enter image description here

Image3D[values, ColorFunction -> Hue]

enter image description here

Image3D[values]

enter image description here

share|improve this answer
    
I was thinking something like this but with the Image3D functionality from Version 9. Not sure what the difference might be but it may look "smoother." I only have Mathematica 8 at the moment though so I can't test it. –  amr Feb 14 '13 at 2:59
1  
@amr yes, that will be other way. I added examples. –  halmir Feb 14 '13 at 3:27
    
Thank you, great answer. Just so you know I needed this to visualize the error in a 3d position-estimate in the xyz space, so I'll most likely try something like your first example. –  h3now Feb 18 '13 at 14:47
add comment

A typical way of visualizing functions of the form $f(x,y,z)$ is in terms of level sets. One uses ContourPlot3D in Mathematica. Here I show it in conjunction with the function's gradient field, which may be omitted.

Manipulate[
 Show[
   ContourPlot3D[f == c, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
    ContourStyle -> Opacity[0.5]],
   ControlActive[{}, VectorPlot3D[Evaluate[D[f, {{x, y, z}}]], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]]
  ],
 {{f, x^2 + x y z + z^4}, InputField},
 {{c, 0.1}, -0.25, 5, Appearance -> "Labeled"}]

output

You mention in a comment visualizing error. I wasn't sure exactly what you were after, but you can plot contours plus or minus a given error in the value of f fairly easily.

Manipulate[
 Show[
  ContourPlot3D[f, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
   Contours -> c + {-dc, 0, dc}, 
   ContourStyle -> {Directive[Opacity[0.3], Red], Opacity[0.3], 
     Directive[Opacity[0.3], Blue]}, Mesh -> None],
  ControlActive[{}, VectorPlot3D[Evaluate[D[f, {{x, y, z}}]], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]]
  ],
 {{f, x^2 + x y z + z^4}, InputField},
 {{c, 0.6}, -0.25, 5, Appearance -> "Labeled"},
 {{dc, 0.5}, 0, 1., Appearance -> "Labeled"}]

output

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.