Mathematica∗ Tutorial For Math 243 Rakesh† Department of Mathematical Sciences University of Delaware May 6, 2014

Contents 1 Basic Functions

3

1.1

Differentiation, Integration, Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.2

Saving, Destroying or Starting a Notebook . . . . . . . . . . . . . . . . . . . . . . . .

4

1.3

Substitution, Numerical Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

1.4

Getting Help, Interrupting Mathematica . . . . . . . . . . . . . . . . . . . . . . . . .

5

1.5

Plotting Planar Curves Given Explicitly or Implicitly . . . . . . . . . . . . . . . . . .

6

1.6

Factor, Expand, Postfix Application of a Function . . . . . . . . . . . . . . . . . . .

8

1.7

Lists, Parts of lists and expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

1.8

Brackets, Names of built-in objects . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

1.9

Solving a System of Equations I - Solve, NSolve . . . . . . . . . . . . . . . . . . . . . 10

1.10 Solving a System of Equations II - FindRoot . . . . . . . . . . . . . . . . . . . . . . 11 1.11 Time Saving Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.12 Some Common Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.13 Summary of Section 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.14 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 ∗ †

Version 9 Please send suggestions and corrections to [email protected]

1

2 Preparing a Mathematica Report

16

3 Advanced Functions

17

3.1

Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.2

Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.3

Conditional Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.4

Finite Sequences and Series, Taylor Polynomials . . . . . . . . . . . . . . . . . . . . 21

3.5

Plotting Planar Parametric Curves or Curves in Polar Coordinates . . . . . . . . . . 21

3.6

Summary of Sections 1 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4 Vectors Operations and Multidimensional Integrals

24

4.1

Vector Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.2

Operations on Vector Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.3

Multidimensional Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.4

Jacobian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5 Plotting Curves and Surfaces

26

5.1

Plotting Three Dimensional Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.2

Plotting Three Dimensional Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5.3

Superimposing Pictures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.4

Plotting Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.5

Summary of Section 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Acknowledgement: This tutorial is based partly on a Maple tutorial by the author and partly on the single variable and multi-variable versions of CalcLabs Mathematica by Selwyn Hollis.

2

1

Basic Functions

1.1

Differentiation, Integration, Editing

Start Mathematica and in the new window choose Create New Notebook. A new window/Notebook titled Untitled opens with a + and a line. Click this window and we are ready to execute Mathematica commands in this notebook. To differentiate sin(x2 ) type D[Sin[x^2], x]

hit Shift Return

To compute definite and indefinite integrals use Integrate[Sin[x], {x,0,Pi}] Integrate[ Log[a*x^2], x]

Shift Return Shift Return

Note that Pi (upper case P) is the symbol used for π in Mathematica. The first command computes the definite integral over the interval [0, π] and the second command computes the indefinite integral. In the second integral, we could have integrated with respect to a instead of x. Also note that Mathematica uses Log for the Natural Logarithm function and not Ln. The ←, →, ↑, ↓ keys may be used to navigate in the notebook and the Backspace, Delete keys may be used to correct typing errors. So if we wish to differentiate x sin(x3 ) instead of sin(x2 ), we can modify our notebook as follows - using the ← ↑ → ↓, keys move the cursor to the line which computes the derivative of sin(x2 ) and using the Backspace, Delete, and arrow keys modify that line to read D[x*Sin[x^3], x]

Shift Return

Now move the cursor down until you see a line at end of the notebook. Sometimes it is desirable to execute several commands together. Consider f = Sqrt[1+x] + 3*Exp[5*x] - (x+7)*Log[1+x] Enter D[f, {x,3}] (third derivative) Shift Enter The Enter just starts a new line and does not execute the command; the Shift both √Enter executes 5x commands. The first line assigns a name f to the complicated expression 1 + x + 3e − (x + 7) ln(1 + x) and the second line computes the third derivative of this expression. Also note the use of the square root function and the exponential function - one can also use E^x for the exponential function. The letter E is reserved for the constant e = Exp[1].

3

1.2

Saving, Destroying or Starting a Notebook

To save the current notebook (perhaps for future use), from the File menu choose Save and choose a name for the file and a location to save it. To start a new notebook, from the File menu choose New Notebook and to destroy a notebook, choose Quit from the file menu.

1.3

Substitution, Numerical Value

Open a new Mathematica notebook if you do not have one open. Suppose we wish to substitute the values a = 3 and b = 5 into the expression a3 + b2 . This may be accomplished with the command (below -> is generated by using the - and > keys) a^3 + b^2 /. { a->3, b->5}

Shift Enter

Here {a->3, b->5} is called a rule which says a becomes 3 and b becomes 5. The /. means apply the rule given after /. to the result of computing whatever comes before /. . For example, we compute the third order x derivative of x2 sin(kx3 ) at x = 1, k = 3, accurate to 7 digits. Try f = (x^2)*Sin[k*x^3] fxxx = D[f, {x,3}] compute third order derivative fxxxval = fxxx /. {x ->1, k->3} evaluate third derivative at x=1, k=3 If one wants the numerical value of the third derivative then one can take advantage of the fact that when Mathematica sees decimal inputs Mathematica returns decimal outputs so instead of using {x ->1, k->3} we use {x ->1, k->3.0}, that is fxxxval = fxxx /. {x ->1, k->3.0}

evaluate third derivative at x=1, k=3

Another way is to use the operator N which when applied to any expression gives the numerical value of that object. So one could use N[fxxxval] or equivalently fxxxval // N The last line introduces the command // which applies the function(operator) after // to the result of executing the expression before //. We will see more examples of this in subsection 1.6. 4

1.4

Getting Help, Interrupting Mathematica

Mathematica has an excellent help tool. For example, to find a Mathematica function to solve the system of equations x2 + 3y 2 = 36, 2x + y = 3, from the Help menu choose the Function Navigator, then Mathematics and Algorithms and then Equation Solving. Try one of the functions and see which one is appropriate. We will cover solving systems of equations using Mathematica in subsection 1.9. Another way you could search for the appropriate Mathematica function is to try your luck. So to find the function to solve a system of equations one could guess that the command is Solve and if we execute ?Solve Mathematica gives the basic syntax for the command Solve and, if we click the >> at the end of the output, Mathematica gives a detailed description of the command. However, as you will see in subsection 1.9, the function Solve is useful only in some situations and other functions are more appropriate in some situations, so sometimes it is better to use the Help menu and search for all the possible functions appropriate for whatever you wish to do. Sometimes a calculation takes much longer than you expected it to take and you may wish to interrupt the calculation. This can be done by choosing Abort Evaluation from the Evaluation menu; you may need to do this several times before the evaluation stops. For example, to compute sin 1 + sin 2 + · · · sin(107 ) use Sum[ Sin[n^2], {n,1,10^7} ] which takes a long time, so one should abort the calculation by choosing Abort Evaluation from the Evaluation menu. If that fails try using the Alt+ or Alt+. keys and if that fails you can always Quit Mathematica and start again. Now is a good time to do the exercises below. They are quite straightforward and will help you assimilate the ideas we have discussed so far. 2

