Docsity

Mathematica Basics II - Mathematics Computer - Lab 2 | MATH 1200, Lab Reports of Mathematics

Toggle sidebar
bg1
Mathematics Computer Laboratory - Math 1200
Lab 2 - Mathematica Basics II
1. The Mathematics computer lab is located in Bldg 4, Rm 505. All computers in this lab have access to
the latest version of Mathematica. All other PC computer labs should also have access to this software.
2. Here is how to get on Mathematica:
Get on a computer. (Some machines may require a log in process. Instruction and help should be
available in the labs.) Move the mouse pointer to the
Mathematica icon
, which looks like the above
star like symbol, and rapidly
click twice
using the
left mouse button
.
3. Recall that the
Evaluation
(Execution) key command is the
Enter
key on the number pad and not
,
j
key on the main keyboard. Also remember that you should input the statements in
True Type
font
exactly as is
!
Mathematica has three symbols for equality; let's try each one in the next three parts.
4. Replacement. A single equal sign indicates replacements. Type in the following and then evaluate them
by pushing the
Enter
key.
x = 5; y = 12; z = a + b;
Enter all of them in just one cell; you may enter each on a separate line or all on one line. If you type in
more than one on the same line, be sure to separate them by semicolons. The nal semicolon in a line
suppresses the nal output. If you have used all the semicolons, you should not get any output! Now
evaluate the following.
(a)
x
(This should give the assigned value of
x
which is 5 .)
(b)
z
(This should give the expression that
z
stands for:
a
+
b
.)
(c)
x y^2
(Remember to insert the space between
x
and
y
to indicate a product.)
(d)
Expand[z^x]
(This is (
a
+
b
)
5
.)
5. The assignments for
x
,
y
and
z
are permanent; this means that to reuse these variables for something
else requires that they rst be \cleared". Type in the following and evaluate it.
(a)
Clear[x,y,z]
(b)
x
(You should get
x
and not its previous value of 5.)
It is a good idea to clear each variable after its use, otherwise its reuse will give unintended results.
6. Input each part in one cell and evaluate it.
(a)
f=x^2+3x+2; g=(2x+3)(5x-2);h=2/(x-3)-1/(x-1);k=(x+5)/((x+2)(x+3));
(As before, you may
enter them on one or more lines.)
(b)
f
(If the output is a number, you have forgotten to clear the variable
x
in the last step.)
(c)
Factor[f]
pf3
pf4

Partial preview of the text

Download Mathematica Basics II - Mathematics Computer - Lab 2 | MATH 1200 and more Lab Reports Mathematics in PDF only on Docsity!

Mathematics Computer Lab oratory - Math 1200 Lab 2 - Mathematica Basics I I

  1. The Mathematics computer lab is lo cated in Bldg 4, Rm 505. All computers in this lab have access to the latest version of Mathematica. All other PC computer labs should also have access to this software.
  2. Here is how to get on Mathematica: Get on a computer. (Some machines may require a log in pro cess. Instruction and help should b e available in the labs.) Move the mouse p ointer to the Mathematica icon, which lo oks like the ab ove star like symb ol, and rapidly click twice using the left mouse button.
  3. Recall that the Evaluation (Execution) key command is the Enter key on the numb er pad and not j^ key on the main keyb oard. Also rememb er that you should input the statements in True Type font exactly as is! Mathematica has three symb ols for equality; let's try each one in the next three parts.
  4. Replacement. A single equal sign indicates replacements. Typ e in the following and then evaluate them by pushing the Enter key.

x = 5; y = 12; z = a + b;

Enter all of them in just one cell; you may enter each on a separate line or all on one line. If you typ e in more than one on the same line, b e sure to separate them by semicolons. The nal semicolon in a line suppresses the nal output. If you have used all the semicolons, you should not get any output! Now evaluate the following.

(a) x (This should give the assigned value of x which is 5 .) (b) z (This should give the expression that z stands for: a + b .) (c) x y^2 (Rememb er to insert the space b etween x and y to indicate a pro duct.) (d) Expand[z^x] (This is (a + b)^5 .)

  1. The assignments for x , y and z are p ermanent; this means that to reuse these variables for something else requires that they rst b e \cleared". Typ e in the following and evaluate it.

(a) Clear[x,y,z] (b) x (You should get x and not its previous value of 5 .) It is a go o d idea to clear each variable after its use, otherwise its reuse will give unintended results.

  1. Input each part in one cell and evaluate it.

(a) f=x^2+3x+2; g=(2x+3)(5x-2);h=2/(x-3)-1/(x-1);k=(x+5)/((x+2)(x+3)); (As b efore, you may enter them on one or more lines.) (b) f (If the output is a numb er, you have forgotten to clear the variable x in the last step.) (c) Factor[f]

  1. Continued. (d) Expand[g] (e) Together[h] (f ) Apart[k] (g) Clear[f,g,h,k]
  2. In Mathematica, an equation is denoted by using two equal signs. For example, the equation 3x+2==x- represents the equation 3 x + 2 = x 5. You can nd exact solutions of many equations using the function Solve. Typ e in and evaluate each of the following. The solution is given as a replacement value for the variable (fx! answerg).

