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/141-Labs/Lab 02 - New Functions From Old.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 02 - New Functions From Old

Overview

In this lab, we will use SageMath to create functions and then use these functions to create new funcitons. Also, we will learn how to simplify and expand expressions and how to evaluate them at given values.

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̲ ̲\hspace{.7in} \…
Section 1.2

Example 1

Suppose f(x)f(x) and g(x)g(x) are functions. There are countless ways to combine these functions to create a new function. Some basic examples of this are f(x)+g(x)f(x) + g(x), f(x)g(x)f(x) - g(x), f(x)g(x)f(x)g(x), f(x)g(x)\dfrac{f(x)}{g(x)} and f(g(x))f(g(x)).

We first use SageMath to set f(x)=2x1f(x) = 2\sqrt{x-1} and g(x)=x1g(x) = \sqrt{x-1}.

def f(x): return 2*sqrt(x-1) def g(x): #Insert your code here show(f(x)) show(g(x))

Now, we will use f(x)f(x) and g(x)g(x) to create the five new functions f(x)+g(x)f(x) + g(x), f(x)g(x)f(x) - g(x), f(x)g(x)f(x)g(x), f(x)g(x)\dfrac{f(x)}{g(x)} and f(g(x))f(g(x)).

show(f(x) + g(x))
show(f(x) - g(x))

Observe how SageMath automatically simplified each output. Unforunately, this is not always the case. Consider the expression x(1+1x)x\left(1 + \frac{1}{x}\right). We know that this expression can easily simplify to x+1x + 1. Type this expression below and see what SageMath returns.

SageMath did not sipmlify the expression, but instead returned exactly what we typed in. We can make SageMath simplify the expression as much as possible by using the command ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{.full_̲simplify()}.

(x*(1+1/x)).full_simplify()

Example 2

Repeat Example 1 using the functions f(x)=1+xx+1f(x) = 1 + \frac{x}{x+1} and g(x)=21xg(x) = 2 - \frac{1}{x}. Use the command ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{.full_̲simplify()} to fully simplify each expression.

Example 3

Now, set f(x)=x2+1f(x) = x^2 + 1. Find and simplify the functions f(5x+2),3f(1/x),f(5x+2), 3f(1/x), and f(f(f(x)))f(f(f(x))).

Note that both f(5x+2)f(5x+2) and f(f(f(x)))f(f(f(x))) are polynomials, but they are written in factored or compact form. If we want to expand the polynomial, we can use the ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{.full_̲simplify()} command from earlier, or we could use the expand(expression)\textbf{expand}(\textit{expression}) command.

f(5*x+2).full_simplify()
expand(f(5*x+2))

Use both of these commands to expand f(f(f(x)))f(f(f(x))) and see if they give the same result.

Example 4

Recall that the difference quotient of a function is the expression f(x+h)f(x)h\dfrac{f(x+h) - f(x)}{h}. We will use SageMath to simplify this expression for the function f(x)=5x3+2x+1f(x) = 5x^3 + 2x + 1. First, create the function f(x)f(x) below.

In order for SageMath to simplify the difference quotient, we need to tell SageMath that hh is also a variable like xx. We do this by using the var(letter)\textbf{var}(`letter\textit{'}) command.

h = var('h')

Now, SageMath will treat hh like a variable. Below, simplify the difference quotient of f(x)f(x) and assign this expression to the name DiffQuot. Once simplified, the expressions should be a polynomial.

DiffQuot = #Insert your code here DiffQuot

Note that this expression is not completely simplified. Again, we can use the ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{.full_̲simplify()} command to fully simplify the difference quotient.

DiffQuot = DiffQuot.full_simplify() DiffQuot

Now, the difference quotient is fully simplifed. Suppose we wish to evaluate this new expression at h=0h=0. We can do this by appending (h=0)\textbf{(h=0)} after our expression.

DiffQuot(h=0)

Example 5

Repeat Example 4 using the function f(x)=1(x+1)2f(x) = \dfrac{1}{(x+1)^2}.

Example 6

Find and fully simplify f(g(x))f(g(x)), g(f(x))g(f(x)), f(g(f(x)))f(g(f(x))) and g(f(x)+g(x))g(f(x) + g(x)) for the following choices of f(x)f(x) and g(x)g(x).

  1. f(x)=2x+3f(x) = \sqrt{2x + 3} and g(x)=x2+1g(x) = x^2 + 1

  1. f(x)=x+1x1f(x) = \dfrac{x+1}{x-1} and g(x)=x1xg(x) = \dfrac{x}{1-x}

Example 7

Let F(x)=(sin(x2)+1)3F(x) = (\sin(x^2)+1)^3. Note that we can decompose F(x)F(x) into the composition of the three functions f(x)=x3f(x) = x^3, g(x)=sin(x)+1g(x) = \sin(x) + 1, and h(x)=x2h(x) = x^2, where F(x)=f(g(h(x))).F(x) = f(g(h(x))).

def f(x): return x^3 def g(x): return sin(x) + 1 def h(x): return x^2 f(g(h(x)))

Example 8

Repeat Example 7 with the following with the following choices for F(x)F(x), that is, find f(x)f(x), g(x)g(x), and h(x)h(x) such that F(x)=f(g(h(x))).F(x) = f(g(h(x))). Be sure to check your composition.

  1. F(x)=2+1x1/3F(x) = 2 + \sqrt{1 - x^{1/3}}

  1. F(x)=sin(x+5)2+1F(x) = \sin(\sqrt{x + 5})^2 + 1