home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1989-11-04 | 35.0 KB | 834 lines | [ TEXT/OMEG]
(*^ ::[paletteColors = 128; fontset = title, "New York", 18, L2, center, bold, R34351, G1374, B1374, nohscroll; fontset = subtitle, "New York", 14, L2, center, bold, R34351, G1374, B1374, nohscroll; fontset = subsubtitle, "New York", 12, L2, center, bold, R34351, G1374, B1374, nohscroll; fontset = section, "New York", 14, L2, bold, R34351, G1374, B1374, nohscroll, grayBox; fontset = subsection, "New York", 12, L2, bold, R34351, G1374, B1374, nohscroll, blackBox; fontset = subsubsection, "New York", 10, L2, bold, R34351, G1374, B1374, nohscroll, whiteBox; fontset = text, "New York", 10, L2, nohscroll; fontset = smalltext, "New York", 10, L2, nohscroll; fontset = input, "Courier", 12, L2, bold, R3627, G4302, B30180, nowordwrap; fontset = output, "Courier", 12, L2, R3627, G4302, B30180, nowordwrap; fontset = message, "Courier", 12, L2, R65535, nowordwrap; fontset = print, "Courier", 12, L2, nowordwrap; fontset = info, "Courier", 12, L2, nowordwrap; fontset = postscript, "Courier", 12, L2, nowordwrap; fontset = name, "Geneva", 10, L2, italic, B65535, nohscroll; fontset = header, "New York", 10, L2, nohscroll; fontset = footer, "New York", 12, L2, center, nohscroll; fontset = help, "Geneva", 10, L2, nohscroll; fontset = clipboard, "New York", 12, L2; fontset = completions, "New York", 12, L2; fontset = network, "Courier", 10, L2, nowordwrap; fontset = graphlabel, "Courier", 12, L2; fontset = special1, "New York", 12, L2; fontset = special2, "New York", 12, L2, center; fontset = special3, "New York", 12, L2, right; fontset = special4, "New York", 12, L2; fontset = special5, "New York", 12, L2;] :[font = title; inactive; startGroup; ] A Sampling of Mathematica® ;[s] 4:0,0;14,1;25,2;26,0;28,-1; 3:2,23,17,New York,1,18,34351,1374,1374;1,23,17,New York,3,18,34351,1374,1374;1,12,10,New York,0,9,34351,1374,1374; :[font = text; inactive; ] This file is a Mathematica Notebook that gives some examples of what Mathematica can do. For information on how to read this Notebook, see the file Read This First! This file is loosely based on Chapter 0 of The Mathematica Book: "Mathematica: A System for Doing Mathematics by Computer", by Stephen Wolfram. This book was published by Addison-Wesley in 1988, and is available at most bookstores. For information on how to obtain copies of Mathematica itself, see the section "Buying Mathematica" in the file Read This First! ;[s] 17:0,0;20,1;31,0;74,1;85,0;155,2;172,0;224,1;235,0;243,1;254,0;454,1;465,0;499,1;510,0;524,2;540,0;541,-1; 3:9,14,10,New York,0,10,0,0,0;6,14,10,New York,2,10,0,0,0;2,14,10,New York,1,10,0,0,0; :[font = section; inactive; startGroup; Cclosed; ] Numerical Calculations :[font = text; inactive; ] You can use Mathematica as an enhanced scientific calculator. Let's start with a simple example. ;[s] 5:0,0;12,1;23,0;81,2;82,0;99,-1; 3:3,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0;1,14,10,New York,0,10,65535,0,65535; :[font = input; startGroup; ] 45 + 78 :[font = output; inactive; output; endGroup; ] 123 ;[o] 123 :[font = text; inactive; ] The first line here is what you type into Mathematica. The second line is the result Mathematica gives. If you are reading this Notebook on a color system, the input and output are blue, with the input in boldface. ;[s] 5:0,0;42,1;53,0;86,1;97,0;218,-1; 2:3,14,10,New York,0,10,0,0,0;2,14,10,New York,2,10,0,0,0; :[font = text; inactive; ] Now let's try something more difficult. :[font = input; startGroup; ] 3^100 :[font = output; inactive; output; endGroup; ] 515377520732011331036461129765621272702107522001 ;[o] 515377520732011331036461129765621272702107522001 :[font = text; inactive; ] Unlike a calculator, Mathematica gives an exact answer for 3 raised to the power 100. ;[s] 3:0,0;21,1;32,0;87,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = text; inactive; ] Now let's really test out Mathematica. Here is 3 raised to the power 1000. ;[s] 3:0,0;26,1;37,0;76,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] 3^1000 :[font = output; inactive; output; endGroup; ] 13220708194808066368904552597521443659654220327521481676649\ 2036822682859734670489954077831385060806196390977769687258\ 2355950954582100618911865342725257953674027620225198320803\ 8780147742289648412743904001175886180411289478156230944380\ 6156617305408667449050617812548034440554705439703889581746\ 5368254916136220830268563778582290228416398307887896918556\ 4040848989376093732421718463599386955167650189405881090604\ 2608967143886410281435038564874716583201061436613217310276\ 8902855220001 ;[o] 13220708194808066368904552597521443659654220327521481676649\ 2036822682859734670489954077831385060806196390977769687258\ 2355950954582100618911865342725257953674027620225198320803\ 8780147742289648412743904001175886180411289478156230944380\ 6156617305408667449050617812548034440554705439703889581746\ 5368254916136220830268563778582290228416398307887896918556\ 4040848989376093732421718463599386955167650189405881090604\ 2608967143886410281435038564874716583201061436613217310276\ 8902855220001 :[font = text; inactive; ] This took about half a second on a Macintosh II. :[font = text; inactive; ] Here's the result in the form you might get on a calculator. :[font = input; startGroup; ] N[%] :[font = output; inactive; output; endGroup; ] "1.32207"*10^"477" ;[o] 477 1.32207 10 :[font = text; inactive; ] Here is the value of pi to two hundred decimal places. :[font = input; startGroup; ] N[Pi, 200] :[font = output; inactive; output; endGroup; ] 3.141592653589793238462643383279502884197169399375105820974\ 9445923078164062862089986280348253421170679821480865132823\ 0664709384460955058223172535940812848111745028410270193852\ 1105559644622948954930382 ;[o] 3.141592653589793238462643383279502884197169399375105820974\ 9445923078164062862089986280348253421170679821480865132823\ 0664709384460955058223172535940812848111745028410270193852\ 1105559644622948954930382 :[font = text; inactive; ] Mathematica knows about a big collection of mathematical functions — most of those you would find in any book of mathematical tables. ;[s] 2:0,1;11,0;135,-1; 2:1,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] BesselJ[5, 34.6] :[font = output; inactive; output; endGroup; ] 0.0511826 ;[o] 0.0511826 :[font = input; startGroup; ] Log[4.5 + 2I] :[font = output; inactive; output; endGroup; ] 1.59421 + 0.418224*I ;[o] 1.59421 + 0.418224 I :[font = input; startGroup; ] Zeta[1/2 + 14.3 I] :[font = output; inactive; output; endGroup; endGroup; ] -0.0119878 + 0.132231*I ;[o] -0.0119878 + 0.132231 I :[font = section; inactive; startGroup; Cclosed; ] Algebraic Calculations :[font = text; inactive; ] One of the most important features of Mathematica is its ability to deal with mathematical formulas in algebraic form. ;[s] 3:0,0;38,1;49,0;120,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] (1 + x)^3 :[font = output; inactive; output; endGroup; ] (1 + x)^3 ;[o] 3 (1 + x) :[font = text; inactive; ] This is what Mathematica does if you type in a simple algebraic expression. You can expand out the expression like this: ;[s] 3:0,0;13,1;24,0;121,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] Expand[%] :[font = output; inactive; output; endGroup; ] 1 + 3*x + 3*x^2 + x^3 ;[o] 2 3 1 + 3 x + 3 x + x :[font = text; inactive; ] Mathematica gives an explicit formula for the result. You can factor this result to get back to what you started from. % always stands for the last result that Mathematica gave you. ;[s] 6:0,1;11,0;119,2;120,0;160,1;171,0;182,-1; 3:3,14,10,New York,0,10,0,0,0;2,14,10,New York,2,10,0,0,0;1,13,9,Courier,0,10,0,0,0; :[font = input; startGroup; ] Factor[%] :[font = output; inactive; output; endGroup; ] (1 + x)^3 ;[o] 3 (1 + x) :[font = text; inactive; ] Now let's try a more complicated example. :[font = input; startGroup; ] (1 + 2x + 5y)^7 :[font = output; inactive; output; endGroup; ] (1 + 2*x + 5*y)^7 ;[o] 7 (1 + 2 x + 5 y) :[font = input; startGroup; ] Expand[%] :[font = output; inactive; output; endGroup; ] 1 + 14*x + 84*x^2 + 280*x^3 + 560*x^4 + 672*x^5 + 448*x^6 + 128*x^7 + 35*y + 420*x*y + 2100*x^2*y + 5600*x^3*y + 8400*x^4*y + 6720*x^5*y + 2240*x^6*y + 525*y^2 + 5250*x*y^2 + 21000*x^2*y^2 + 42000*x^3*y^2 + 42000*x^4*y^2 + 16800*x^5*y^2 + 4375*y^3 + 35000*x*y^3 + 105000*x^2*y^3 + 140000*x^3*y^3 + 70000*x^4*y^3 + 21875*y^4 + 131250*x*y^4 + 262500*x^2*y^4 + 175000*x^3*y^4 + 65625*y^5 + 262500*x*y^5 + 262500*x^2*y^5 + 109375*y^6 + 218750*x*y^6 + 78125*y^7 ;[o] 2 3 4 5 6 1 + 14 x + 84 x + 280 x + 560 x + 672 x + 448 x + 7 2 3 128 x + 35 y + 420 x y + 2100 x y + 5600 x y + 4 5 6 2 2 8400 x y + 6720 x y + 2240 x y + 525 y + 5250 x y + 2 2 3 2 4 2 5 2 21000 x y + 42000 x y + 42000 x y + 16800 x y + 3 3 2 3 3 3 4375 y + 35000 x y + 105000 x y + 140000 x y + 4 3 4 4 2 4 70000 x y + 21875 y + 131250 x y + 262500 x y + 3 4 5 5 2 5 175000 x y + 65625 y + 262500 x y + 262500 x y + 6 6 7 109375 y + 218750 x y + 78125 y :[font = input; startGroup; ] Factor[%] :[font = output; inactive; output; endGroup; ] (1 + 2*x + 5*y)^7 ;[o] 7 (1 + 2 x + 5 y) :[font = subsection; inactive; startGroup; Cclosed; ] Calculus :[font = text; inactive; ] You can use Mathematica to do calculus. Here's a simple integral. ;[s] 3:0,0;12,1;23,0;66,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] Integrate[x^n, x] :[font = output; inactive; output; endGroup; ] x^(1 + n)/(1 + n) ;[o] 1 + n x ------ 1 + n :[font = text; inactive; ] Here's a more complicated example. :[font = input; startGroup; ] Integrate[x/(x^3-1), x] :[font = output; inactive; output; endGroup; ] (3^(1/2)*ArcTan[(1 + 2*x)/3^(1/2)])/3 + Log[1 - x]/3 - Log[1 + x + x^2]/6 ;[o] 1 + 2 x Sqrt[3] ArcTan[-------] 2 Sqrt[3] Log[1 - x] Log[1 + x + x ] ----------------------- + ---------- - --------------- 3 3 6 :[font = text; inactive; ] Now let's try differentiating again. :[font = input; startGroup; ] D[%, x] :[font = output; inactive; output; endGroup; ] -1/(3*(1 - x)) + 2/(3*(1 + (1 + 2*x)^2/3)) - (1 + 2*x)/(6*(1 + x + x^2)) ;[o] -1 2 1 + 2 x --------- + ------------------ - -------------- 3 (1 - x) 2 2 (1 + 2 x) 6 (1 + x + x ) 3 (1 + ----------) 3 :[font = text; inactive; ] This gives the expression in a different algebraic form. We can get back our original form using Simplify. ;[s] 3:0,0;97,1;105,0;107,-1; 2:2,14,10,New York,0,10,0,0,0;1,13,9,Courier,1,10,0,0,0; :[font = input; startGroup; ] Simplify[%] :[font = output; inactive; output; endGroup; endGroup; ] x/(-1 + x^3) ;[o] x ------- 3 -1 + x :[font = subsection; inactive; startGroup; Cclosed; ] Solving Equations :[font = text; inactive; ] This is how you solve a quadratic equation in Mathematica. ;[s] 3:0,0;46,1;57,0;59,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] Solve[x^2 + 2 a x + 1 == 0, x] :[font = output; inactive; output; endGroup; ] {{x -> (-2*a + (-4 + 4*a^2)^(1/2))/2}, {x -> (-2*a - (-4 + 4*a^2)^(1/2))/2}} ;[o] 2 -2 a + Sqrt[-4 + 4 a ] {{x -> ----------------------}, 2 2 -2 a - Sqrt[-4 + 4 a ] {x -> ----------------------}} 2 :[font = text; inactive; ] Here's a more complicated example. :[font = input; startGroup; ] Solve[x^5 + 3x + 1 == 0, x] :[font = output; inactive; output; endGroup; ] {ToRules[Roots[3*x + x^5 == -1, x]]} ;[o] 5 {ToRules[Roots[3 x + x == -1, x]]} :[font = text; inactive; ] It is a fact of mathematics that there is no way to get an exact formula for the solutions of a quintic equation like this. You can nevertheless ask Mathematica to give you numerical results. You get the five complex number roots to the equation. ;[s] 3:0,0;150,1;161,0;249,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] N[%] :[font = output; inactive; output; endGroup; endGroup; endGroup; ] {{x -> -0.839072 - 0.943852*I}, {x -> -0.839072 + 0.943852*I}, {x -> -0.331989}, {x -> 1.00507 - 0.937259*I}, {x -> 1.00507 + 0.937259*I}} ;[o] {{x -> -0.839072 - 0.943852 I}, {x -> -0.839072 + 0.943852 I}, {x -> -0.331989}, {x -> 1.00507 - 0.937259 I}, {x -> 1.00507 + 0.937259 I}} :[font = section; inactive; startGroup; Cclosed; ] Graphics :[font = input; startGroup; ] Plot[Sin[x], {x, 0, 2Pi}] :[font = postscript; inactive; PICT; pictureID = 7529; output; endGroup; pictureLeft = 61; pictureWidth = 282; pictureHeight = 174; preserveAspect; ] :[font = text; inactive; ] Here is a simple Mathematica plot. ;[s] 3:0,0;17,1;28,0;36,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = text; inactive; ] Now for some three-dimensional graphics. :[font = input; startGroup; ] Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}] :[font = postscript; inactive; PICT; pictureID = 5819; output; endGroup; pictureLeft = 61; pictureWidth = 282; pictureHeight = 282; preserveAspect; ] :[font = text; inactive; endGroup; ] Mathematica generates all graphics in PostScript, so that you can resize pictures, and make use of the resolution available on different types of printers. (Note, however, that to save disk space the graphics in this Notebook have been converted into bitmap images, which have lower resolution and do not look as good when resized or printed. The ability to convert images into bitmap form is useful when space is at a premium, and for animations, which are normally not printed.) ;[s] 2:0,1;11,0;482,-1; 2:1,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = section; inactive; startGroup; Cclosed; ] Animated Graphics :[font = text; inactive; ] You can use sequences of graphics cells in a Notebook as frames in a "movie". To show a movie, you select its sequence of cells (by clicking the bracket that encloses all of them), then type Y. The movie appears in the first graphics cell you have selected. The movie is produced by showing in rapid succession the graphics cells in the selected sequence. A click anywhere inside the window will stop the animation. ;[s] 3:0,0;191,1;193,0;420,-1; 2:2,14,10,New York,0,10,0,0,0;1,17,12,Chicago,0,12,0,0,0; :[font = text; inactive; ] For information on other controls for viewing Mathematica movies, see the Notebook Read This First! ;[s] 5:0,0;46,1;57,0;84,2;100,0;101,-1; 3:3,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0;1,14,10,New York,1,10,0,0,0; :[font = text; inactive; ] This Notebook contains a sample of animation in Mathematica. Due to disk space limitations, this is a very simple two-dimensional example. Look in the "Animations" folder on your disk for other examples of animated graphics. ;[s] 3:0,0;48,1;59,0;227,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = text; inactive; ] What follows is an animation showing how the curve of a Bessel function changes with the order of the Bessel function. (The movie looks best when run fairly slowly, with the frames shown cyclically.) :[font = input; ] <<Needs["Graphics`Animation`"] :[font = input; ] MoviePlot[BesselJ[n, x], {x, 0, 15}, {n, 1, 7, 0.2}, PlotRange->{-0.5, 1.0}] :[font = postscript; inactive; PICT; pictureID = 13084; output; startGroup; Cclosed; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 12426; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 26137; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 12558; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 14240; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 9142; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 22065; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 910; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 19887; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 28709; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 9183; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 20703; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 11535; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 30976; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 9455; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 29084; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 30681; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 31488; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 4847; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 17950; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 18992; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 18147; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 8348; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 24678; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 8016; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 19083; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 15287; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 18030; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 26621; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 1088; output; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = postscript; inactive; PICT; pictureID = 30762; output; endGroup; endGroup; pictureLeft = 76; pictureWidth = 282; pictureHeight = 171; preserveAspect; ] :[font = section; inactive; startGroup; Cclosed; ] Programming in Mathematica ;[s] 3:0,0;15,1;26,0;28,-1; 2:2,19,14,New York,1,14,34351,1374,1374;1,19,14,New York,3,14,34351,1374,1374; :[font = text; inactive; ] You can use Mathematica not only as a "calculator", but also as a full symbolic programming language. Many application packages covering specific areas have been or are being written in the Mathematica language. ;[s] 6:0,1;0,0;12,1;23,0;191,1;202,0;213,-1; 2:3,14,10,New York,0,10,0,0,0;3,14,10,New York,2,10,0,0,0; :[font = subsubsection; inactive; startGroup; Cclosed; ] A Graphics Application Package :[font = input; ] <<Needs["Graphics`Polyhedra`"] :[font = text; inactive; ] This loads in a package that defines properties of polyhedra. The package defines, among other things, the geometry of a dodecahedron. :[font = input; startGroup; ] Dodecahedron[ ] // Short :[font = output; inactive; output; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] {Polygon[<<1>>], <<10>>, Polygon[{<<5>>}]} :[font = text; inactive; ] The Dodecahedron function gives the coordinates for the faces of a dodecahedron, shown here in shortened form. ;[s] 4:0,0;4,2;16,1;17,0;111,-1; 3:2,14,10,New York,0,10,0,0,0;1,13,9,Courier,0,10,0,0,0;1,14,10,New York,1,10,0,0,0; :[font = input; startGroup; ] Show[Graphics3D[ % ]] :[font = postscript; inactive; PICT; pictureID = 2215; output; pictureLeft = 50; pictureWidth = 282; pictureHeight = 277; preserveAspect; ] :[font = output; inactive; output; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = text; inactive; ] This shows the dodecahedron as a three-dimensional graphical object. As another example, we can use the definitions from the polyhedra package to create an image of a stellated icosahedron, which is often used as an icon for the Mathematica system. ;[s] 3:0,0;230,1;241,0;250,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] Show[ Graphics3D[ Stellate[ Icosahedron[ ] ] ] ] :[font = postscript; inactive; PICT; pictureID = 26624; output; pictureLeft = 50; pictureWidth = 282; pictureHeight = 277; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = subsubsection; inactive; startGroup; Cclosed; ] More on Programming :[font = text; inactive; ] There are several styles of programming in Mathematica. One of them is procedural programming, as you would find in a standard structured programming language such as C or Pascal. Another is "rule-based programming". The idea is to give transformation rules which specify how Mathematica should transform expressions it receives as input. You can give rules that mimic the formulas you might find in a mathematics textbook. Here is an example of how you might teach Mathematica about a new form of logarithm function, called nlog. ;[s] 9:0,0;43,1;54,0;279,1;290,0;472,1;483,0;531,2;535,0;537,-1; 3:5,14,10,New York,0,10,0,0,0;3,14,10,New York,2,10,0,0,0;1,13,9,Courier,0,10,0,0,0; :[font = input; startGroup; ] nlog[a b c d^2] :[font = output; inactive; output; endGroup; ] nlog[a*b*c*d^2] ;[o] 2 nlog[a b c d ] :[font = text; inactive; ] Mathematica initially knows nothing about our new function, so it does nothing to expressions involving nlogs. ;[s] 2:0,1;11,0;111,-1; 2:1,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; ] nlog[x_ y_] := nlog[x] + nlog[y] :[font = text; inactive; ] This tells Mathematica how to expand out logarithms of products. ;[s] 3:0,0;11,1;22,0;65,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] nlog[a b c d^2] :[font = output; inactive; output; endGroup; ] nlog[a] + nlog[b] + nlog[c] + nlog[d^2] ;[o] 2 nlog[a] + nlog[b] + nlog[c] + nlog[d ] :[font = text; inactive; ] Now Mathematica can expand the nlog out. ;[s] 5:0,0;4,1;15,0;31,2;35,0;42,-1; 3:3,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0;1,13,9,Courier,0,10,0,0,0; :[font = input; ] nlog[x_^n_] := n nlog[x] :[font = text; inactive; ] This gives a rule for nlog of a power. ;[s] 3:0,0;22,1;26,0;39,-1; 2:2,14,10,New York,0,10,0,0,0;1,13,9,Courier,0,10,0,0,0; :[font = input; startGroup; ] nlog[a b c d^2] :[font = output; inactive; output; endGroup; ] nlog[a] + nlog[b] + nlog[c] + 2*nlog[d] ;[o] nlog[a] + nlog[b] + nlog[c] + 2 nlog[d] :[font = text; inactive; endGroup; endGroup; ] Now Mathematica can expand the expression out completely. ;[s] 3:0,0;4,1;15,0;58,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = section; inactive; startGroup; Cclosed; ] Mathematica's User Interface ;[s] 2:0,1;11,0;29,-1; 2:1,19,14,New York,1,14,34351,1374,1374;1,19,14,New York,3,14,34351,1374,1374; :[font = text; inactive; ] Mathematica consists of two parts — the "Kernel", which actually does computations, and the "Front End", which deals with interaction with the user. The Kernel of Mathematica is essentially the same on all computers that support Mathematica. The Front End, on the other hand, works differently on different kinds of computer. On the Macintosh, Mathematica has a sophisticated Front End that takes advantage of the Macintosh's unique user interface capabilities. (You can actually use the Macintosh Front End even if you are using a "remote Kernel", say on a supercomputer connected through a network.) ;[s] 8:0,1;11,0;164,1;175,0;230,1;241,0;348,1;359,0;607,-1; 2:4,14,10,New York,0,10,0,0,0;4,14,10,New York,2,10,0,0,0; :[font = subsubsection; inactive; startGroup; ] Notebooks :[font = text; inactive; ] One of the most important aspects of the Macintosh Front End is its ability to support Mathematica "Notebooks". This file is an example of a Notebook. Notebooks consist of a mixture of text, graphics, and Mathematica input. Notebooks can be used like "interactive textbooks" — you read the text in the Notebook, then use the Mathematica input in the Notebook to perform calculations. ;[s] 7:0,0;87,1;98,0;209,1;220,0;330,1;341,0;389,-1; 2:4,14,10,New York,0,10,0,0,0;3,14,10,New York,2,10,0,0,0; :[font = text; inactive; ] Here is a sample Mathematica Notebook called Point Plots and Space Curves. ;[s] 5:0,0;17,1;28,0;45,2;73,0;77,-1; 3:3,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0;1,14,10,New York,1,10,0,0,0; :[font = title; inactive; startGroup; ] Point Plots and Space Curves by Theodore W. Gray ;[s] 4:0,1;28,0;29,2;48,0;49,-1; 3:2,23,17,New York,1,18,34351,1374,1374;1,19,14,New York,1,14,34351,1374,1374;1,17,12,New York,2,12,34351,1374,1374; :[font = text; inactive; ] This Notebook defines the functions PointPlot, PointPlot3D, PointParamPlot3D, SpaceCurve, and PointSpaceCurve. These functions let you make discrete point plots in two and three dimensions. The SpaceCurve and PointSpaceCurve functions let you make three-dimensional functions of one parameter (lines or points in 3D). ;[s] 11:0,0;41,1;50,0;52,1;63,0;65,1;81,0;83,1;93,0;99,1;114,0;325,-1; 2:6,14,10,New York,0,10,0,0,0;5,14,10,New York,1,10,0,0,0; :[font = section; inactive; startGroup; Cclosed; ] Examples :[font = text; inactive; ] Each of the functions defined in this Notebook is a variation of either Plot, Plot3D, or ParametricPlot3D. The arguments are quite similar to these standard functions. Following are descriptions of each of the functions. ;[s] 7:0,0;77,1;81,0;83,1;89,0;94,1;110,0;228,-1; 2:4,14,10,New York,0,10,0,0,0;3,14,10,New York,1,10,0,0,0; :[font = subsection; inactive; startGroup; Cclosed; ] PointPlot :[font = text; inactive; ] PointPlot[ f, {x, min, max, (step)}] produces a plot of f(x) vs. x. Here is an example: ;[s] 3:0,0;66,1;69,0;94,-1; 2:2,14,10,New York,0,10,0,0,0;1,14,10,New York,2,10,0,0,0; :[font = input; startGroup; ] PointPlot[Sin[x], {x, 0, 2 Pi, 0.2}] :[font = postscript; inactive; PICT; pictureID = 20909; output; pictureLeft = 67; pictureWidth = 243; pictureHeight = 147; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics- :[font = subsection; inactive; startGroup; Cclosed; ] PointPlot3D :[font = text; inactive; ] PointPlot3D[ f, {x, min, max, (step)}, {y, min, max, (step)}] produces a plot of f(x, y), plotted with points instead of surfaces. :[font = input; startGroup; ] PointPlot3D[x y, {x, -4, 4, 0.5}, {y, -4, 4, 0.5}, BoxRatios->{1,1,1}] :[font = postscript; inactive; PICT; pictureID = 12547; output; pictureLeft = 107; pictureWidth = 202; pictureHeight = 198; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = subsection; inactive; startGroup; Cclosed; ] PointParamPlot3D :[font = text; inactive; ] PointParamPlot3D[{x,y,z}, {u, min, max, (step)}, {v, min, max, (step)}] produces a parametric plot of (x(u,v), y(u,v), z(u,v)), plotted with points instead of surfaces. :[font = input; startGroup; ] PointParamPlot3D[{Sin[u] Cos[v], Sin[u] Sin[v], Cos[u]}, {u, 0, Pi, Pi/15}, {v, 0, 2 Pi, Pi/15}, BoxRatios->{1,1,1}] :[font = postscript; inactive; PICT; pictureID = 23646; output; pictureLeft = 113; pictureWidth = 205; pictureHeight = 201; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = subsection; inactive; startGroup; Cclosed; ] SpaceCurve :[font = text; inactive; ] SpaceCurve[{x,y,z}, {u, min, max, (step)}] produces a parametric plot of (x(u), y(u), z(u)), with the calculated points connected by straight lines. :[font = input; startGroup; ] SpaceCurve[{u Sin[u], u Cos[u], u}, {u, 0, 15, 0.15}, BoxRatios->{1,1,1}] :[font = postscript; inactive; PICT; pictureID = 32679; output; pictureLeft = 107; pictureWidth = 202; pictureHeight = 198; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = subsection; inactive; startGroup; Cclosed; ] PointSpaceCurve :[font = text; inactive; ] PointSpaceCurve[{x,y,z}, {u, min, max, (step)}] produces a parametric plot of (x(u), y(u), z(u)), with the calculated points shown as dots. :[font = input; startGroup; ] PointSpaceCurve[{u Sin[u], u Cos[u], u^2}, {u, 0, 15, 0.30}, BoxRatios->{1,1,1}] :[font = postscript; inactive; PICT; pictureID = 13244; output; pictureLeft = 114; pictureWidth = 198; pictureHeight = 194; preserveAspect; ] :[font = output; inactive; output; endGroup; endGroup; endGroup; ] The Unformatted text for this cell was not generated. Use options in the Actions Settings dialog box to control when Unformatted text is generated. ;[o] -Graphics3D- :[font = section; inactive; initialization; startGroup; Cclosed; pageBreak; ] Implementation :[font = text; inactive; initialization; startGroup; Cclosed; ] Remove previous definitions for the functions defined in this file: :[font = input; initialization; endGroup; ] *) Remove[PointPlot, PointParamPlot3D, PointPlot3D, SpaceCurve, PointSpaceCurve]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Begin this package: :[font = input; initialization; endGroup; ] *) BeginPackage["PointPlots`"]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define the usage strings for each of the functions: :[font = input; initialization; ] *) PointPlot::usage = "PointPlot[f, {u, u0, u1, (du)}], (options)] \ produces a 2D plot made out of points. \ Options are passed to Show[]"; (* :[font = input; initialization; ] *) PointPlot3D::usage = "PointPlot3D[f, {x, x0, x1, (dx)}, \ {y, y0, y1, (dy)}, (options)] \ produces a 3D plot made out of points. \ Options are passed to Show[]"; (* :[font = input; initialization; ] *) PointParamPlot3D::usage = "PointParamPlot3D[{x, y, z}, {u, u0, u1, (du)}, \ {v, v0, v1, (dv)}, (options)] \ produces a 3D parametric plot made out of points. \ Options are passed to Show[]"; (* :[font = input; initialization; ] *) SpaceCurve::usage = "SpaceCurve[{x, y, z}, {u, u0, u1, (du)}, \ (options)] \ produces a 3D space curve. \ Options are passed to Show[]"; (* :[font = input; initialization; endGroup; ] *) PointSpaceCurve::usage = "PointSpaceCurve[{x, y, z}, \ {u, u0, u1, (du)}, (options)] \ produces a set of points in 3D. \ Options are passed to Show[]"; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Begin the private part of this package: :[font = input; initialization; endGroup; ] *) Begin["`Private`"]; `plotpoints = PlotPoints /. Options[Plot3D]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define PointPlot: :[font = input; initialization; endGroup; ] *) Attributes[PointPlot] = {HoldFirst}; PointPlot[function_, range:{x_,___}, options___] := ListPlot[Table[{x, function}, range], options]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define PointParamPlot3D: :[font = input; initialization; endGroup; ] *) Attributes[PointParamPlot3D] = {HoldFirst}; PointParamPlot3D[fun:{_, _, _}, {u_, u0_, u1_, du_:((u1-u0)/(plotpoints-1))}, {v_, v0_, v1_, dv_:((v1-v0)/(plotpoints-1))}, opts___] := Show[Graphics3D[Table[Point[N[fun]], {u, u0, u1, du}, {v, v0, v1, dv}]], opts]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define PointPlot3D (in terms of PointParamPlot3D): :[font = input; initialization; endGroup; ] *) Attributes[PointPlot3D] = {HoldFirst}; PointPlot3D[fun_, ulim:{u_, ___}, vlim:{v_, ___}, opts___] := PointParamPlot3D[ {u, v, fun}, ulim, vlim, opts]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define SpaceCurve: :[font = input; initialization; endGroup; ] *) Attributes[SpaceCurve] = {HoldFirst}; SpaceCurve[fun:{_, _, _}, {u_, u0_, u1_, du_:((u1-u0)/(plotpoints-1))}, opts___] := Show[Graphics3D[Line[Table[N[fun], {u,u0,u1,du}]]], opts]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] Define PointSpaceCurve: :[font = input; initialization; endGroup; ] *) Attributes[PointSpaceCurve] = {HoldFirst} PointSpaceCurve[fun:{_, _, _}, {u_, u0_, u1_, du_:((u1-u0)/(plotpoints-1))}, opts___] := Show[Graphics3D[Table[Point[N[fun]], {u,u0,u1,du}]], opts]; (* :[font = text; inactive; initialization; startGroup; Cclosed; ] End this package: :[font = input; initialization; endGroup; endGroup; endGroup; endGroup; endGroup; endGroup; ] *) End[]; EndPackage[]; (* ^*)