home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math.symbolic
- Path: sparky!uunet!wupost!psuvax1!atlantis.psu.edu!apix.psu.edu!thor
- From: thor@vivaldi.psu.edu (Thomas Moertel)
- Subject: Re: 3D scatter plots using Mathematica
- In-Reply-To: andrew@uaneuro.uah.ualberta.ca's message of Wed, 29 Jul 1992 23:31:13 GMT
- Message-ID: <THOR.92Jul30010933@haydn.vivaldi.psu.edu>
- Sender: news@atlantis.psu.edu (Usenet)
- Organization: Pennylvania State University
- References: <1992Jul29.233113.24299@kakwa.ucs.ualberta.ca>
- Date: 30 Jul 92 01:09:33
- Lines: 77
-
- > I need to produce 3D surfaces as the solution to various
- > regression analysis and plot those with the original points in 3D, ie the
- > 3D equivalent of a linear regression with both regression line and data
- > points visible. I am using Mathematica 2.0 on the NeXT. Be merciful I'm
- > not a Mathematician.
- >
- > Andrew Penn
-
- What you need to do is create 2 plots, one of the sample points and one
- of the regression surface. Then you can combine them with the Plot[]
- command. Using 2D for example, you could combine plots of sine and cosine
- like this:
-
- plot1 = Plot[Sin[x], {x, 0, Pi}]; (* first plot *)
- plot2 = Plot[Cos[x], {x, 0, Pi}]; (* second plot *)
- Show[plot1, plot2] (* combo plot *)
-
- Here's a more realistic example in 3D. Let's say your regression surface is
- given by
-
- surfaceEq = x^2 + y^2 + z^2 == 16; (* sphere w/radius 4 *)
-
- We can make a plot of this surface and some (fake) data like so:
-
- (* this function calculates the z-value of a point on the suface *)
- (* at the given (x, y) coordinates *)
-
- f[x_, y_] := Evaluate[z /. Flatten[Solve[surfaceEq, z]]]
-
- (* this function randomly generates a "pretend" data point *)
-
- samplePoint[] :=
- Module[{r, phi, x, y},
- r = Random[Real, 4.0];
- phi = Random[Real, N[Pi/2]];
- x = r Cos[phi];
- y = r Sin[phi];
- {x, y, f[x, y] + Random[Real, 0.25]}
- ]
-
- (* let's make a fake set of data *)
-
- data = Table[samplePoint[], {50}];
-
- (* now let's plot the data *)
-
- Needs["Graphics`Graphics3D`"]
-
- pointPlot = ScatterPlot3D[data]
-
- (* let's plot the regression surface *)
-
- surface =
- ParametricPlot3D[
- {
- r Cos[phi],
- r Sin[phi],
- Re[f[r Cos[phi], r Sin[phi]]]
- },
- {r, 0, 4}, {phi, 0, Pi/2.0}
- ]
-
- (* finally, we can combine the plots! *)
-
- Show[surface, pointPlot]
-
- Under less ideal conditions some sample points may be hidden by the
- surface. Therefore, you may want to make several plots from different
- viewpoints so that all the sample points can be seen.
-
- I hope this helps.
-
- --Tom
- --
-
- Tom Moertel Pennsylvania State University
- thor@vivaldi.psu.edu "Them bats is smart. They use radar!" ;-)
-