12
H*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.*L H*01. Summation*L H*Example*L H*Find the sum of all the odd numbers from 1 to 99 inclusive.*L Sum@i, 8i, 1, 99, 2<D H*Here i starts at 1, ends at 99 and increment every time is 2*L 2500 H*Example*L H*Find the sum of the infinite series: 12 + 14 + 18 + ...*L Sum@1 2^i, 8i, 1, Infinity<D H*Increment is by 1, so no need to specify. Even if you do, you will get the same result.*L 1 H*02. Product*L H*Example*L H*Find the product of the first 10 prime numbers*L Product@Prime@iD, 8i, 1, 10<DH*Prime@iD returns the i'th prime number. The increment is by default 1.*L 6469693230 H*Example*L H*Compute the product H12LH23LH34LH45LH56L... H9899LH99100L*L Product@i Hi + 1L, 8i, 1, 99<D 1 100 H*Example*L H*Compute the product of all the even numbers between 1 and 21*L Product@i, 8i, 2, 20, 2<D H*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.*L 3715891200 H*03. Simplification and Solving equations*L

Mathematica lab review

  • Upload
    ojomojo

  • View
    51

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Mathematica lab review

H*This is a file to help you prepare for the lab finalexam. Please go through all the Mathematica functionsused here. All of them will be tested in your exam. Don't hesitate to contact me at nakib.mojojojo�gmail.comor protik�bracu.ac.bd in case you face problems.*L

H*01. Summation*LH*Example*LH*Find the sum of all the odd numbers from 1 to 99 inclusive.*LSum@i, 8i, 1, 99, 2<D H*Here i starts at 1,ends at 99 and increment every time is 2*L

2500

H*Example*LH*Find the sum of the infinite series: 1�2 + 1�4 + 1�8 + ...*L

Sum@1�2^i, 8i, 1, Infinity<D H*Increment is by 1,so no need to specify. Even if you do,you will get the same result.*L

1

H*02. Product*LH*Example*LH*Find the product of the first 10 prime numbers*LProduct@Prime@iD, 8i, 1, 10<DH*Prime@iD returns thei'th prime number. The increment is by default 1.*L

6469693230

H*Example*LH*Compute the product H1�2LH2�3LH3�4LH4�5LH5�6L...

H98�99LH99�100L*LProduct@i� Hi + 1L, 8i, 1, 99<D

1

100

H*Example*LH*Compute the product of all the even numbers between 1 and 21*LProduct@i, 8i, 2, 20, 2<DH*The starting value is 2 because this is the first even numberin the range. The last even number is 20. The incrementis 2 because even numbers progress at steps of 2.*L

3715891200

H*03. Simplification and Solving equations*L

Page 2: Mathematica lab review

H*Example*L

H*Simplify 2 + 8 + 18 *LSqrt@2D + Sqrt@8D + Sqrt@18D

6 2

H*Example*L

H*Express Π to 20 significant digits*L

N@Sqrt@PiD, 20D H*N@expression, accuracyD computes thenumerical value of the expression to the mentioned accuracy.*L

1.7724538509055160273

H*Example*L

H*Find an algebraic expression for cosJsin-1J x2

x2 + 1NN*L

Cos@ArcSin@Hx^2L � Hx^2 + 1LDD

1 -x4

H1 + x2L2

H*Example*LH*Compute the product of the natural logarithms

Hbase eL of the integers from 2 through 20,obtaining an approximation of 20 significant digits*LN@Product@Log@iD, 8i, 2, 20<D, 20DH*Carefully notice the way this problem has been solved.*L

1.3632878207490815857´106

H*Example*LH*Compute the product of the base 10logarithms of the integers from 2 through 20,

obtaining an approximation of 20 significant digits*LN@Product@Log@10, iD, 8i, 2, 20<D, 20DH*Notice carefully how the base of log can bechanged. Log@b, xD gives you the value of base 10 log of x.*L

0.17885021623800023677

