You are on page 1of 12

(+This is a file to help you prepare for the lab final

exam. Please go through all the Mathematica functions


used here. All of them will be tested in your exam. Don'
t hesitate to contact me at nakib.mojojojogmail.com
or protikbracu.ac.bd in case you face problems.+)
(+01. Summation+)
(+Example+)
(+Find the sum of all the odd numbers from 1 to 99 inclusive.+)
Sum[i, {i, 1, 99, 2}] (+Here i starts at 1,
ends at 99 and increment every time is 2+)
2500
(+Example+)
(+Find the sum of the infinite series: 1/2 + 1/4 + 1/8 + ...+)
Sum[1/2^i, {i, 1, Infinity}] (+Increment is by 1,
so no need to specify. Even if you do,
you will get the same result.+)
1
(+02. Product+)
(+Example+)
(+Find the product of the first 10 prime numbers+)
Product[Prime[i], {i, 1, 10}](+Prime[i] returns the
i'th prime number. The increment is by default 1.+)
6469693230
(+Example+)
(+Compute the product (1/2)(2/3)(3/4)(4/5)(5/6)...
(98/99)(99/100)+)
Product[i/(i + 1), {i, 1, 99}]
1
100
(+Example+)
(+Compute the product of all the even numbers between 1 and 21+)
Product[i, {i, 2, 20, 2}]
(+The starting value is 2 because this is the first even number
in the range. The last even number is 20. The increment
is 2 because even numbers progress at steps of 2.+)
3715891200
(+03. Simplification and Solving equations+)
(+Example+)
(+Simplify 2 + 8 + 18 +)
Sqrt[2] + Sqrt[8] + Sqrt[18]
6 2
(+Example+)
(+Express to 20 significant digits+)
N[Sqrt[Pi], 20] (+N[expression, accuracy] computes the
numerical value of the expression to the mentioned accuracy.+)
1.7724538509055160273
(+Example+)
(+Find an algebraic expression for cos]sin
-1
]
x
2
x
2
+ 1
+)
Cos[ArcSin[(x^2)/(x^2 + 1)]]
1
x
4
(1 x
2
)
2
(+Example+)
(+Compute the product of the natural logarithms
(base e) of the integers from 2 through 20,
obtaining an approximation of 20 significant digits+)
N[Product[Log[i], {i, 2, 20}], 20]
(+Carefully notice the way this problem has been solved.+)
1.363287820749081585710
6
(+Example+)
(+Compute the product of the base 10
logarithms of the integers from 2 through 20,
obtaining an approximation of 20 significant digits+)
N[Product[Log[10, i], {i, 2, 20}], 20]
(+Notice carefully how the base of log can be
changed. Log[b, x] gives you the value of base 10 log of x.+)
0.17885021623800023677
2 mathematica_lab_review.nb
(+Example+)
(+Solve the algebraic equation x
3
- 2x
2
+ 1 = 0+)
Solve[x^3 - 2+x^2 + 1 = 0] (+Notice carefully the use of =
when writing equations in Mathematica.+)
{x 1], x
1
2
1 5 , x
1
2
1 5
(+Notice that a cubic equation is supposed to produce three
solutions. Each solution appears in Mathematica as elements
of a list characterized by the use of curly brackets {}.+)
(+Example+)
(+Solve the simultaneous equations 3x + 4y = 10 and x + 3y = 20+)
Solve[{3+x + 4+ y = 10, x + 3+ y = 20}, {x, y}]
(+Notice the use of curly brackets to
define all lists. {x, y} specifies which variable
Mathematica should solve the equations for.+)
{{x 10, y 10]]
(+Example+)
(+Solve the following equation numerically to 25
significant figures: x
4
- 16x
3
+ 61x
2
- 22x - 12 = 0+)
NSolve[x^4 - 16+x^3 + 61+x^2 - 22+x - 12 = 0, 25]
{{x 0.2915026221291811810032315],
{x 0.7639320225002103035908263],
{x 5.236067977499789696409174], {x 10.29150262212918118100323]]
(+2D Graph Plotting+)
(+Example+)
(+Plot the f(x) = x
3
from -3 to 3.+)
Plot[x^3, {x, -3, 3}]
Out[3]=
3 2 1 1 2 3
20
10
10
20
(+Example+)
mathematica_lab_review.nb 3
In[4]:= (+Plot f(x) = cos(x) and g(x) = sin(x) from -2 to 2,
(i) separately (ii) in the same diagram.+)
g1 = Plot[Cos[x], {x, -2+Pi, 2+Pi}]
Out[4]=
6 4 2 2 4 6
1.0
0.5
0.5
1.0
In[5]:= g2 = Plot[Sin[x], {x, -2+Pi, 2+Pi}]
Out[5]=
6 4 2 2 4 6
1.0
0.5
0.5
1.0
4 mathematica_lab_review.nb
Show[g1, g2] (+Show[] command can
be used to plot to named graphs together.+)
Out[6]=
6 4 2 2 4 6
1.0
0.5
0.5
1.0
(+3D Graph Plotting+)
(+Example+)
(+Plot f(x,y) = xcos(y) and g(x,y) =
ysin(x) in a cubical box with x and y going from -
5 to 5 (i) separately (ii) in the same graph.+)
In[8]:= p1 = Plot3D[x+Cos[y], {x, -5, 5},
{y, -5, 5}, BoxRatios - {1, 1, 1}]
Out[8]=
mathematica_lab_review.nb 5
In[9]:= p2 = Plot3D[y+Sin[x], {x, -5, 5},
{y, -5, 5}, BoxRatios - {1, 1, 1}]
Out[9]=
6 mathematica_lab_review.nb
In[10]:= Show[p1, p2]
Out[10]=
mathematica_lab_review.nb 7
In[11]:= (+Example+)
(+Plot the above functions in the
same graph and label the axes x, y, z.+)
Show[p1, p2, AxesLabel - {"x", "y", "z"}]
Out[11]=
In[12]:=
(+Limits and Derivatives+)
(+Example+)
(+Find the limit of x /x as x tends to 0.+)
Limit[Abs[x]/x, x - 0]
Out[12]= 1
(+Example+)
(+Find the limit of e
x
as x tends to -.+)
Limit[E^x, x - -Infinity]
Out[13]= 0
8 mathematica_lab_review.nb
In[14]:= (+Example+)
(+Find the limit of tan
-1
(x) as x tends to +)
Limit[ArcTan[x], x - Infinity]
Out[14]=