Exercise 1.1 Compute the fourth derivative of cos(x + 1) + ln(x − 1) + xex +1 with respect to x. Also compute the integral of the original function with respect to x over the interval [2, 4] - do not retype the expression to be integrated. 2

Exercise 1.2 What is the numerical value of eu+v + u2 sin(uv) when u = −3, v = 2? Exercise 1.3 What is the numerical value of sin 3? All trigonometric angles in Mathematica are in radians (and not degrees) by default. What is the numerical value of sine of 20 degrees ? Hint: convert degrees to radians and then apply the sine function. Answer: 0.3420201433 . 5

Exercise 1.4 Determine the numerical value of the following expression when p = 3, q = 1 Z p  d u2 sin(p u) du − p q 3 sin(p q) + (p q + 1) eq dq q Answer: −8.73549981 .

1.5

Plotting Planar Curves Given Explicitly or Implicitly

We now describe some of Mathematica’s plotting tools. Planar curves may be given explicitly as in y = x2 (a parabola), implicitly as in x2 + y 2 = 1 (a circle), or in parametric form as in x = t + sin t, y = 1 − cos t, −6 ≤ t ≤ 6 (a cycloid). Curves may also be given in polar form as in the three leaved rose r = sin(3θ). We draw curves given in explicit or implicit form. To draw the graph of the explicitly given curve y = x2 + 9 sin x over the interval [−3, 3] use Plot[ x^2 + 9*Sin[x], {x,-3,3} ] To draw the graph of two (or more) explicitly given curves y = x − x2 and y = 1 − 2x over the interval [0,1] in the same window, one could use Plot[ {x-x^2, 1-2*x}, {x,0,1} ] but one would not know which curve represents which function. So one usually specifies a color for each of the functions as in Plot[ {x-x^2, 1-2*x}, {x,0,1}, PlotStyle -> {Red, Blue} ] with y = x − x2 colored red and y = 1 − 2x colored blue - note Red and Blue start with upper case letters. Plot has other options such as axes labels Plot[ {x-x^2, 1-2*x}, {x,0,1}, PlotStyle -> {Red, Blue}, AxesLabel -> {x,y} ] In the plot, the vertical and horizontal sizes are scaled so that the spaces devoted to the horizontal range and the vertical range are equal. If you want to see the true shape of the curves, use the option AspectRatio->Automatic; try Plot[ {x-x^2, 1-2*x}, {x,0,1},

PlotStyle -> {Red, Blue}, AspectRatio->Automatic ]

To find other options available for Plot use the Help menu. To determine the point of intersection of the two curves in the plot, click the plot and then hold down the right mouse button and choose Get Coordinates. Now as the cursor moves over the plot the coordinates of the cursor are displayed. 6

To draw curves given implicitly (i.e. they are not given in the form y = f (x), but in the form g(x, y) = c) use the ContourPlot function. To draw the ellipse x2 + 4y 2 = 4 use ContourPlot[ x^2 + 4*y^2 == 4, {x,-3,3}, {y,-3,3} ] Note that equations are entered with two equal signs ==. Also, note that for ContourPlot, both the x and y ranges have to be given because ContourPlot draws the plot only in the rectangle determined by the x and y ranges. Compare this with using the Plot command used to plot explicitly given curves such as y = x2 where only the x range is required. Examine what happens if you increase or decrease the ranges for x and y - try several changes. For ContourPlot, it is advisable to start with a large range and then decrease the range until the graph is satisfactory. To draw more than one implicitly given curve, for example, the ellipse x2 + 4y 2 = 4 and the circle x2 + y 2 = 2, with ellipse blue and circle colored green, use ContourPlot[ {x^2 + 4*y^2 == 4, x^2 + y^2 == 2}, Return {x,-3,3}, {y,-3,3}, ContourStyle -> {Blue, Green},

Axes -> True ]

Note we must use ContourStyle instead of PlotStyle to assign the color to the curves and we also used the option Axes -> True to display the coordinate axes. Again the approximate locations of the points of intersection may be read by right clicking the picture and choosing Get Coordinates. Explicitly given curves such as y = x2 − 5x can be plotted using Plot or ContourPlot but Plot will usually give better pictures. Curves such as x2 + 4y 2 = 9 can be plotted only with ContourPlot. To superimpose two plots (obtained from different commands) use the Show function. For example, to display the graphs of y = x2 , y = 1 − x2 , and the circle x2 + y 2 = 1 in the same picture, use pic1 = Plot[ {1-x^2, x^2}, {x,-1,1}, PlotStyle -> {Red, Blue} ] ; pic2 = ContourPlot[ x^2 + y^2 == 1, {x,-1,1}, {y,-1,1}, ContourStyle -> {Green} ] ; Show[ pic1, pic2, PlotRange->All ] The first and second lines define two plots named pic1 and pic2 and the third line shows the two pictures superimposed. Note the use of the semicolons ; - Mathematica does not display the output of commands which end in semicolons. We did not want want the individual plots pic1 and pic2 so we hid those plots by using the semicolon. See what happens if you remove the semicolon. Also note the use of the option PlotRange->All. When Show is used, it may happen that only a part of the second plot is used because the window in which the plot is displayed is determined 7

by the first picture. To guarantee that all parts of all the pictures are displayed we used the PlotRange->All option. See what happens if you remove that part of the Show command. When the plot generated by ContourPlot looks jagged use the PlotPoints option. Exercise 1.5 In the same picture show the curves y = 2x and x3 + y 3 = 3xy with the first curve colored red and the second one blue and label the axes ’x’ and ’y’. Graphically determine the point of intersection of these two curves with as much accuracy as you can.

1.6

Factor, Expand, Postfix Application of a Function

The functions Factor, Expand, Simplify have the usual meaning - also try Collect. One can use Factor[ x^4 + 5*x^3 - 5*x^2 + 5*x -6 ] Expand[ (x^2+2)*(x^3-4)*(x+2) ] Simplify[ (x-1)*(x^3+1) + (x+2)*(x^2+4) ] but usually one thinks of Factoring, Expanding or Simplifying a function only after we have seen the expression so the postfix form is more convenient (and less cumbersome without the square brackets). x^4 + 5*x^3 - 5*x^2 + 5*x -6 // Factor (x^2+2)*(x^3-4)*(x+2) // Expand (x-1)*(x^3+1) + (x+2)*(x^2+4) // Simplify

