# Mathematica Instructions

Here are instructions on how to use Mathematica for Calculus II:

Introductory Instructions:

2. For basic mathematica usage instructions; using mathematica for algebra; using mathematica for precalculus; using mathematica for calculus I:

Section 5.2

1. Evaluating sums (e.g., sum of i from 1 to n)
• `Sum[i, {i, 1, n}]`
2. Evaluating Riemann sums
1. Store integrand into f(x) using: `f[x_]:=function`
2. Store Δx into variable dx using: `dx=(b-a)/n` – where a is lower limit of integration and b is upper limit of integration
3. Find xi and store into variable xi using: `xi=expression`
4. Evaluate the sum and store into sum variable: `sum = Sum[f[xi]*dx,{i,1,n}]`
5. Evaluate the limit of the sum as n → ∞: `Limit[sum, n -> Infinity]`
3. Graphing Riemann sums
• See Project 1:

Section 5.2 & 5.3:

1. Evaluating definite integrals
• Define function as f[x_] (see above), then use: `Integrate[f[x], {x, a, b}]`
note: where a is the lower limit of integration and b is the upper limit of integration; OR
• `Integrate[expression, {x, a, b}]`
note: `NIntegrate` can be used to find an approximation of the definite integral
2. Shading area under the curve
• Define function as f[x_] (see above), then use: `Plot[f[x], {x, a, b}, Filling -> Axis, FillingStyle -> Hue[d]]`
note: where [ab] is a subset of the domain; and 0 ≤ d ≤ 1.

Section 5.4:

1. Fundamental Theorem of Calculus, Part 1 (FTC1)
• Define function as f[t_] as function (see above), then use: `D[Integrate[f[t], {t, 1, g(x)}], x]` – where g(x) is some function of x

Section 5.7 & Appendix G:

1. Partial Fractions
• Define rational function as f[x_] as function (see above), then use: `Apart[[f[x]]]`
2. Solving Systems of Equations [needed to algebraically find partial fractions]
• To solve the system, expr1 = a, expr2 = b, expr3 = c, etc, use: `Solve[{expr1, expr2, expr3} == {a, b, c}]`
NOTE: You must have the same number of equations as variables; and the order of the variables in each expression is not important.

Section 5.9:

1. Approximate Integration
• See Project 1:

Section 5.10:

1. Improper Integrals
1. Infinite Intervals:
• Formal Method: Use Limit function
• `Limit[Integrate[f[x], {x, a, b}], a -> -Infinity]` where b is the value for the upper limit of integration
• `Limit[Integrate[f[x], {x, a, b}], b -> Infinity]` where a is the value for the lower limit of integration
• NOTE: If a = –∞ and b = ∞, then you need to split the integral into two different integrals using x = c and use both of the above improper integrals
NOTE: If Mathematica returns a number, then the improper integral converged to that number; if Mathematica returns either –∞ or ∞, then the improper integral diverged.
• Informal Method: Use Integrate function directly
• `Integrate[f[x], {x, a, b}]` where a = –∞, b = ∞, or both
• NOTE: If Mathematica returns a number, then the improper integral converged to that number; if Mathematica returns an error message including the phrase "does not converge on", then the improper integral diverged.
2. Discontinuous Integrands:
• Formal Method: Use Limit function
• `Limit[Integrate[f[x], {x, a, b}], a -> c, Direction -> -1]` where f(x) is not continuous at x = c and b is the value for the upper limit of integration
• `Limit[Integrate[f[x], {x, a, b}], b -> c, Direction -> 1]` where f(x) is not continuous at x = c and a is the value for the lower limit of integration
• NOTE: If f(x) is not continuous at x = d for some d in the interval (ab), then you need to split the integral into two different integrals using x = d and use both of the above improper integrals
NOTE: If Mathematica returns a number, then the improper integral converged to that number; if Mathematica returns either –∞ or ∞, then the improper integral diverged.
• Informal Method: Use Integrate function directly
• `Integrate[f[x], {x, a, b}]` where f(x) is not continuous at x = a, x = b, or x = d in the interval (ab)
• NOTE: If Mathematica returns a number, then the improper integral converged to that number; if Mathematica returns an error message including the phrase "does not converge on", then the improper integral diverged.

Section 6.1:

