Three-Dimensional Mathematica Graphics (Section 6.2)

Extract from Mathematica Graphics: An Intensive Tutorial

by Tom Wickham-Jones

This HTML document is based on Mathematica Graphics: An Intensive Tutorial by Tom Wickham-Jones. It was adapted by Martin Kraus for non-commercial use.

Mathematica and MathLink are registered trademarks, and MathReader, MathSource and 3-Script are trademarks of Wolfram Research, Inc.

All other product names mentioned are trademarks of their producers.

Copyright 1992 by Wolfram Research, Inc.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder.

Function Plotting

Constructing a new function is very simple.

 In:= weirdf[x_, y_] := If[x^2 + y^2 < 1, x^2 + y^2, Exp[1 - x^2 - y^2]] The function which Plot3D requires must evaluate to a number. Thus our weird function is quite adequate. In:= Plot3D[weirdf[s, t], {s, -2, 2}, {t, -2, 2}] Out= - SurfaceGraphics -

A further possibility is to use Mathematica numerical capabilities. For this the NDSolve function, which numerically solves differential equations, is very suitable.

 NDSolve returns an InterpolatingFunction. Of course we could have solved this problem analytically. In:= NDSolve[{x''[t] == -x[t], x == 2, x' == 0}, x, {t, 0, 20}] Out= {{x -> InterpolatingFunction[{0., 20.}, <>]}} This plots the result. Evaluate is necessary since Plot is HoldAll. In:= ParametricPlot3D[Evaluate[{t, x[t], D[x[t], t]} /. %], {t, 0, 20}] Out= - Graphics3D - This example is more complex. It comprises of two coupled oscillators. In:= NDSolve[{x''[t] == -x[t] - x[t] y[t]^2, y''[t] == -y[t] - x[t] y[t]^2, x == 2, x' == 0, y == 1, y' == 0}, {x, y}, {t, 0, 20}] Out= {{x -> InterpolatingFunction[{{0., 20.}}, <>], y -> InterpolatingFunction[{{0., 20.}}, <>]}} This shows the solution. In:= ParametricPlot3D[Evaluate[{t, x[t], y[t]} /. First[%]], {t, 0, 20}] Out= - Graphics3D -