Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

Transformations of Functions Using Sage

by Susan Schmoyer (adapted by Linda Green)

 


In this worksheet you will learn how to graph functions using transformations.  In particular, you will learn how horizontal and vertical shifts and stretches of the graph of a function affect the equation for the function.

Before you begin, make sure you know the graphs of our "toolkit" functions: 

 

y=xy = x

y=x2y = x^2

y=xy = \sqrt{x}   (denoted by sqrt(x) )

y=x3y = x^3

y=xy = |x|  (denoted by abs(x))

y=1/xy = 1/x

sin(x)\sin(x)

If the function sin(x)\sin(x) is new to you, that's okay.  You don't need to know what it means, but you should familiarize yourself with its shape below.

 

%auto functions = {'sin(x)':sin(x), 'x':x,'x^2':x^2,'x^3':x^3, 'sqrt(x)':sqrt(x),'1/x':1/x, 'abs(x)':abs(x)} @interact def _(g = selector(functions.keys(),label='function $f(x)$'), auto_update=True): g(x) = g P=plot(g(x), (x, -5, 5), legend_label='$y = f(x)$') P.show(gridlines='minor', ymin=-5, ymax=5, aspect_ratio=1)

Experiment A: transformations of toolkit functions.

For each of the following exercises, type the following expressions into the boxes below.  

Exercise 1:  f(x)= x2,       g(x)=x2+1,      h(x)=x22f(x) =  x^2, \;\;\; g(x) = x^2 + 1, \;\;\; h(x) = x^2 - 2  (type x^2 to get the squaring function).

Exercise 2: f(x)=x,      g(x)=x+3,      h(x)=x4f(x) = |x|, \;\;\; g(x) = |x + 3|, \;\;\; h(x) = |x - 4|  (type abs(x), abs(x-1), abs(x+2)  into the respective cells).

Exercise 3: f(x)=x,      g(x)=x,      h(x)=xf(x) = \sqrt{x}, \;\;\; g(x) = - \sqrt{x}, \;\;\; h(x) = \sqrt{-x}  (type sqrt(x), - sqrt(x), sqrt(-x) into the respective cells).

Exercise 4: f(x)=sin(x),      g(x)=5sin(x),      h(x)=(1/3)sin(x)f(x) = \sin(x), \;\;\; g(x) = 5 * \sin(x), \;\;\; h(x) = (1/3)*\sin(x) (you must use * for multiplication).

Exercise 5:  f(x)=sin(x),      g(x)=sin(3x),      h(x)=sin((1/2)x)f(x) = \sin(x), \;\;\; g(x) = \sin(3*x), \;\;\; h(x) = \sin((1/2)*x)  (you must use * for multiplication).

%auto @interact def _(f = x^2, g = x^2 + 1, h = x^2 - 2): f(x) = f g(x) = g h(x) = h P1=plot(f, (x, -6.5, 6.5), legend_label='$f(x)$') P2 = plot(g, (x, -6.5, 6.5), color = 'red', legend_label='$g(x)$') P3 = plot(h, (x, -6.5, 6.5), color = 'green', legend_label='$h(x)$') (P1+P2+P3).show(gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1)

 Generalize experiment A:

1: How does the graph of f(x)+cf(x) + c compare to the graph of f(x)f(x)?

2: How does the graph of f(x+c)f(x+c) compare to the graph of f(x)f(x)?

3: How does the graph of f(x)-f(x) compare to the graph of f(x)f(x)?  How does the graph of f(x)f(-x) compare to the graph of f(x)f(x)?

4: How does the graph of cf(x)c*f(x) compare to the graph of f(x)f(x)?

5: How does the graph of f(cx)f(c*x) compare to the graph of f(x)f(x)?

Experiment B: combining shifts

Use the drop-down menu to pick a toolkit function for f(x)f(x).  Then use the sliders to pick

  • kk, the vertical shift
  • hh, the horizontal shift
and graph the shifted function f(x+h)+kf(x+h)+k
 
The original toolkit function stays in gray.  The newly transformed function appears in blue.  
%auto @interact def _(q = [x^2, x^3, sqrt(x), 1/x, abs(x), sin(x)], h = (0, (-5, 5, 1)), k = (0, (-5, 5, 1))): q(x) = q Pnew=plot(q(x+h)+k,(x,-10,10), legend_label='$y = g(x+%s) + %s$' %(h,k), color='blue') Pold = plot(q(x), (x, -10, 10), legend_label='$y = g(x)$', color='gray') (Pold+Pnew).show(gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1, axes_labels=(['$x$','$y = g(x+h) + k$']))

Experiment C: Combining shifts and stretches

Use the drop-down menu to pick a toolkit function for f(x)f(x).  Then use the sliders to pick

  • aa, the vertical stretch / shrink
  • bb, the horizontal stretch / shrink
  • kk, the vertical shift
  • hh, the horizontal shift
and graph the shifted function af(b(x+h))+ka*f(b*(x+h))+k
 
The original toolkit function stays in gray.  The newly transformed function appears in blue.

 