(a) Solve[3x-8==4] (If the output is an empty set, either this equation has no solution or you have forgotten to clear the value of x earlier. Check you answer.) (b) Solve[z^2+2z==-2] (Did you clear z earlier? What typ e of numb ers are the solutions? When do es a quadratic equation have two complex conjugate solutions?) (c) Solve[a t-2==3a, t] The t after the comma indicates that the equation should b e solved for t and not a. Simplify your answer; (Simplify[%]).

  1. Input each part in one cell and evaluate it.

(a) f = x^2-3x-4; Solve[f==0] (This solves the equation f = 0 where f = x^2 3 x 4. Check your answers.) (b) Clear[f] (c) g = 1/(x-2); h = 4/(x+1); (d) Solve[g==h] (This solves the equation (^) x^12 =^ x+1^4 .) (e) Clear[g,h]

  1. The Solve function can also b e used to solve systems of equations. Input each part in one cell and evaluate it.

(a) Solve[{x-2y==4,x-1==5y}, {x,y}] This is the 2  2 linear system of equations: x 2 y = 4 and x 1 = 5 y. To solve two or more equations simultaneously, enter the equations and the variables you want to solve for as lists. In Mathematica's syntax a list is any collection of terms separated by commas and group ed by braces. (b) Solve[{3x-4y==4,x+2y==7}, {x,y}] (c) f = 2x+y; g = 5x+2y; (d) Solve[{f==2, g==3},{x,y}] (This solves the system of equations 2 x + y = 2 and 5 x + 2 y = 3 .) (f ) Clear[f,g]

  1. It might not b e p ossible or even desirable to nd exact solutions to certain equations. You can nd numerical approximation of solutions of most equations using the NSolve function. Typ e in and evaluate each of the following. (a) NSolve[2x-3==x^2-3x-4] (b) NSolve[2x-3==x^2-3x-4, x] (Did you get the same answer as in part a?) (c) NSolve[{x^2+y^2==16, y==x^2-2x+2}, {x,y}]
  1. You can plot two or more functions on the same co ordinate system. Input each part in one cell and evaluate it.

(a) f[x_]:=-x^2+4x+5; g[x_]:=E^(x) (b) Plot[{f[x], g[x]}, {x,-2,4}] To graph two or more functions on the same co ordinate system, enter them as \lists" which means group ed in braces and separated by commas. (c) Read o the co ordinates of their two p oints of intersections. (Click on the graph, hold down the Ctrl key (the Alt key or equivalent on some machines) and move the cursor over to p oints of intersection) (d) NSolve[f[x]==g[x]] Notice that Mathematica can not solve this equation using the NSolve command, but you were able to read o approximate solutions using the graph in part c. (e) Clear[f,g]

Now use Mathematica and what you have learned so far in the following exercises.

A. Input the expressions f = x x+1^1 ^ x x+1 1 ,^ g^ =^ ^2 x^4 ^11 x^3 ^16 x^2 ^ x^ +^5 and^ h^ =^ (x2)(2^4 x+1x+3).

(i) Simplify the expression named f. (Use the Simplify function.) (ii) Rewrite f as a single fraction. (Use the Together function.) (iii) Are the answers in the last two parts equivalent? if not, what is the di erence? (iv) Factor g. (v) Rewrite h as sum or di erence of two fractions. (Use the Apart function.) (vi) Clear the variables f , g and h.

B. Solve the following equations using b oth Solve and NSolve functions.

(i) 15 x^4 38 x + 7 = 38 x^3 22 x^2 (ii) The system 2 x = 7 y 4 and 3 x + 2 y = 6. (iii) The system y = x^2 3 x 4 and y + x = 6 x^2.

C. Input the expressions f (x) = x x+1 1 and^ g^ (x)^ =^ x^2 ^2 x^ +^3 and^ p^ erform^ the^ following^ steps.

(i) Draw the graph of y = f (x) form x = 1 to x = 3. (ii) Draw the graphs of y = f (x) and y = g (x) on the same co ordinate system with the same domain. (iii) Redraw these graphs by cho osing an appropriate short domain so that the p oint of intersection of the two graphs is clearly visible. (iv) Read o the co ordinates of the p oint of intersection. (v) Solve the equation f (x) = g (x). Compare the real solution of this equation with the x-co ordinate of the p oint of intersection. (vi) Clear the two functions.

  1. It is essential, b oth as a courtesy to future users, and to continued problem-free usage, to leave the computers as you nd them. When you are done, close the software b eing used and/or log o prop erly.