Calculus Lab #1:  Intro to Mathematica & Functions

Goals:	1.  Learn how to create your own notebook, save it, and print it
	2.  Learn  basic algebraic operations in Mathematica
	3.  Learn how to use palattes
	4.  Learn how to evaluate and plot functions with Mathematica 
	5.  Identify & locate basic features of graphs
	6.  Transform functions & determine the impact
	7.  Use graphs to find approximate solutions to calculus problems.

Getting Started
	This is a Mathematica notebook -- an interactive text that will allow us to visualize calculus concepts.  Notebooks are made up of "cells," indicated by the brackets on the right. They are organized in outline form.  Double-clicking the brackets on the right will open more cells.  Open the first section below and get started.

Lab Assignment

Because this is your first experience in the laboratory,your assignment in this notebook is short.  Follow the directions in each cell, type in answers to the questions, and save the results.

1.  Basic Arithmetic

The first thing you'll want to do when opening Mathematica is load some palettes.  Go to the FILE menu and move your cursor down to PALETTES.  The palattes we'll use most in this course are (1) Basic Calculations and (2) Basic Input.

Let's begin by solving some simple aritmetic problems.   Below is what is called an input cell. You can recognize input cells by the boldface type. Click anywhere on the text of the input cell.  We now want to execute the commands in the cell.  To do this, press the ENTER key (not the RETURN key).  You can also hit SHIFT-ENTER to execute commands.

2+2

Using the palettes, create the following two problems:
	1.  Multiply one-third by four-sevenths
	2.  Find the square root of two.

(1/3)*(4/7)

(Sqrt[2])

Notice how Mathematica keeps the square root of two (an irrational number) in symbolic form.  If we want to estimate the answer to a specific level of precision, we use the N[ ] command:

N[(Sqrt[2]), 50]

Find the value of pi to 100 digits.  You should enter pi as Pi, with a capital P (or use the palette)

N[Pi, 100]

Find the value of e (the exponential function raised to the first power) to 27 digits.  You enter the exponential function as EXP[1] or by using the palettes.

N[Exp[1], 100]

We can use the palettes to evaluate trigonometric functions as well.  Evaluate the following cell to find the sine of pi.

Sin[Pi]

Now find the tangent of (Pi / 8) and round your answer to five decimal places.

Tan[Pi/8]

N[Tan[Pi/8], 5]

2.  Defining Functions

Let's define a few functions.  The following cell defines f(x) as a simple quadratic function.  Notice the underline next to the x.  You will need this underline whenever you define a function.

f[x_]=(x^2)

We can then input any value for the independent variable and evaluate the function

f[6]
f[Pi] 
f[smileyface]

Define the function g(x) to be the natural logarithm of x.

g[x_]=Log[x]

g[1]
g[(E^1)] 
g[(E^10)]
g[(E^(-4))]

We can now algebraically manipulate our functions.  Let's define new functions h(x), i(x), and j(x).  Notice the last function is a composition of our two functions

h[x_] = f[x] + g[x]
i[x_] = f[x]/g[x] 
j[x_] = f[g[x]]

3.  Algebraic Operations

The function a(x) is defined as

a[x_] = (x^2)-5  x-6

We could easily factor this quadratic by hand.  Let's let Mathematica factor it for us.

Factor[a[x]]

We could also set this quadratic equation equal to zero and solve for x.  We call this finding the zeros (or the roots) of the quadratic function.

Solve[a[x] == 0,  x]

Let's define the function b(x) as

b[x_] = (x + 4) (x - 5) (2  x - 6)

Using the expand command, we can multiply these three factors together

Expand[b[x]]

We could also try simplifying the function

FullSimplify[b[x]]

I wonder what the zeros of this function are...

Solve[b[x] == 0,  x]

Let's deal with another function, c(x)

c[x_] = (3/(-7 + 2 x))-(x/(-7 + 
              2 x))

FullSimplify[c[x]]

Solve[c[x] == 0,  x]

Finally, let's define a linear function and a quadratic function.

d[x_] = 3  x + 4 
e[x_] = 2  (x^2)

Let's get a rough idea of what these functions look like.  The following command plots the two functions

Plot[{d[x], e[x]}, {x, -5, 5}]

At what value of X do these functions appear to intersect?  How do we find where they intersect?

Solve[d[x] == e[x],  x]

Let's get numerical approximations to these answers

NSolve[d[x] == e[x],  x]

Now let's check our answer by plugging in those values for x

d[-0.8507810593582122] 
e[-0.8507810593582122]
d[2.350781059358212]
e[2.350781059358212]

4.  Graphs

Using the GRAPHICS option on the palette, we'll graph some functions.

Plot[Sin[x], {x, -2 Pi, 2  Pi}] 
Plot[Cos[x], {x, -2 Pi, 2  Pi}]

Now let's plot these two functions on the same axes

Plot[{Sin[x], Cos[x]}, {x, -2 π, 
        2  π}]

Mathematica offers lots of options to customize the appearance of graphs.  First, let's label our axes.

Plot[Sin[x], {x, 0, 2  π}, 
      AxesLabel -> {"x value", "Sin[x]"}]

If we want to, we can overlay a grid.

Plot[Sin[x], {x, 0, 2  π}, Frame -> True, 
      GridLines -> Automatic]

If we want to define the domain (the range of x-values) and range (the range of y-values), we can use the following syntax