1.7

Lists, Parts of lists and expressions

Ordered lists show up in many situations in Mathematica. We have already seen lists of equations as in {x+y==2, x-y==1}, or an ordered list of colors as in {Red, Blue, Green}, or even when giving the range of a variable in a plot as in the ordered list {x,-2,2}. Note that lists are enclosed in curly brackets { }. For example, consider the list below some of whose elements are themselves lists. mylist = { 3, 6, {x, x^2}, {7,8,9}, 2,7 } Here are some operations on a list. mylist^2 + 1/mylist Length[mylist] mylist[[2]]

number of elements in mylist second element in mylist 8

mylist[[3]] mylist[[{1,2,4}]] mylist[[2;;4]]

third element in mylist first, second and fourth elements in mylist second to fourth elements in mylist

These commands are also useful in getting parts of expressions - try the following and think about the Mathematica output. f = x^3 + 3*x^2 - 7*x + 10 Length[f] f may be thought of as a list; how many terms in this list f[[1]] first term of f f[[3]] third term of f f[[2;;4]] second to fourth terms of f g = Sin[x]*Cos[x]*(1+x^2)/(2-x^3) Length[g] g[[4]] g[[2;;4]] Exercise 1.6 Consider the expression (ax2 + bx sin y + c sin y)2 + (a sin2 y + bx)3 (a) Write the above as a polynomial in x and extract the coefficient of x2 . Ans : b2 (3a + 1) sin2 y + 2ac sin y. (b) Write the above as a multinomial in the variables x and sin y and extract the coefficient of x sin2 y. Ans : 2bc.

1.8

Brackets, Names of built-in objects

Mathematica has very specific roles for the different types of “brackets”. The square brackets [ ] are reserved exclusively to enclose the variables of a Mathematica function as seen above in the case of D, Integrate, Sin or Log. The round brackets ( ) are used only for grouping expressions as seen in (x+7)*Log[1+x], and the curly brackets { } are used only to enclose ordered or unordered lists, as in Integrate[ Sin[x], {x,0,Pi} ] where, in the ordered list {x,0,Pi}, the first entry is the variable of integration, the second entry is the lower limit and third entry is the upper limit. All Mathematica built-in objects such as function names D, Integerate, Sin or constants such as E or Pi begin with an upper case letter. If a Mathematica built-in object is made of two words then the two words will begin with upper case letters as in FindRoot. So when introducing your own objects it is highly recommended that you use names which begin with lower case letters.

9

1.9

Solving a System of Equations I - Solve, NSolve

To obtain solutions of one equation in one variable or to find the solutions of a system of equations, the Solve command is useful. To find all solutions of the quadratic equation x2 − 3x + 2 = 0, use Solve[ x^2 - 3*x + 2 == 0, x ] Note the double equal. The solutions are x = 1 and x = 2 but the Mathematica output is given as a list of rules { {x -> 1}, {x -> 2} } because this will make it easy to use the solutions in other Mathematica calculations. To solve the system of equations x + y = 1, x2 − y = 1, for the variables x, y, use Solve[ {x + y ==1, x^2 - y == 1}, {x,y} ] and we obtain the two sets of solutions. To find all solutions of 3x − 2y = 5, x2 − y 3 = 2 we use Solve[ {3*x - 2*y == 5, x^2 - y^3 == 2}, {x,y} ] and to obtain the decimal values of the solutions one uses NSolve mysol = NSolve[ {3*x - 2*y == 5, x^2 - y^3 == 2}, {x,y} ] We also named the list of solutions as mysol because we will use it below. We can extract the different solutions in mysol, for example mysol[[1]] mysol[[3]]

first part of mysol third part of mysol

Often, we will need to substitute the solution of a system of equations into an expression. Suppose we need to substitute the third solution x = 2.908, y = 1.862 into the expression x2 + y 3 + sin(xy). We would do this using /. as seen earlier and one inefficient way of doing it is x^2 + y^3 + Sin[x*y] /. {x->2.908, y->1.862} This is inefficient because we retyped {x->2.908, y->1.862} which was already available as Mathematica output. A better way would be to use the output x^2 + y^3 + Sin[x*y] /. mysol[[3]] 10

and this has the advantage of working even if the original system of equations is modified where as the inefficient way would would have to be modified manually to enter the new solutions think about this a little. One should never retype or Copy and Paste the results of a Mathematica calculation. Instead, a name should be given to the output and the name should be used. Please try the exercise below before moving to the next section. Exercise 1.7 Find the numerical value of sin(x2 + x) where x is the positive root of the equation x3 + 3x2 = 2. Answer : 0.9544912329. Exercise 1.8 Evaluate x3 + exy at the solution of y = x + 1, x2 + y 2 = 4 which lies in the first quadrant. Ans: 5.038878215 .

1.10

Solving a System of Equations II - FindRoot

The functions Solve and Nsolve are suitable mostly for solving systems of polynomial equations. If the equations involve non-polynomials then Solve and Nsolve may not find all or even one solution of the system of equations. One then has to appeal to numerical methods which construct solutions of the system of equations one solution at a time. The function used to solve systems of non-polynomial equations is FindRoot and it will give one solution per execution. To find all solutions of the equation 7 cos x + x + x2 = 15 try Solve[ 7*Cos[x] + x + x^2 == 15, x ] NSolve[ 7*Cos[x] + x + x^2 == 15, x ] and neither of these two work. We now use FindRoot to find approximations of the solutions to 7 cos x + x + x2 = 15. Unfortunately FindRoot is an iterative method and needs a starting guess for the solution. One can just choose an arbitrary starting guess and try our luck - let us say we choose our starting guess for the solution to be x = 5.0. So we try FindRoot[ 7*Cos[x] + x + x^2 == 15, {x, 5.0} ] and we get one solution x = 3.9701 (actually it is a very good approximation of the solution). How do we find other solutions of this equation if there are any? One could try other starting guesses and hope for the best. However, for the given equation one can do better. The solutions of 7 cos x + x + x2 = 15 are the solutions of 7 cos x + x + x2 − 15 = 0, that is points where the graph of y = 7 cos x + x + x2 − 15 cuts the x axis, so we can get good starting points by examining the plot of y = 7 cos x + x + x2 − 15. We plot the graph over the interval [−10, 10] and we can adjust this interval later. Plot[ 7*Cos[x] + x + x^2 -15, {x, -10,10} ] 11