1. Shading area between two curves
• Define function as f[x_] and g[x_] (see above), then use: `Plot[{f[x], g[x]}, {x, xmin, xmax}, Filling -> {1 -> {{2}, Hue[d]}}]`
note: where [ab] is a subset of the domain; 0 ≤ d ≤ 1; and only change the value for d in the `Filling` option (i.e., do not change the 1 and 2 in the `Filling` option)
2. Plot two functions of y
• Define function as f[y_] and g[y_] (see above), then use: `ContourPlot[{x == f[y], x == g[y]}, {x, xmin, xmax}, {y, ymin, ymax}, Frame -> False, Axes -> True]`
3. Find the intersection(s) of two functions of y
• Define function as f[y_] and g[y_] (see above), then use: `Solve[f[y] == g[y], y]`
• note: To find the x-coordinates, evaluate f(y) at each value calculated above

Appendix H:

1. Plotting polar curves
• Define function as r[t_] (see above), then use: `PolarPlot[r[t], {t, tmin, tmax}]`
• Plotting polar curve, θ = a
• Convert to cartesian equation
2. Plot two polar curves
• Define function as r1[t_] and r2[t_] (see above), then use: `PolarPlot[{r1[t],r2[t]}, {t, tmin, tmax}]`
3. Find the intersection(s) of two polar curves
• Define function as r1[t_] and r2[t_] (see above), then use: `Solve[r1[t] == r2[t], t]`
4. Plot a polar curve along with a cartesian equation
• Define variable plot1 using: `plot1 = PolarPlot[r1[t], {t, tmin, tmax}]`
• Define variable plot2 using: `plot2 = Plot[f[x], {x, xmin, xmax}]`
• Use: `Show[plot1, plot2]`

Section 7.1:

1. Find the general solution to differential equation
• Store y′ into variable eqn using: `eqn = y'[t] == f[t, y]` where f[t, y] is the differential equation
Note: Make sure to use y[t] for every dependent variable
• Solve for y using: `y[t]/.DSolve[eqn, y[t], t]`
2. Solve Initial-Value Problem
• Store y′ into variable eqn using: `eqn = y'[t] == f[t, y]` where f[t, y] is the differential equation
Note: Make sure to use y[t] for every dependent variable
• Solve for y using: `y[t]/.DSolve[{eqn, y[a]==b}, y[t], t]` where y(a) = b is the initial condition

Section 7.2:

1. Plotting direction field for y′ = f(xy)
• `VectorPlot[{1, f[x, y]}, {x, xmin, xmax}, {y, ymin, ymax}, Axes -> True]`
2. Euler's method
• See Project __

Section 7.3:

1. Solving Separable Equations
• `DSolve[y'[x] == f[x, y], y[x], x]` where f[x, y] is the separable equation

Section 8.1:

1. Sequences
• List first i terms given an, using: `Table[a_n, {n, nmin, i}]` where a_n is the nth term and i is the number of terms desired
2. Plot Sequences
• `ListPlot[Table[a_n, {n, nmin, i}]]` where a_n is the nth term and i is the number of terms desired
Note: You can use the option `PlotRange -> {ymin, ymax}` to keep the y-values of the plot constant
3. Evalaute the Limit of Sequences as n → ∞
• `Limit[a_n, n -> Infinity]` where a_n is the nth term

Section 8.2:

1. Series
• Evaluate the sum of the first i terms of a series given an, using: `Sum[a_n, {n, 1, i}]` where a_n is the nth term and i is the number of terms desired
2. Find the partial sums, Si, of a series
• `Table[Sum[a_n, {n, 1, k}], {k, 1, i}]` where a_n is the nth term and i is the number of sums desired
Note: For decimal output, use `//N` after the Table function
3. Plot Partial Sums
• `ListPlot[Table[Sum[a_n, {n, 1, k}], {k, 1, i}]]` where a_n is the nth term and i is the number of terms desired
Note: You can use the option `PlotRange -> {ymin, ymax}` to keep the y-values of the plot constant

Section 8.7:

1. Maclaurin Series
• Find the first i terms of the Maclaurin series for f(x), using: `Normal[Series[f[x], {x, 0, i}]]` where i is the number of terms desired
2. Taylor Series
• Find the first i terms of the Taylor series for f(x), using: `Normal[Series[f[x], {x, a, i}]]` where i is the number of terms desired and the series is centered about x = a using: `Normal[Series[f[x], {x, a, i}]]` where i is the number of terms desired and the series is centered about x = a