Plot[Sin[x], {x, 0, 2  π}, 
      PlotRange -> {0, 1.2}]

We can also color our plots to distinguish them

Plot[{Sin[x], Cos[x]}, {x, -2 Pi, 2  Pi}, 
      PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 0, 
              1]}}]

We could also plot 3-dimensional functions

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

5.  Graphs of Function Families

5a.  Linear Functions

A linear function, commonly written in slope-intercept form (y=mX+b), is generally the first type of function you learn in algebra.  Linear functions increase at a constant rate.  Suppose you rent out my office to see coffee to students.  Further suppose I charge you $20 to rent out my office and it costs you 25 cents to make each cup of coffee.  We can define the function c(x) to model your total costs:

c[x_] = 20 + .25  x

Plot this function and determine your total costs if you make 80 cups of coffee.

Plot[c[x], {x, 0, 100}]

c[80]

Suppose you charge students $1.10 for each cup of coffee.  How many cups must you sell to break even?  We'll first define a revenue function, r(x), and plot it:

r[x_] = (1.10 - 0.25) x  
Plot[r[x], {x, 0, 100}]

Let's plot these on the same axes to find our break-even point.

Plot[{c[x], r[x]}, {x, 0, 100}, 
      PlotStyle -> {{RGBColor[0, 0, 1]}, {RGBColor[1, 0, 
              0]}}]

Some questions to think about:
1.  What are the domain and range of our two functions?
2.  How can we find exactly where they intersect?

Solve[r[x] == c[x],  x]

5b.  Polynomial Functions

Ploynomial functions are of the form:  a(x^n)+b(x^(n - 1))+ ...  + (cx^1) + d.  What happens to the following quadratic function as we change the coefficient?

red[x_] = (x^2)
blue[x_] = 3  (x^2)
green[x_] = (1/3) (x^2)
Plot[{red[x], blue[x],  green[x]}, {x, -10, 10},  
      PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 0, 
              1]},    {RGBColor[0, 1, 0]}}]

What happens when we add or subtract a constant?

red[x_] = (x^2)
blue[x_] = (x^2) + 25
green[x_] = (x^2) - 30
Plot[{red[x], blue[x],  green[x]}, {x, -10, 10},  
      PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 0, 
              1]},   {RGBColor[0, 1, 0]}}]

The roots of a polynomial function are the points at which the function is equal to zero.  We can find these roots graphically or through factoring.  Find the roots of the following function:

f[x_] = 3  (x^2)-2  
          x -5 
Plot[f[x], {x, -5, 5}]

Factor[f[x]]

Solve[f[x] == 0, x]

5c.  Rational Functions

Rational functions are simply the ratio of one polynomial to another.

f[x_] = 3  (x^2) + 2  x - 1
g[x_] = (x^2)-7  
          x+12 
r[x_] = f[x]/(g[x] ) 
Plot[r[x], {x, 0, 10}]

Are those vertical lines part of the graph?  How can we find exactly where those points exist?

Solve[g[x] == 0, x]

Suppose we have another rational function, this time involving a trigonometric function

a[x_] = Sin[x]/x 
Plot[a[x], {x, -10, 10}]

Several key questions we'll learn how to answer using Calculus:
1.  Where is this function increasing; where is it decreasing?  What does it mean to be increasing/decreasing?
2.  Where is the function concave up; where is it concave down?  How do we determine concavity?
3.  Where is the maximum of this function?  Does it have any other maxima?  How about minima?  How do we go about finding these values?
4.  What is the slope of this function at a specific point?
5.  What is the area under this curve?

5.  Questions (Turn in for credit)

Normally, we'll work through a Mathematica notebook as a class, pointing out important concepts and reasoning.  At the end of each notebook, I will have a set of questions that you (or you and a partner) will have to answer and hand-in.

The questions will deal with calculus concepts; not your knowledge of Mathematica commands.  While I do want you to become familiar with Mathematica, I'm more interested in making sure you learn calculus.  If you ever need help with a Mathematica command, don't hesitate to ask.

We will complete several Mathematica labs in this course.  Through these labs, you will learn how to apply concepts we learn in class to solve (somewhat) real problems.  I will allow you to work with a partner or two on these labs.

As we move towards the end of the semester, I may include some test items that force you to use Mathematica to solve.  I will make sure you are fully capable of running Mathematica before then.

1:  Define the function f(x) = ((Sin(X))/X).

2.  Plot this function over the interval:  {-3π , 3π).

3.  Evaluate the function at X = (Pi/4).  Get an exact answer and a numeric answer rounded to 20 decimal places.

4.  What's the domain of this function?  What is the range?  At what values of X is this function undefined?

5.  What value does this function approach as X approaches zero?

6.  Define another two functions:   g(x) = (x^2) and h[(x) = (Sqrt[3  x]) 

7.  Plot these two functions on the same set of axes and determine exactly where they intersect.  Use the following syntax:

Plot[{g[x], h[x]}, {x, -3, 3}, 
      PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 0, 
              1]}}]

Why did you get an error message when you tried to plot this?

6.  Reflection

At the end of each Mathematica session, I want you to write a sentence or two describing what you learned (or just list important concepts from this lab).  You can later use these reflections as a reference for other Mathematica Labs.

Print out your answers to the lab questions and turn them in for credit.