We see that there are only two solutions (in [−10, 10]) - one near x = 5 and one near x = −5. We can plot the graph over larger intervals (and argue theoretically - a little difficult) to see that there are no other solutions. We have already found the solution near x = 5, we now find the solution near x = −5. FindRoot[ 7*Cos[x] + x + x^2 == 15, {x, -5.0} ] Exercise 1.9 Find all the solutions of x2 + 2x + x sin x = 4. Check your answer by substituting these values of x into the equation. Now consider the system of equations x2 + y 2 = 4 and sin(x + y) + cos x = 1; these are not polynomial equations so Solve and NSolve will fail - try it. Solve[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x,y} ] NSolve[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x,y} ] So we try FindRoot and as before we need a starting guess for the solution. We can choose an arbitrary starting guess for x and y but we can do much better by plotting. The solutions of the system of equations are the points of intersection of the curves x2 +y 2 = 4 and sin(x+y)+cos x = 1. Plotting these curves over the rectangle −3 ≤ x ≤ 3, −3 ≤ y ≤ 3 ContourPlot[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x,-3,3}, {y,-3,3}, ContourStyle -> {Red, Blue} ] we observe that there are two points of intersection. Right clicking the plot and choosing Get Coordinates we see that the points of intersection are near (0.87, 1.74) and (−1.20, 1.53). So we can get these solutions with more precision by using FindRoot[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x,0.87}, {y,1.74} ] FindRoot[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x, -1.20}, {y,1.53} ] Of course, the question remains whether there are solutions outside the rectangle −3 ≤ x ≤ 3, −3 ≤ y ≤ 3. One can plot the curves over larger rectangles but some thought will show that there are no solutions outside this rectangle because the curve x2 + y 2 = 4 lies inside this rectangle. Of course this plotting method fails when we have three equations in three unknowns - in that case one tries to make educated guesses for the starting point. Try finding solutions of the system of equations x2 + y 2 + z 2 = 4, x + y + z = 0, x sin(yz) = −1. Exercise 1.10 Find all solutions of x2 + y 2 = 9, x3 + y 3 − sin(xy) = 7. Why are you sure that there are no more? Answer: There are two solutions. 12

1.11

Time Saving Tricks

• Use space between characters judiciously, not too much and not too little, to make error detection easier. The following three lines do exactly the same thing - finding the solution of a system of equation - but the first is preferable. FindRoot[ {x^2 + y^2 == 4, Sin[x+y] + Cos[x] == 1}, {x,0.87}, {y,1.74} ] Good FindRoot[{x^2+y^2==4,Sin[x+y]+Cos[x]==1},{x,0.87},{y,1.74}] terrible FindRoot[{x^2 + y^2 == 4, Sin[x+y] +Cos[x] ==1}, {x,0.87},{y,1.74} ] can be improved In the first line, note how the command, the equations and the initial guess are judiciously spaced so that the different units stand out. • If the output of a certain calculation is to be used later, it is best to give the output a meaningful name and use the name. Never retype the output and never copy and paste the output. • For incorrect commands, Mathematica will highlight where errors may have occurred in the command. Check the highlighted characters for errors. The following attempts to find the solution of a system of equations. FindRoot[ {x^2 + y^2 == 4, Sin(x+y] + Cos[x] == 1}, {x,0.87}, {y,1.74} ] Now locate the error and correct it. • It is OK to Copy and Paste a command but a bad idea to Copy and Paste the output of a command. • In Mathematica, several commands may be executed together. This is particularly convenient if the desired output is the result of several commands and one is not interested in the intermediate results. For example, we will compute the numerical value of Z 3  d 3 x sin(kx) + t cos(t + k) dt dx 1 when x = 2, k = 4. a = D[ Sin[k*x]*x^3 , x ] b = Integrate[ t*Cos[t+k], {t,1,3} ] a+b /. {x->2, k->4}

Return (not Shift Return) Return Shift Return

All the commands are executed together and the last result is the desired answer. The problem was broken into several parts then combined to get the final result. In the previous problem, we were not really interested in the intermediate values a, b. One can suppress the output of a command by placing a semicolon at the end of the command, so try a = D[ Sin[k*x]*x^3 , x ] ; b = Integrate[ t*Cos[t+k], {t,1,3} ] ; a+b /. {x->2, k->4} 13

Return (not Shift Return) Return Shift Return

1.12

Some Common Errors

Here are some common errors when using Mathematica. • Mathematica built-in objects start with upper case letters. So, for example, don’t use integrate instead of Integrate, don’t use sin[x] instead of Sin[x] and don’t use red instead of Red. • Another common error is to use round brackets or no brackets where square brackets are to be used. For example Sin(x) and Sin x are incorrect where as Sin[x] is correct. • Do not use a single = for equations; you must use ==. So do not use x^2 + y^2=1 instead use x^2 + y^2 ==1. • Do not type xy when you really want x ∗ y. • The function Solve is useful only in finding solutions of systems of polynomial equations. It is useless/incorrect to attempt to use Solve for simplifying expressions (use Simplify) or use it in other ways in which we use the verb solve in mathematics such as solving a particular type of problem. • A common error is to use a symbol as a variable even though the symbol was assigned a value earlier. For example, suppose at some stage you used x = 4; and you forgot about it. Some commands later you differentiate sin x expecting cos x but instead you get an error message because x has the value 4. Try x = 4 D[Sin[x], x] Clear[x] D[Sin[x], x]

Error Clear the value assigned to x now it works as you want it to

• Since the commands in a Mathematica notebook are often modified and then rerun, it is a good idea to start every notebook with the Quit[] command which clears the values assigned to all the variables. Execute the following commands D[Sin[x], x] D[Cos[y], y] x = 4 Now reexecute each of the commands and a problem arises with the first command. That is so because Mathematica remembered that x = 4 from the third command so in the rerun the first command does not make sense. So try the following - move the cursor above the first line and then type Quit[] and hit Shift Enter and then reexecute the commands and there should be no problem.

14

1.13

Summary of Section 1

D, Integrate Plot ContourPlot Show Solve, NSolve, FindRoot /. // N Length Factor, Expand, Simplify Sqrt, Log, Sin, Exp [ ], { }, ( )

1.14

differentiate, integrate plot curves of the form y = f (x) plot curves of the form g(x, y) = c superimpose two or more pictures solve systems of equations apply a rule such as {a ->3} to the expression before /. apply the function given after // to the expression before // applied to an expression gives its numerical value length of a list or number of terms in an expression, also see how to get parts of lists obvious obvious specific roles of the three types of brackets

