Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
483 views

##Lab 7 Piecewise fn's and Operations with fn's

We'll start by looking at the syntax for defining piecewise functions using the builtin function called Piecewise. Let's have a 2-piece(can go with more) over the overall interval, [5,5][-5,5]. We want the function to return 4x4-x over the interval 5<x<1-5<x< 1 and x21x^2-1 over the interval 1x<51\le x<5. The function's name will be pw. One important thing to mention!! SAGE doesn't allow half-open or half-closed intervals! To it, the intervals are always closed.

x=var('x') pw=Piecewise([[(-5,1),4-x],[(1,5),x^2-1]],x)#take careful note how this is typed!!! show(pw) pw(1)#This is what I was talking about in red above! SAGE returns the average of the two outputs for x=1 pw.plot()#another way to create a quick plot ︠b9ef9790-0f28-428b-b13b-af99b7bc5d30i︠ %md Next we look at operations on functions and function composition. I will use the two functions, $f(x)=2x+3\mbox{ and }g(x)=3x-7$. Step 3 below shows the two functions, their sum, difference, product and quotient. It also shows the composition, $f(g(x))$.

Next we look at operations on functions and function composition. I will use the two functions, f(x)=2x+3 and g(x)=3x7f(x)=2x+3\mbox{ and }g(x)=3x-7. Step 3 below shows the two functions, their sum, difference, product and quotient. It also shows the composition, f(g(x))f(g(x)).

x=var('x') f=2*x+3; g=3*x-7 show([f,g,f+g,f-g,expand(f*g),f/g,f(g)]) ︠38607fec-633e-45b7-a2b5-ebf36f67a0a6is︠ %md Your turn. . . Let $f(x)=\sqrt[3]{6-3x}$ and $g(x)=2x^3+1$ Find the following all together or one at a time: 1. $f+g$ 2. $f-g$ 3. $fg$ 4. $f/g$(determine its domain) 5. $f(g)$ 6. $g(f)$ Evaluate all results for $x=2$

Your turn. . . Let f(x)=63x3f(x)=\sqrt[3]{6-3x} and g(x)=2x3+1g(x)=2x^3+1 Find the following all together or one at a time:

  1. f+gf+g

  2. fgf-g

  3. fgfg

  4. f/gf/g(determine its domain)

  5. f(g)f(g)

  6. g(f)g(f) Evaluate all results for x=2x=2

︠42f0f6f7-df19-420a-b942-b1b8e3b7cb07i︠ %md Let's look at one more new concept in this lab. It's called a **difference quotient**. This idea is fundamental to the study of beginning calculus. The difference quotient is a new function whose variable is $h$ that's built using an ordinary function of $x$. Here I name it $diff\_quo$. What $h$ represents is not important at this point. In the example below, my $f(x)=2x^2+3$. Use my block to fashion code to calculate the difference quotients for the following functions: 1. $\sqrt{x}$ 2. $x^3$ 3. $1/x$ 4. $x^2-5x+6$

Let's look at one more new concept in this lab. It's called a difference quotient. This idea is fundamental to the study of beginning calculus. The difference quotient is a new function whose variable is hh that's built using an ordinary function of xx. Here I name it diff_quodiff\_quo. What hh represents is not important at this point. In the example below, my f(x)=2x2+3f(x)=2x^2+3. Use my block to fashion code to calculate the difference quotients for the following functions:

  1. x\sqrt{x}

  2. x3x^3

  3. 1/x1/x

  4. x25x+6x^2-5x+6

h=var('h') f(x)=2*x^2+3 diff_quo(h)=(f(x+h)-f(x))/h diff_quo(h)
2*((h + x)^2 - x^2)/h