2
In[15]:= (+Example+)
(+Define the function f(x) =
2x
6
+ 5x
3
- x
2
+ 9 and find the (i) first derivative
(ii) third derivative (iii) seventh derivative.+)
f[x_] := 2+x^6 + 5+x^3 - x^2 + 9
f'[x] (+for 1st derivative+)
Out[16]= 2 x 15 x
2
12 x
5
In[17]:= f'''[x] (+for 3rd derivative+)
Out[17]= 30 240 x
3
In[18]:= D[f[x], {x, 7}] (+I could have used the f'[x] notation,
but it is easier to write it like
this when we need high order derivatives+)
Out[18]= 0
(+Example <- VERY IMPORTANT+)
(+Let f(x) = cos(x),
sketch the graph and its tangent line at a = /7.+)
In[23]:= f[x_] := Cos[x] (+Define the function+)
In[24]:= a := Pi/7 (+Define the constant a+)
In[25]:= t[x_] := f[a] + f'[a]+(x - a) (+Equation of the tangent,
see class notes for the detailed derivation+)
mathematica_lab_review.nb 9
In[26]:= Plot[{f[x], t[x]}, {x, -2+Pi, 2+Pi}]
(+Plot both in the same graph+)
Out[26]=
6 4 2 2 4 6
1
1
2
3
(+Maclaurin and Taylor series+)
(+Example+)
(+Find the Maclaurin Polynomial of degree 10
for the funtion j(x) = tan
-1
(x). Evaluate j(12.5)+)
j[x_] := ArcTan[x]
Series[j[x], {x, 0, 10}] // Normal
(+the //Normal command is used to remove the O
(n) term. You can't evaluate j(a) with this term.+)
Out[28]= x
x
3
3

x
5
5

x
7
7

x
9
9
In[30]:= j[12.5]
Out[30]= 1.49097
(+Example+)
(+Find the Taylor Polynomial of degree 5 for the funtion k(x) =
e
x
at x = 2. Evaluate k(53.54).+)
k[x_] := E^x
In[34]:= Series[k[x], {x, 2, 5}] // Normal
(+Notice how things are written here inside the curly brackets.+)
Out[34]=
2

2
(2 x)
1
2

2
(2 x)
2

1
6

2
(2 x)
3

1
24

2
(2 x)
4

1
120

2
(2 x)
5
In[35]:= k[53.54]
Out[35]= 1.7870110
23
10 mathematica_lab_review.nb
In[37]:=
(+Integral calculus+)
(+Example+)
(+Calculate
]
[b
2
+ x
2
|dx+)
Integrate[b^2 + x^2, x]
Out[37]= b
2
x
x
3
3
(+Example+)
(+Calculate
]
-5
5
[5x + x
2
|dx+)
In[39]:= Integrate[5+x + x^2, {x, -5, 5}]
Out[39]=
250
3
In[40]:=
(+Ordinary Differential Equation+)
(+Example+)
(+Solve the equation y' =
x + y with initial condition y(0) = 2.+)
DSolve[{y'[x] = x + y[x], y[0] = 2}, y[x], x]
Out[40]= {{y[x] 1 3
x
x]]
(+Example+)
(+Numerically solve the equation y' =
xy with initial condition y(1) =
2 and the graph the solution for -2 to 2.+)
In[41]:= eq1 = NDSolve[{y'[x] = x+ y[x], y[1] = 2}, y[x], {x, -2, 2}]
Out[41]= {{y[x] InterpolatingFunction[{{2., 2.]], ][x]]]
mathematica_lab_review.nb 11
In[42]:= Plot[y[x] /. eq1, {x, -2, 2}]
Out[42]=
2 1 1 2
4
6
8
(+I hope you will all get full scores in the test. All the best!+)
12 mathematica_lab_review.nb

You might also like