Problems

1. Graphically determine the number of solutions of the equation x2 − x sin(3x) − x ln(x + 2) = 1 in the interval [0,3] and the approximate values of these solutions. Then find the solution closest to x = 2 accurate to 6 digits. Ans : x = 1.3, 2.2, 2.8; x = 2.199377 . 2. Find the numerical value of the following sum 1 1 1 1 + + + ··· + . 2 3 4 100 Ans: 4.1873775. 3. Find all solutions of the system of equations x2 + y 2 = y 2x + 2y 2 + 2 cos(xy) = 3 which lie in the region −1 ≤ x ≤ 1, −2 ≤ y ≤ 2. Ans: (x = −0.2895, y = 0.9076) and (x = 0.43877, y = 0.26026). 4. Find the largest and the smallest value of the function x2 − x sin(3x) − x ln(x + 2) over the interval [0, 3]; at which points are these values attained. Ans: max = 2.93533 at x = 3; min = −0.81567 at x = 0.6639. 5. Let f = A cos x + B sin x + P x2 + Qx + R. Find the value of A, B, P, Q, R so that d2 f df +3 + 2f = 5 sin x + 2x2 + 1 dx2 dx Ans : a = −3/2, b = 1/2, p = 1, q = −3, r = 4. 15

6. Find all solutions of the system of equations x2 + y 2 + z 2 = 9 x+y+z = 2 x + 2y + 3z = 5 Then compute the value of exp(xy + z) + z 2 at the solution where z is the largest. Ans: two solutions, largest z solution is (x = 1.25958, y = −1.51914, z = 2.25958), value is 6.5192.

2

Preparing a Mathematica Report

A report on the solution of a mathematical problem consists of text/comments which guides the reader and mathematical calculations and plots needed to obtain the solution. Mathematica notebooks provide an excellent tool for preparing reports. A Mathematica notebook has various types of cells. You have seen input cells where you enter commands, output cells which contain the output of a command, graphics cells. Below we use text cells for comments/description, title cells, section cells etc. We will prepare a report which presents the solution of the problem Find all solutions of the equation x sin x = 5 in the interval [0, 10]. • Open a new notebook. • We first provide a heading for our report. Click the first line of the notebook and you will see a + symbol followed by a line. From the Format menu choose, choose Style and then Title. Now type First Report For Math 242/243/302 Your name The date and you can center it if you wish by choosing the appropriate item from the Format menu. • We now state the problem. Click just below the last line and you will see a + with a line. From the Format menu choose Style amd then Section . Then type Finding all solutions of x sin(x)=5 in [0,10] We are now ready to solve the problem. • Click just below the last line and from Format choose Style and Text, then type We start by finding the approximate location of the solutions by plotting the graph of y= x sin(x)-5 on [0,10] 16

and then click below, enter the following Mathematica commands Quit[] Plot[x*Sin[x]-5, {x,0,10}]

Shift Enter Shift Enter

The places where the plot crosses the x-axis give the approximate locations of the solutions of x sin x = 5 in the interval [0, 10]. We see that there are two solutions, one near x = 7 and the other near x = 9. We find these two solutions. • Right click below the line and execute the following sol1 = FindRoot[x*Sin[x]==5, {x,7}] sol2 = FindRoot[x*Sin[x]==5, {x,9}]

Enter Shift Enter

and we obtain the two solutions. We now state our conclusion. Right click below the last line, and from Format and Style choose Text and then type The equation x sin(x) = 5 has two solutions in [0,10]. Accurate to 6 digits they are 7.06889 and 8.82222. and our report is complete.

3 3.1

Advanced Functions Functions

So far we have used expressions instead of functions. For example, if we want to work with the function x3 + sin x then we have chosen to use p = x^2 + Sin[x] ; However, the p defined above is an expression and not a function; because to find the value of x2 + sin x at x = 2 we have to use a rule p /. {x->2.0} instead of p[2]. Depending on the situation, a better way may be to define a function f f[x_] = x^2 + Sin[x] and now try f[2.0] 17

Here is another example of a function and its uses. Please examine the output of each command and see whether you get what you expected. g[x_,k_] = x^k + Sin[k*x] g[y, 3] g[2, m] g[2.0,5] Plot[ g[x,5], {x,0,1} ] D[g[x,k], x] Note that, when defining a function, the input variables are declared with an underscore. Functions can be defined with an = or := called Set or SetDelayed. For example f[x_] = Sin[x^3] + Cos[x] g[x_] := Sin[x^3] + Cos[x] seem to behave the same - try f[2.0] g[2.0] but there is a difference between using = and := which will become apparent in the examples below. When = is used in defining a function then the right hand side is evaluated before the value of x is substituted where as when := is used then first the x value is substituted and then the right hand side is evaluated. Consider the following function which returns the third derivative of sin(x2 + x) at x. f[x_] = D[ Sin[x^2+x], {x,3} ] f[5.0] and everything is fine because x = 5 is substituted into the RHS of the definition of f after the RHS has been computed. However, if you try g[x_] := D[ Sin[x^2+x], {x,3} ] g[5.0] then there is an error, because x = 5 is substituted in the RHS of the definition of g before the RHS is computed and its makes no sense to differentiate with respect to 5. On the other hand in the next example you do want to delay the computation. Here g[k_] := Plot[ Sin[kx], {x,0,Pi} ] g[3] plot the graph of Sin[3x] over [0, 2 Pi] 18

works, where as h[k_] = Plot[ Sin[kx], {x,0,Pi} ] h[3] plot the graph of Sin[3x] over [0, 2 Pi] does not work because in the definition of h Mathematica attempts to plot sin(kx) for x varying in [0, 2π] without knowing k, where as in the := case the execution of the Plot is delayed until the k is known.

3.2

Animation

Consider the function sin(tx) which depends on x and another variable t (think of it as time). So at time t = 1, the function is sin x, at t = 2 the function is sin(2x), at t = 7.5 the function is sin(7.5x). We can plot the graph of sin(tx) on 0 ≤ x ≤ π for varying t using the Manipulate function. p[t_] := Plot[ Sin[t*x], {x,0,Pi} ] p[2] p[6.3] Manipulate[ p[t], {t,0,10} ]

