CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/142-Labs/Lab 02 - Review of Calculus I.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 02 - Review of Calculus 1

Overview

In this lab, we will learn how to use SageMath to define functions, to compute limits, derivatives, and integrals, and to plot functions.

Important SageMath Commands Introduced in this Lab

ParseError: KaTeX parse error: Undefined control sequence: \hfill at position 32: …|l|l|} \hline \̲h̲f̲i̲l̲l̲ ̲\textbf{Command…

Notes

Note that SageMath's integrate\textbf{integrate} command does not include any constants of integration. Whenever you evaluate an indefinite integral, do not forget to include a constant of integration (+C) in your answer.

Basic Function and Expressions: SageMath uses sqrt(x)\textbf{sqrt(x)} for x\sqrt{x}, abs(x)\textbf{abs(x)} for x|x|, log(x)\textbf{log(x)} for ln(x)\ln(x), e\textbf{e} for Euler's constant, pi\textbf{pi} for π\pi, and infinity\textbf{infinity} for \infty. Other basic functions can be typed in as they are but you must carefully use ()() to group together and match up expressions as needed. You must also type * when multiplication is presented. For example, you need to type in sin(x)\textbf{sin(x)} instead of sinx\sin x and 2 * x / (x+y) for 2xx+y\frac{2x}{x+y}.

Chapters 1 - 6

Example 1

Use SageMath to define the following functions and find their derivative.

  1. f(x)=x3ln(x)f(x) = x^3 \ln(x)

  2. g(x)=arctan(x)x2+1g(x) = \dfrac{\arctan(x)}{\sqrt{x^2 + 1}}

  3. h(x)=1ln(x)1+ln(x)h(x) = \dfrac{1 - \ln(x)}{1 + \ln(x)}

def f(x): return x^3 * ln(x) diff(f(x),x)

You can make SageMath return the output in an easier to read way by using the ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{show(\dotsParseError: KaTeX parse error: Expected 'EOF', got '}' at position 2: )}̲ command. This command works for most outputs in SageMath.

show(diff(f(x),x))

Caution: \textbf{Caution: } SageMath uses log(x)\textbf{log(x)} to represent ln(x)\textbf{ln(x)}.

Example 2

Use SageMath to compute the first, second, third, and 100th derivative of f(x)=xsin(2x).f(x) = x\sin(2x).

Example 3

Use SageMath to evaluate the following indefinite and definite integrals:

  1. x+1(x2)2 dx\displaystyle \int \dfrac{x+1}{(x-2)^2} \ dx

  2. 13xex2 dx\displaystyle \int_{-1}^3 xe^{-x^2} \ dx

  3. 0π / 212cosx dx\displaystyle \int_0^{\pi \ / \ 2} \left | \dfrac{1}{2} - \cos x \right | \ dx

show(integrate((x+1)/(x-2)^2,x))

Example 4

Use SageMath to evaluate the following limits:

  1. limr0r2arccos(r)(sin(2r))2\displaystyle \lim_{r\rightarrow 0} \dfrac{r^2 \arccos(r)}{(\sin(2r))^2}

  2. limn(1+3/n)2n\displaystyle \lim_{n \rightarrow \infty} (1 + 3/n)^{2n}

  3. limt1+tan(π2t)\displaystyle \lim_{t \rightarrow 1^+} \tan\left(\frac{\pi}{2} t\right)

Note: In order to use a variable other than xx in SageMath, you must first declare it as a variable using the var()\textbf{var()} command.

r = var('r') limit((r^2 * arccos(r))/(sin(2*r)^2), r=0)

Example 5

Define the function f(x)=12x4x336x2+108xf(x) = \dfrac{1}{2} x^4 - x^3 - 36x^2 + 108x in SageMath.

Find the first and second derivatives of f(x)f(x) and assign them to the names df\textbf{df} and ddf\textbf{ddf}.

df = #Insert your code here ddf = #Insert your code here

Plot the graph y=f(x)y = f'(x) on the interval 10<x<10-10 < x < 10 and estimate the invervals on which y=f(x)y = f(x) is increasing.

Plot the graph y=f(x)y = f''(x) on the same interval and estimate the intervals on which f(x)f(x) is concave up.

Create a single plot containint the graphs y=f(x)y = f(x), y=f(x)y = f'(x), and y=f(x)y = f''(x) on the interval [10,10].[-10, 10]. Make sure to graph each function in a different color and a different linestyle. Also, add a legend identifying each of the three graphs. Were your estimations in the previous two parts correct?