2 mathematica_lab_review.nb

Page 3: Mathematica lab review

H*Example*L

H*Solve the algebraic equation x3 - 2x2 + 1 = 0*LSolve@x^3 - 2*x^2 + 1 � 0D H*Notice carefully the use of �

when writing equations in Mathematica.*L

:8x ® 1<, :x ®1

2I1 - 5 M>, :x ®

1

2I1 + 5 M>>

H*Notice that a cubic equation is supposed to produce threesolutions. Each solution appears in Mathematica as elementsof a list characterized by the use of curly brackets 8<.*L

H*Example*LH*Solve the simultaneous equations 3x + 4y = 10 and x + 3y = 20*L

Solve@83*x + 4* y � 10, x + 3* y � 20<, 8x, y<DH*Notice the use of curly brackets todefine all lists. 8x, y< specifies which variableMathematica should solve the equations for.*L

88x ® -10, y ® 10<<

H*Example*LH*Solve the following equation numerically to 25

significant figures: x4 - 16x3 + 61x2 - 22x - 12 = 0*L

NSolve@x^4 - 16*x^3 + 61*x^2 - 22*x - 12 � 0, 25D

88x ® -0.2915026221291811810032315<,8x ® 0.7639320225002103035908263<,8x ® 5.236067977499789696409174<, 8x ® 10.29150262212918118100323<<

H*2D Graph Plotting*LH*Example*L

H*Plot the fHxL = x3 from -3 to 3.*LPlot@x^3, 8x, -3, 3<D

Out[3]=-3 -2 -1 1 2 3

-20

-10

10

20

H*Example*L

mathematica_lab_review.nb 3

Page 4: Mathematica lab review

In[4]:= H*Plot fHxL = cosHxL and gHxL = sinHxL from -2Π to 2Π,HiL separately HiiL in the same diagram.*Lg1 = Plot@Cos@xD, 8x, -2*Pi, 2*Pi<D

Out[4]=-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

In[5]:= g2 = Plot@Sin@xD, 8x, -2*Pi, 2*Pi<D

Out[5]=-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

4 mathematica_lab_review.nb

Page 5: Mathematica lab review

Show@g1, g2D H*Show@D command canbe used to plot to named graphs together.*L

Out[6]=-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

H*3D Graph Plotting*LH*Example*LH*Plot fHx,yL = xcosHyL and gHx,yL =

ysinHxL in a cubical box with x and y going from -

5 to 5 HiL separately HiiL in the same graph.*L

In[8]:= p1 = Plot3D@x*Cos@yD, 8x, -5, 5<,8y, -5, 5<, BoxRatios ® 81, 1, 1<D

Out[8]=

mathematica_lab_review.nb 5

Page 6: Mathematica lab review

In[9]:= p2 = Plot3D@y*Sin@xD, 8x, -5, 5<,8y, -5, 5<, BoxRatios ® 81, 1, 1<D

Out[9]=

6 mathematica_lab_review.nb

Page 7: Mathematica lab review

In[10]:= Show@p1, p2D

Out[10]=

mathematica_lab_review.nb 7

Page 8: Mathematica lab review

In[11]:= H*Example*LH*Plot the above functions in thesame graph and label the axes x, y, z.*L

Show@p1, p2, AxesLabel ® 8"x", "y", "z"<D

Out[11]=

In[12]:=

H*Limits and Derivatives*LH*Example*LH*Find the limit of x �x as x tends to 0.*LLimit@Abs@xD �x, x ® 0D

Out[12]= 1

H*Example*LH*Find the limit of ex as x tends to -¥.*LLimit@E^x, x ® -InfinityD

Out[13]= 0

8 mathematica_lab_review.nb

Page 9: Mathematica lab review

In[14]:= H*Example*L

H*Find the limit of tan-1HxL as x tends to ¥*LLimit@ArcTan@xD, x ® InfinityD

Out[14]=

Π

2