p[t] gives the plot of y=sin(tx) for 0
When the Manipulate command is executed a box appears with a slider associated to t. Click the + next to the slider and various controls appear - the animation can be played by pressing the play button on the controls. You can slow down the animation, pause it, choose the value of t you wish and manipulate the plots in various other ways - try it. Manipulate can also be used when discrete values of t are used. For example, one knows (a + b)2 = a2 + 2ab + b2 , (a + b)3 = a3 + 3a2 b + 3ab2 + b3 ; to see how the expansion of (a + b)n changes as n varies from 1 to 25 with n increasing by 3 each time, try ex[n_] := Expand[ (a+b)^n ] Manipulate[ ex[n], {n,1,25,3} ] Actually the increment by 3 is not very informative; change the increment to 1 and see the expansion only for n between 1 and 10, that is modify the command to be {n,1,10,1}. Exercise 3.1 Consider the family of curves x3 +y 3 −3txy −x = t as t varies over [−2, 2]. Animate the plot of this family of curves over the rectangle −4 ≤ x ≤ 4, − 4 ≤ y ≤ 4.

19

3.3

Conditional Execution

Conditional statements are useful when writing Mathematica functions. For example, to define the function ( −2x, x < 0 f (x) = 3x, otherwise, we would use f[x_] := If[ x<0, -2*x, 3*x ] f[3] f[-5] f[t] So If is an if then else statement. To generate compound conditions such as x < 1 or x > 5, or the condition x3 + x > 10 and x < 7, use || for or and && for and. For example, one could have f[x_] := If[ x<1 || x>5 , -2*x, 3*x ] f[3] f[-5] f[t] g[x_] := If[ x^3+x > 10 && x <7 , -2*x, 3*x ] g[3] g[2] g[y] Mathematica also has Which and Piecewise functions which are used when several If statements are required. Exercise 3.2 Define the function ( 1 − x2 f (x) = x−1

x≤1 x>1

and then plot it over the interval [−1, 3]. Exercise 3.3 Define the function  2  1 − x f (x) = x − 1   3−x

x≤1 1
and then plot it over the interval [−1, 4]. You may need to use the Which function.

20

3.4

Finite Sequences and Series, Taylor Polynomials

To find the sum of the series

69 X sin n 1 + 3n2

n=5

accurate to seven digits, use NSum[ Sin[n]/(1+3*n^2), {n,5,69} ] If one had used Sum instead of NSum the exact sum would have been given. To generate sequences of numbers arising from one ‘formula’ try Table. Observe the result of executing the following statements Table[ n^2, {n,3,10} ] Table[ n^2, {n,3,30,5} ] Table[ Sin[k*x], {k,1,7} ]

generate n^2 for n from 3 to 7, n increasing by 1 generate n^2 for from 3 to 30, n increasing by 5

To find the Taylor series of an expression f , around x = a up to and including the power (x − a)n , use Series[f, {x,a,n}]. For example Series[ Log[x], {x,1,7} ] gives the Taylor expansion of ln x, around x = 1, up to and including (x − 1)7 terms. The output is a polynomial followed by the expression O[x − 1]8 and this last expression is inconvenient when we wish to manipulate the polynomial. To extract just the polynomial part one uses the function Normal; try polyseven = Series[ Log[x], {x,1,7} ] Normal[polyseven]

3.5

Plotting Planar Parametric Curves or Curves in Polar Coordinates

In subsection 1.5 we plotted curves of the form y = f (x) or g(x, y) = 0. We now plot curves in the plane given either in parametric form or in polar coordinates. To plot the cycloid given in the parametric form x = t + sin t, y = 1 − cos t, 0 ≤ t ≤ 4π we use ParametricPlot[ {t + Sin[t], 1 - Cos[t]}, {t,0,4*Pi} ]

21

To draw the two (or more) parametric curves but with the same parameter range say the cycloid x = t + sin t, y = 1 − cos t, x = 2 cos t, y = 2 sin t,

0 ≤ t ≤ 2π 0 ≤ t ≤ 2π

we use ParametricPlot[ { {t+Sin[t], 1-Cos[t]}, {2*Cos[t], 2*Sin[t]} }, {t,0,2*Pi}, PlotStyle->{Red, Blue} ] However, to plot curves with different parametric ranges in the same plot, one must first draw the curves separately and then use Show to display them together. For example to draw x = t + sin t, y = 1 − cos t, x = 2 cos t, y = 2 sin t,

0 ≤ t ≤ 2π 0 ≤ t ≤ π,

note the range for the second curve is different from the that for he first curve, we use pic1 = ParametricPlot[ {t+Sin[t], 1-Cos[t]}, {t,0,2*Pi}, PlotStyle->Red ]; pic2 = ParametricPlot[ {2*Cos[t], 2*Sin[t]}, {t,0,Pi}, PlotStyle->Blue ]; Show[pic1, pic2] Note the use of the semicolon ; to avoid displaying the pictures separately when generating pic1 and pic2. To plot curves given in polar coordinates use the function PolarPlot. For example, to draw the cardiod r = 1 + cos θ, 0 ≤ θ ≤ 2π, use PolarPlot[ 1+Cos[t], {t,0,2*Pi} ] and to draw curves with the same angular range, say r = 1 + cos θ and r = 1 − cos θ both with 0 ≤ θ ≤ 2π we use PolarPlot[ {1+Cos[t], 1-Cos[t]}, {t,0,2*Pi}, PlotStyle->{red,blue} ] with r = 1+cos t colored red and r = 1−cos t colored blue. To draw two polar curves with different ranges one must plot them separately and then use Show. We now plot four different types of curves in the same picture. To plot the curves (a) y = x2 , −1 ≤ x ≤ 1, (b) x2 + y 2 = 1, (c) x = sec t, y = tan t, π/4 ≤ t ≤ π/4, 22

(d) r = sin(3θ), 0 ≤ θ ≤ 2π. in the same picture we use pic1 = Plot[ x^2, {x,-1,1}, PlotStyle -> Red ] ; pic2 = ContourPlot[ x^2 + y^2 ==1, {x,-1,1}, {y,-1,1}, PlotStyle->Green ] ; pic3 = ParametricPlot[ {Sec[t], Tan[t]}, {t,-Pi/4,Pi/4}, PlotStyle->Blue ] ; pic4 = PolarPlot[ Sin[3*t], {t,0,2*Pi}, PlotStyle->Brown ] ; Show[ pic1, pic2, pic3, pic4 ] Exercise 3.4 Generate a plot showing the three leaved rose r = sin 3θ and the circle r = 1 coloring the rose red and the circle blue. Do the same showing only the right hand side of the rose and the full circle. Rewrite the two curves in parametric form x = .., y = .. and plot them using the ParametricPlot function instead of the PolarPlot function.

3.6

Summary of Sections 1 and 3

Factor, Expand, Simplify Sqrt, Log, Sin, Exp [ ], { }, ( )

differentiate, integrate plot curves of the form y = f (x) plot curves of the form g(x, y) = c superimpose two or more pictures solve systems of equations apply a rule such as {a ->3} to the expression before /. apply the function given after // to the expression before // applied to an expression gives its numerical value length of a list or number of terms in an expression, also see how to get parts of lists obvious obvious specific roles of the three types of brackets

f[x_] := etc. Manipulate If[cond true, do this, else this] ||, && Table ParametricPlot PolarPlot

defining a function Animation conditional statement, also see Which, Piecewise Or, And generate a sequence plot curves given in parametric form plot curves given in polar form

D, Integrate Plot ContourPlot Show Solve, NSolve, FindRoot /. // N Length

23

4 4.1

Vectors Operations and Multidimensional Integrals Vector Operations

The following statements show some of the vector commands in Mathematica. v = {2,3,7} w = {-3,4,2} v.w lenv:= Sqrt[ v.v ] Cross[v,w] u := 3*v- w/2 ; u[[3]]

define v to be the vector 2i + 3j + 7k define vector w dot product of v and w length of v is sqrt of v.v cross product of v and w compute 3v-w/2 the 3rd component of u

When working with the motion of a particle we have to differentiate or integrate a vector expression. We show some examples below. r = {Sin[t], t+Cos[t], t*Sin[2*t]} defines a curve v = D[r,t] the derivative of r which is the velocity of the curve junk = Integrate[r, {t,0, Pi/2} ] component-wise integration of r for t in [0, Pi/2] To determine the value of a vector expression (x2 − yz)i + (y 2 + z 2 )j + xyzk when x = 1, y = 3, z = −1, we use the /.; try a = {x^2 -y*z, y^2 + z^2, x*y*z} a/.{x->1, y-> 3, z -> -1}

4.2

Operations on Vector Fields

In Mathematica, we may compute the gradient of a function and the curl and the divergence of a vector field. These functions are available in the Vector Analysis package which has to be loaded into Mathematica. Try the following commands. Needs["VectorAnalysis‘"] load the package SetCoordinates[Cartesian[x,y,z]] coordinates are set to x,y,z Grad[ x^2 + yz - y^2 ] Gradient of a function v = {x^2 - 2*y*z, y^3 + x*z, z^2+ x*y} defines the vector field Curl[v] curl of v Div[v] divergence of v In Mathematica, the default Cartesian coordinates are Xx, Yy, Zz, I presume in case the user has assigned values to x, y, z in their calculations. In most cases you will find it convenient to reset the coordinates to x, y, z. 24

4.3

Multidimensional Integrals

To compute the double integral 2 Z 3x2

Z

x + y dy dx 1

2x

use Integrate[ x+y, {x,1,2}, {y, 2*x, 3*x^2} ] note that the outer limits are listed first and the inner limits second. So to compute 1 Z y2

Z

x + y dx dy y3

0

use Integrate[ x+y, {y,0,1}, {x,y^3, y^2} ] To compute the triple integral Z



0

Z 1

2 Z 2r2

zr2 dz dr dθ

r2

use Integrate[ z*r^2, {t, 0, 2*Pi}, {r, 1, 2}, {z, r^2, 2*r^2} ]

4.4

Jacobian

The Jacobian needed in multi-dimensional change of variable problems may be computed as shown in the following example. For the change of variables x = u sin v cos w,

y = u sin v sin w,

z = u cos v,

the Jacobian is computed by the following set of commands. M = D[ {{ u*Sin[v]*Cos[w], jac = Det[ M[[1]] ] Simplify[jac]

u*Sin[v]*Sin[w], u*Cos[v] }},

{{ u,v,w }} ]

The first command generates the Jacobian matrix and the Jacobian is its determinant. However, for reasons I do not know, the M above always has an extra pair of parentheses - that is why M [[1]] is used in the second command instead of just M . Let me know if you find a more reasonable way. 25

5

Plotting Curves and Surfaces

5.1

Plotting Three Dimensional Curves

Curves in three dimensions are given in parametric form x = f (t), y = g(t), z = h(t),

a≤t≤b

which are plotted using the ParametricPlot3D. As an example, we plot the spiral x = cos t , y = sin t , z = t,

0 ≤ t ≤ 4π

and the line segment 5π t, 0≤t≤1 2 in the same picture with the spiral colored red and the line segment colored blue. x=1−t , y =t , z =

spiral = ParametricPlot3D[ {Cos[t], Sin[t], t}, {t,0,4}, PlotStyle->Red]; line = ParametricPlot3D[ {1-t, t, 5*Pi*t/2}, {t,0,1}, PlotStyle->Blue]; Show[ {spiral, line} ] If the curves need to be thickened then it can be done with the help of the AbsoluteThickness specification. For example, to thicken the spiral, one could use spiral = ParametricPlot3D[ {Cos[t], Sin[t], t}, {t,0,4}, PlotStyle->{Red, AbsoluteThickness[3]} ]; line = ParametricPlot3D[ {1-t, t, 5*Pi*t/2}, {t,0,1}, PlotStyle->Blue]; Show[ {spiral, line} ] The orientation of the plot may be changed by dragging the box surrounding the plot.

5.2

Plotting Three Dimensional Surfaces

Surfaces may be given either in explicit form (z given in terms of x, y) such as z = x2 + y 2 , in implicit form (x, y, z connected by a single equation) such as x2 + y 2 + z 2 = 1, or in parametric form (a formula to generate all the points on the surface) such as the above sphere has the parametric form x = sin φ cos θ, y = sin φ sin θ, z = cos φ, To plot the explicitly given surface z = x2 + y 2 use 26

0 ≤ θ ≤ 2π,

0 ≤ φ ≤ π.

Plot3D[ x^2 +y^2,

{x,-2,2}, {y,-2,2} ]

It is usually convenient to label the axes with the AxesLabel option; also try some of these other options. Plot3D[ x^2 +y^2,

{x,-2,2}, {y,-2,2}, PlotStyle->FaceForm[Red,Blue], AxesLabel->{x,y,z} ]

Rotate the picture and examine the surface from different viewing angles. To draw two explicitly given surfaces, such as the paraboloids z = x2 + y 2 and z = 6 − x2 − y 2 with the first colored red and the second blue use Plot3D [ {x^2 + y^2, 6 - x^2 - y^2}, {x,-2,2}, {y,-2,2}, PlotStyle->{Red, Blue}, AxesLabel->{x,y,z} ] While plotting surfaces some thought must be devoted to choosing the ranges for x and y - some theoretical analysis and trying various choices usually results in good plots. Surfaces given implicitly such as the ellipsoid x2 /4 + y 2 /9 + z 2 /8 = 1 are plotted using the ContourPlot3D function. ContourPlot3D[ (x^2)/4 + (y^2)/9 + (z^2)/8 == 1, {x,-2,2}, {y,-2,2}, {z,-2,2}, AxesLabel ->{x,y,z} ] Note that we prescribed ranges for x and y as for Plot3D but we also have to prescribe a range for z. The range is important - only the part of the surface inside the range box will be displayed. So a blank picture will be displayed if the surface is outside the range box. Modify the command so that the x, y, z ranges are larger -see what happens. What is a good range for x, y and z. The various options for ContourPlot3D and Plot3D may be found through the Help facility of Mathematica. Explicitly drawn surfaces such as z = x2 + y 2 should always be drawn using Plot3D even though they may also be drawn using ContourPlot3D (using x2 + y 2 − z = 0) but Plot3D gives better pictures. Surfaces which are in explicit form or implicit form may often be rewritten in parametric form and pictures obtained using the parametric form are usually better. In addition, many surfaces can only be written in parametric form. Surfaces in parametric form are given as x = f (u, v), y = g(u, v), z = h(u, v),

a ≤ u ≤ b, c ≤ v ≤ d.

For example, the following parametric equation represents a torus x = (5 + 2 cos u) cos v, y = (5 + 2 cos u) sin v, z = 2 sin v, which may be plotted using ParametricPlot3D . 27

0 ≤ u ≤ 2π, 0 ≤ v ≤ 2π

ParametricPlot3D[ { (5 + 2 * Cos[u])*Cos[v], (5 + 2 * Cos[u])*Sin[v], 2*Sin[u] }, {u,0,2*Pi}, {v,0, 2*Pi}, AxesLabel -> {x,y,z} ] What happens if you reduce the ranges for u and v? Also, redraw the sketch with the reduced range and option PlotStyle -> Faceform[Red, Blue] . This allows us to see the inside and the outside of the shape.

5.3

Superimposing Pictures

Three dimensional pictures may be superimposed using the Show command. To observe the position of the curve t2 x = 250t , y = + 250t , z = 250t − 16t2 8 in relation to the planes z = (x + y)/10 and z = 0, we use curve = ParametricPlot3D[ { 250*t, (t^2)/8 + 250*t, 250*t - 16*t^2}, {t,0,16}, PlotStyle->{Red, AbsoluteThickness[3]} ] planes = Plot3D[ {0, (x+y)/10}, {x,0,4000}, {y,0,4000} ] Show[ {curve, planes} ] The first and the second commands defined two objects named curve and planes which contain the plots of the curve and the planes respectively. The last line displays the two pictures - superimposed. If you do not want to see the curve and the plane separately then place a semicolon ; at the end of the first two commands.

5.4

Plotting Regions

When computing triple integrals it is convenient to be able to draw a sketch of the solid region over which the integral is to be computed. For example, we may wish to draw the solid region which is above the x, y plane, below the plane x + y + z = 5 and bounded on the sides by the cylinders y = x2 and y = 2 − x2 . Some thought will show that we are plotting the solid region given by {(x, y, z) : z > 0, x + y + z < 5, y > x2 , y < 2 − x2 }. This solid may be plotted using the RegionPlot3D function. RegionPlot3D[ z>0

&&

x+y+z<5 && y>x^2 && y< 2-x^2 , {x,-1,1}, {y,0,2}, {z,-1,5}, AxesLabel -> {x,y,z} ]

The sketch is not very sharp; the sharpness can be improved by using the option PlotPoints -> 100 ; Mathematica will use 100 sample points along each axes. The ranges for x, y and z were chosen carefully - see what happens if you modify the ranges for x, y, z. 28

5.5

Summary of Section 5

ParametricPlot3d Plot3D ContourPlot3D Show RegionPlot3D

plot parametric curves and surfaces in three dimensions plot surfaces in the explicit form z = f (x, y) plot surfaces in the implicit form x2 + y 2 = z 2 + 8 to superimpose two or more three dimensional objects to draw three dimensional regions given by inequalities.

Exercise 5.1 Plot a solid which is a vertical circular cylinder with a conical hat on top and a hemisphere as its bottom. Take one unit to be the length of all the radii and heights. Exercise 5.2 Write the parametric equation of a torus i.e. a doughnut and then plot it using Maple.

29

mathematica tutorial.pdf

Page 1. Whoops! There was a problem loading more pages. mathematica tutorial.pdf. mathematica tutorial.pdf. Open. Extract. Open with. Sign In. Main menu.

289KB Sizes 0 Downloads 151 Views

Recommend Documents

wolfram mathematica tutorial collection pdf
wolfram mathematica tutorial collection pdf. wolfram mathematica tutorial collection pdf. Open. Extract. Open with. Sign In. Main menu. Displaying wolfram ...

wolfram mathematica tutorial pdf
wolfram mathematica tutorial pdf. wolfram mathematica tutorial pdf. Open. Extract. Open with. Sign In. Main menu. Displaying wolfram mathematica tutorial pdf.

Mathematica Data Visualization - Saquib Nazmus.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Mathematica ...

Philosophiae Naturalis Principia Mathematica ...
To practical mechanics all the manual arts belong, from which mechanics took its name. But as .... ISAAC NEWTON. Cambridge, Trinity College, May 8, 1686.

Mathematica, a problem-centered approach
Mathematica's abilities to do programming and solve problems. I could not find a book that I could follow to teach this .... 5.3 Decision making, If and Which .

Mathematica, a problem-centered approach
Mathematica's abilities to do programming and solve problems. ... It mainly concentrates on programming and problem solving in Mathe- matica. ..... Degree, 12.

Acta Mathematica Sinica, English Series - Springer Link
10, pp. 1637–1650. Published online: October 5, 2008 ... Linear mixed effects model is an important class of statistical models that are used in many fields.

wolfram mathematica 7.pdf
Sign in. Loading… Whoops! There was a problem loading more pages. Whoops! There was a problem previewing this document. Retrying... Download. Connect ...

philosophiae naturalis principia mathematica english pdf download ...
philosophiae naturalis principia mathematica english pdf download. philosophiae naturalis principia mathematica english pdf download. Open. Extract.

Acta Mathematica Academiae Paedagogicae Nyıregyháziensis 20 ...
sc respectively. These classes were introduced by El-Ashwah and Thomas[1]. The functions in these classes are close to convex and hence univalent. Sokol [11] introduced two more parameter in this class and obtained structural formula, the coefficient