%auto @interact def _(f = [x^2, x^3, sqrt(x), 1/x, abs(x), sin(x)], a=slider(-4,4,0.1,default=1.00), b = (1, (-4, 4, 0.1)), h = (0, (-5, 5, 1)), k = (0, (-5, 5, 1))): f(x) = f Pnew=plot(a*f(b*(x+h))+k,(x,-10,10), legend_label='$y = %6.1f*f(%6.1f*(x+%s)+%s)$' %(a,b,h,k), color='blue') Pold = plot(f(x), (x, -10, 10), legend_label='$y = f(x)$', color='gray') (Pold+Pnew).show(gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1, axes_labels=(['$x$','$y = a*f(b*(x+h))+k$']))

Challenges for Experiment C (above):

Challenge 1:  Pick the function f(x)=abs(x)f(x) = abs(x) in the graph above.  What value do you need to pick for bb to make the graph stretch out horizontally by a factor of 2?  Try it.  Now, without changing the value of bb that you just set, can you pick a value of aa that brings the graph back onto the original gray function?  What value of aa do you need to use?  

Challenge 2:  Select the function f(x)=x2f(x) = x^2.  What value do you need to pick for bb to make the graph stretch out horizontally by a factor of 2?  Try it.  Now, without changing the value of bb that you just set, can you find a value of aa that brings the graph back onto the original gray function?  What value of aa do you need to use?  

Explain challenges 1 and 2 in terms of the functions' equations.

Experiment D: Match the function

Try to make the blue function match the red function:

  • Enter the correct toolkit function in the box gg
  • Enter the vertical stretch / shrink (if any) in box aa
  • Enter the horizontal stretch / shrink (if any) in box bb
  • Enter the horizontal shift in box hh
  • Enter the vertical shift in box kk

Once you have the blue function superimposed on the red one, you win!

To play again, click in the cell below and press Shift+Enter

%auto var('x') L = [x^2, x^3, 1/x, abs(x), sin(x), sqrt(x)] fPick = ZZ.random_element(0, 5) f(x) = L[fPick] M = [1, 1, 1, 2, 3] cPick = ZZ.random_element(0,5) cc = M[cPick] N = [1, 1, 1, 1, 2] dPick = ZZ.random_element(0,5) dd = N[dPick] r=ZZ.random_element(0,2) aa = (-1)^r*cc hh=ZZ.random_element(-5,6) kk = ZZ.random_element(-5,6) qq = plot(aa*f(x+hh) + kk, (x, -10, 10), color = 'red') @interact def _(g=0, a = 1, b = 1, h = 0, k = 0, auto_update=True): g(x) = g pp=plot(a*g(b*(x+h))+k,(x,-10,10), legend_label='$y = %6.1f*(%6.1f*(x+%s)+%s)$' %(a,b,h,k)) show(qq + pp, gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1, axes_labels=(['$x$','$y = a*f(b*(x+h))+k$']))

Experiment E: Transformations Guessing Game

Guess the equation of the following function, graphed using transformations. 

To get a new graph, click on the cell below, and press Shift-Enter. 

 

To check your answer, evaluate the cell below the graph.


%auto var('x') L = [x^2, x^3, 1/x, abs(x), sqrt(x), 1/x^2] r=ZZ.random_element(0,2) a = (-1)^r b=ZZ.random_element(-5,6) c = ZZ.random_element(-5,6) d = ZZ.random_element(0, 5) f(x) = L[d] p = plot(a*f(x-b) + c, (x, -10, 10)).show(gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1) show(p)
verbose 0 (4128: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 140 points. verbose 0 (4128: plot.py, generate_plot_points) Last error message: ''
\newcommand{\Bold}[1]{\mathbf{#1}}\mathrm{None}

Did you guess correctly?  Click on the cell below and then click on 'evaluate' to see the correct formula.

print('f(x) = '); show(a*f(x-b) + c)
f(x) =
\newcommand{\Bold}[1]{\mathbf{#1}}x^{2}

 

Experiment F: Go wild 

Try typing in the formula for ANY function!  For example, try:

  • g(x)=x33xg(x) = x^3-3*x
  • g(x)=x+sin(x)g(x) = \sqrt{x} + \sin(x)
  • g(x)=(1/x)abs(x)g(x) = (1/x)*abs(x)
  • or anything else you like
%auto @interact def _(g=x^3-3*x, a = 1, b = 1, h = 0, k = 0, auto_update=True): g(x) = g P=plot(a*g(b*(x+h))+k,(x,-10,10), legend_label='$y = %s*g(%s*(x+%s)) + %s$' %(a,b,h,k)) P.show(gridlines='minor', ymin=-10, ymax=10, aspect_ratio=1)

Review:

1: How does the graph of f(x)+cf(x) + c compare to the graph of f(x)f(x)?

2: How does the graph of f(x+c)f(x+c) compare to the graph of f(x)f(x)?

3: How does the graph of f(x)-f(x) compare to the graph of f(x)f(x)?  How does the graph of f(x)f(-x) compare to the graph of f(x)f(x)?

4: How does the graph of cf(x)c*f(x) compare to the graph of f(x)f(x)?

5: How does the graph of f(cx)f(c*x) compare to the graph of f(x)f(x)?