In[15]:= H*Example*LH*Define the function fHxL =

2x6 + 5x3 - x2 + 9 and find the HiL first derivativeHiiL third derivative HiiiL seventh derivative.*L

f@x_D := 2*x^6 + 5*x^3 - x^2 + 9

f'@xD H*for 1st derivative*L

Out[16]= -2 x + 15 x2 + 12 x5

In[17]:= f'''@xD H*for 3rd derivative*L

Out[17]= 30 + 240 x3

In[18]:= D@f@xD, 8x, 7<D H*I could have used the f'@xD notation,but it is easier to write it likethis when we need high order derivatives*L

Out[18]= 0

H*Example <- VERY IMPORTANT*LH*Let fHxL = cosHxL,sketch the graph and its tangent line at a = Π�7.*L

In[23]:= f@x_D := Cos@xD H*Define the function*L

In[24]:= a := Pi�7 H*Define the constant a*L

In[25]:= t@x_D := f@aD + f'@aD * Hx - aL H*Equation of the tangent,see class notes for the detailed derivation*L

mathematica_lab_review.nb 9

Page 10: Mathematica lab review

In[26]:= Plot@8f@xD, t@xD<, 8x, -2*Pi, 2*Pi<DH*Plot both in the same graph*L

Out[26]=

-6 -4 -2 2 4 6

-1

1

2

3

H*Maclaurin and Taylor series*LH*Example*LH*Find the Maclaurin Polynomial of degree 10

for the funtion jHxL = tan-1HxL. Evaluate jH12.5L*Lj@x_D := ArcTan@xD

Series@j@xD, 8x, 0, 10<D �� NormalH*the ��Normal command is used to remove the O

HnL term. You can't evaluate jHaL with this term.*L

Out[28]= x -x3

3+x5

5-x7

7+x9

9

In[30]:= [email protected]

Out[30]= 1.49097

H*Example*LH*Find the Taylor Polynomial of degree 5 for the funtion kHxL =

ex at x = 2. Evaluate kH53.54L.*Lk@x_D := E^x

In[34]:= Series@k@xD, 8x, 2, 5<D �� NormalH*Notice how things are written here inside the curly brackets.*L

Out[34]= ã2 + ã2 H-2 + xL +1

2ã2 H-2 + xL2 +

1

6ã2 H-2 + xL3 +

1

24ã2 H-2 + xL4 +

1

120ã2 H-2 + xL5

In[35]:= [email protected]

Out[35]= 1.78701´1023

10 mathematica_lab_review.nb

Page 11: Mathematica lab review

In[37]:=

H*Integral calculus*LH*Example*L

H*Calculate Ù Ib2 + x2Mâx*L

Integrate@b^2 + x^2, xD

Out[37]= b2 x +x3

3

H*Example*L

H*Calculate Ù-5

5I5x + x2Mâx*L

In[39]:= Integrate@5*x + x^2, 8x, -5, 5<D

Out[39]=

250

3

In[40]:=

H*Ordinary Differential Equation*LH*Example*LH*Solve the equation y' =

x + y with initial condition yH0L = 2.*LDSolve@8y'@xD � x + y@xD, y@0D � 2<, y@xD, xD

Out[40]= 88y@xD ® -1 + 3 ãx - x<<

H*Example*LH*Numerically solve the equation y' =

xy with initial condition yH1L =

2 and the graph the solution for -2 to 2.*L

In[41]:= eq1 = NDSolve@8y'@xD � x* y@xD, y@1D � 2<, y@xD, 8x, -2, 2<D

Out[41]= 88y@xD ® InterpolatingFunction@88-2., 2.<<, <>D@xD<<

mathematica_lab_review.nb 11

Page 12: Mathematica lab review

In[42]:= Plot@y@xD �. eq1, 8x, -2, 2<D

Out[42]=

-2 -1 1 2

4

6

8

H*I hope you will all get full scores in the test. All the best!*L

12 mathematica_lab_review.nb