introduction to mathematica calculus i introduction to...

52
Introduction to Mathematica – Calculus I Page 1 of 52 Introduction To Mathematica For Calculus I Students Mathematica is a math programming language that allows us to do almost any mathematical process you could imagine. In this Tutorial, you will learn how to do the following. 1. How to Get Mathematica as an Olympic College Student. Pages 2 - 5 2. Initial Startup of the Mathematica Program. Pages 6 - 7 3. The Structure and Syntax of Mathematica Commands. Pages 8 - 11 4. How to do Arithmetic calculations. Pages 10 - 11 5. How to do Algebraic Manipulation of Expressions. Pages 12 - 15 6. Solving Equations Exactly and Numerically. Pages 16 - 23 7. Introduction to Functions. Pages 24 27 8. How to Graph Functions. Pages 28 - 37 9. Finding Limits. Pages 38 - 39 10. Finding Derivatives. Pages 40 - 44 11. Application of Derivatives. Pages 45 - 51

Upload: dangnguyet

Post on 11-Mar-2018

242 views

Category:

Documents


3 download

TRANSCRIPT

Introduction to Mathematica – Calculus I

Page 1 of 52

Introduction To Mathematica

For Calculus I Students

Mathematica is a math programming language that allows us to do almost any

mathematical process you could imagine. In this Tutorial, you will learn how

to do the following.

1. How to Get Mathematica as an Olympic College Student. Pages 2 - 5

2. Initial Startup of the Mathematica Program. Pages 6 - 7

3. The Structure and Syntax of Mathematica Commands. Pages 8 - 11

4. How to do Arithmetic calculations. Pages 10 - 11

5. How to do Algebraic Manipulation of Expressions. Pages 12 - 15

6. Solving Equations Exactly and Numerically. Pages 16 - 23

7. Introduction to Functions. Pages 24 – 27

8. How to Graph Functions. Pages 28 - 37

9. Finding Limits. Pages 38 - 39

10. Finding Derivatives. Pages 40 - 44

11. Application of Derivatives. Pages 45 - 51

Introduction to Mathematica – Calculus I

Page 2 of 52

1. How to Get Mathematica as an Olympic College Student. You can obtain Mathematica as a stand-alone program by following these instructions. First you must Create an Account with Wolfram

1. Create an account with Wolfram.

a. Go to https://user.wolfram.com/portal/login.html

b. Click "Create Wolfram ID"

c. Fill out the “Create a Wolfram ID” form.

d. In the “Your email address (this will be your Wolfram ID)” field, type your Olympic College @student.olympic.edu email address when creating your account.

e. After entering information in all the required fields, click “Create Wolfram ID”

f. You will receive a success message after creating your ID.

Introduction to Mathematica – Calculus I

Page 3 of 52

2. Check your Olympic College email account.

a. Go to https://mail.student.olympic.edu/owa/ and log into your Olympic College email

account.

b. Open the “Validate your Wolfram ID” email from [email protected].

c. Click the link in the email to verify that your email address is valid.

d. After you have successfully verified your email address, you will receive a thank you

confirmation.

Introduction to Mathematica – Calculus I

Page 4 of 52

3. Request a Mathematica Activation Key

1. Sign in to the Wolfram account that you created using your @student.olympic.edu email address.

a. Go to https://user.wolfram.com/portal/login.html

b. You will now be logged into the Wolfram User Portal

2. After signing in to the “Wolfram User Portal”, visit the “Wolfram Activation Key Request Form”

for Olympic College.

a. While signed into your “Wolfram User Portal”, copy and paste the following URL into a

new tab in your internet browser:

https://user.wolfram.com/portal/requestAK/b3d8fbb9b1c9930e57fadac88294b36eee36a3f1

b. Fill out the “Wolfram Activation Key Request Form”

c. In the “Email” field of the form, enter your Olympic College @student.olympic.edu email

address.

d. When the form has been completely filled out, click “Submit”

e. An Activation Key will be generated and will display on the screen. Make a note of this

activation key.

Introduction to Mathematica – Calculus I

Page 5 of 52

4. Download and Install Mathematica

1. Return to the “Wolfram User Portal” webpage: https://user.wolfram.com/portal/login.html

2. Click on the “My Products and Services” tab.

3. Under “My Products and Services”, click on “Mathematica for Students for Sites”

4. Under “Product Information”, click “Get Downloads”

5. Locate your operating system from the list and click "Download"

6. Verify that you have selected the correct version of the software and click “Start Download” when

ready.

7. Depending on the platform selected, you will be prompted to save a file to your local computer.

a. For example, if you selected to download Mathematica 10.1.0 for Windows, you will be

prompted to save a file called “Mathematica_10.1.0_WIN.zip”

8. When the file has finished downloading, unzip or extract the file if necessary.

a. For example, in Windows, right-click the .zip file and select “Extract All…”

b. Once the .zip file has been extracted, a “setup.exe” file will become available. This is the

Mathematica installer file for Windows.

9. Run the installer file on your computer. Follow the on-screen instructions and enter your

Activation Key when prompted.

Introduction to Mathematica – Calculus I

Page 6 of 52

2. Initial Startup of the Mathematica Program. You will begin by loading up the Mathematica program its icon will look like The program will then load up and you will see a welcome screen similar to this one below. Click on the Tab to start a new notebook and you will have your first program ready to type.

The notebook screen will now look like this.

Introduction to Mathematica – Calculus I

Page 7 of 52

A very useful addition is to the setup is to add the Basic Math Assistant Palette as this will allow you to

type many math characters and symbols in a more intuitive way.

To do this click on the Palettes Tab and Highlight Basic Math Assistant and click on it.

You will now see on the Right-Hand Corner the Basic Math Assistant.

As can be seen on the Righthand side.

The Basic Math Assistant contains an easy to use set of icons that will

allow you to type in the following items.

Fractions, Powers, Square roots.

Greek letters such as 𝜃 , ∅ , 𝜋.

Special characters such as ∞ , i = √−1 or ! (Factorial).

Common Functions such as Sin , Cos , ArcTan , ex , Log.

It also has Derivative and Integral Commands.

It also has an Advanced Tab that allows for even more choices.

Introduction to Mathematica – Calculus I

Page 8 of 52

3. The Structure and Syntax of Mathematica Commands.

Mathematica is a specialized programming language and has a very particular structure and the rules of

how you type in command and their Syntax need to be followed carefully.

Rule1: Wolfram Language commands begin with capital letters

and are enclosed by square brackets [.....].

For Example, the Command

Factor[x2 – 5 x + 6] will factor the expression x2 – 5x + 6 and give you the output

(−3 + 𝑥)(−2 + 𝑥)

If however you type factor[x2 – 5 x + 6] or Factor(x2 – 5 x + 6) it will not work.

Also there are many predetermined Functions including Sin[x] , Cos[x], Exp[x], Log[x],

ArcSin[x], Pi, Infinity etc….

These Functions all start with a CAPITOL letter followed by square brackets [……]

So Sin[Pi/4] will give you the exact value of sin( 𝜋

4) =

√2

2

ArcTan[Infinity] will give you the exact value of tan-1(∞) = 𝜋

2

In Mathematica your program commands and output will look like this .

Note 1: If in the above two examples we did not use a Capitol letter first such as sin[Pi/4] or

arctan[Infinity] or we did not use Square Brackets such as Sin(Pi/4) or ArcTan{Infinity}

then the command would not work. So, it is important that you get the rule that all

Commands start with a CAPITOL letter followed by square brackets. […..] for if you do

not follow this yntax exactly the programs often fail to work.

Note 2: When you have finished your Mathematica program then you must hit the Numeric

Keypad ENTER button Not the normal Keyboard ENTER button.

The Numeric Keyboard ENTER button tells Mathematica to run the program, while the

normal keyboard ENTER button just jumps to the next line in your program.

Introduction to Mathematica – Calculus I

Page 9 of 52

Rule 2: All variable names must be in lower case. Variables in Mathematica can have any name you like as long as the variable name does not contain any spaces and the first letter must always be in lower case. The following are a list of possible variable names. These are valid names for variables: x , y , z, max , profit, energy , velocity1, account1a These are not valid names for variables: X , Max , xvalue 1, Sin X is not valid as it is a Capitol Letter Max is not valid as it is a Capitol Letter xvalue 1 is not valid as it has a space in it. Sin starts with a Capitol letter and is also a Mathematica command for the sine function. There are some variable names that are allowed but they should not be used as they tend to cause confusion when reading and interpreting a program. For Example : Don’t use variable names that have a similar name to a command such as using variable names like factor,print or simplify. For although factor , print and simplify are acceptable variable names they can easily be mistaken by someone reading your program as the commands Factor , Print and Simplify. Don’t use variable names that are too long or have no obvious meaning as they make your program difficult to read. For Example, don’t use a variable name such as thelargestvalueofafunctionf or xyttppp2. Note: It is a good idea to name your variable, whenever possible, to reflect its meaning or content, so

if a variable is used to store the x coordinate of a point you should call it x or x-coord, if the variable is the velocity of an object you could call it v or velocity. So the rule of thumb here is that you should name your variables intelligently so that your program is easy to read and to understand what your program is doing and the meaning behind each variables value. It is also good practice in your program to insert comments next to important parts of your program such as telling the reader what each variables job is and what the program is doing at specific points. This can be done by adding on the far right hand side of the same line of the command the relevant comment, this can be done by using by using the comment feature in Mathematica the comment feature has the syntax (* put comment here*

Introduction to Mathematica – Calculus I

Page 10 of 52

4. How to do Arithmetic Calculations.

To do calculations you simply type the calculation and then press the Number Pad ENTER Key.

For most calculations, you would enter them in the way you would normally write them, except for

functions where you would need to type 𝑆𝑖𝑛[𝜋

4] instead of sin (

𝜋

4)

Example 1: Here are a list of Arithmetic Calculations.

Note : Be careful when using exponential functions like e2 or e1.5 as the e is a special button on

the Basic Math Palette, so be careful and don’t use the keyboard e as it will not work.

Input Output Comments

3 ∗ 5 + 5 ∗ 6 45 * can be used to indicate multiplication

3

4+

5

6

19

12 you can enter fractions by using the Basic Math Assistant

3(1

2−

9

8)3

375

512

All answers will be in the form of the data

fractions → fractions , decimals → fractions

5(7 + 9) − 2(5 + 91) −112 The order of operations will use PEMDAS

3.13 + 4.6

2.9 + 5.88

0.88041 All answers will be displayed to 5 decimal places by default.

Cos[𝜋

6]

√3

2 All answers will be exact values whenever possible

Sin[𝜋

4]

1

√2

All answers will be exact values whenever possible but not

always in the form you would expect here it is 1

√2 and not

√2

2

Cos[30] Cos[30]

The exact value of cos(30 radians) is not a simple value the

output will just be Cos[30] if you want to get a decimal

approximation to the answer you will need to use the N[……]

command.

Cos[300] √3

2 Gives the exact value of cos(300)

Introduction to Mathematica – Calculus I

Page 11 of 52

The N[expression,n] command attempts to give a result with n-digit precision, in practice this command

will give you the output as a decimal to n significant figures if possible. This command has a particular

syntax it is written in the form

N[expression]

N[expression , number of significant figures]

In expression, you put your calculation then a comma then the desired number of significant figures you

wish in the output]

For Example when you type Cos[3] will give you the unchanged exact value output of Cos[3]

If you type N[Cos[3]] you will get the output Cos[3]

but if you type N[Cos[3],7] you will get the output −0.9899925

and if you type N[Cos[3],23] you will get the output −0.98999249660044545727157

and if you type N[Cos[3],2] you will get the output −0.99

Other examples of the N[…] command include.

𝑁[Sin[𝜋

4],4] which gives the output 0.7071

𝑁[3(1

2−

9

8)3, 3] which gives the output −0.732

𝑁[3

4+

5

6, 3] which gives the output 1.58

Note 1: The N[…] command has some idiosyncrasies for example if you have an exact decimal

number as your input such as 1.234567 and you use the N[….] command you do not

always get what you expect as the output. The N[…] is essentially ignored so that the

following happens.

N[1.234567,2] you get the output of 1.234567

N[1.234567,3] you get the output of 1.234567

Note 2: There is however a command called PaddedForm[…] that can take care of the issue

above and as a bonus it will give you the output to a given number of decimal places.

Its Syntax is one of two versions

PaddedForm[expression,{#digits,#decimal places}]

PaddedForm[N[expression],{#digits,#decimal places}]

Examples:

PaddedForm[1.234567, {5,4}] will give output 1.2346

PaddedForm[𝑁[Cos[3]], {9,5}] will give output −0.98999

PaddedForm[𝑁[1

6], {7,5}] will give output 0.16667

Introduction to Mathematica – Calculus I

Page 12 of 52

5. How to do Algebraic Manipulation of Expressions.

It is possible to do all the typical mathematical manipulations of expressions the most commonly used

are the following.

Together

Simplify

Factor

Expand

The Together[….] command takes several fractions and combines them into a single fraction using

common denominators and it then simplifies the result.

The Together command has the following syntax.

Together[fractional expressions]

Example 2: Together[𝑎 𝑏⁄ + 𝑐 𝑑⁄ ] will give the output 𝑏𝑐+𝑎𝑑

𝑏𝑑

Example 3: Together [𝑎

𝑏+

𝑏

𝑐+

𝑐

𝑎 ]will give the output

𝑎𝑏2+𝑎2𝑐+𝑏𝑐2

𝑎𝑏𝑐

Example 4: Together[𝑥+3

𝑥+

𝑥

𝑥+3−

1

𝑥−1] will give the output

−9+3𝑥2+2𝑥3

(−1+𝑥)𝑥(3+𝑥)

Example 5: Together[4𝑥−4

𝑥2−1+

4𝑥

𝑥+1−

𝑥−2

𝑥2−3𝑥+2+

2𝑥

𝑥−3] will give the output

15−19𝑥+6𝑥2

(−3+𝑥)(−1+𝑥)

Note 1: Notice the unusual form of the Output of the fraction. −9+3𝑥2+2𝑥3

(−1+𝑥)𝑥(3+𝑥) this is the typical

smallest to largest power format

Note 2: You can write fractions in more than one way 𝑎 𝑏⁄ + 𝑐 𝑑⁄ or 𝑎

𝑏+

𝑏

𝑐+

𝑐

𝑎 but it is usually

better to write your fractions in the form 𝑎

𝑏+

𝑏

𝑐+

𝑐

𝑎 as it is easier to read and is more

intuitive.

Introduction to Mathematica – Calculus I

Page 13 of 52

The Simplify command is used to simplify algebraic expressions by combining like terms, simplifying

fractions and radicals or use it to simplify Trig expressions by using Identities.

The Simplify command has the following syntax.

Simplify[expression]

Simplify[expression,contraint]

Example 6: Simplify the following polynomial expressions.

Simplify[x2 – 5 x + 4 x – 3 x2 + x – 4 – ( – 6)] will give you the output 2 – 2x2

Simplify[𝑎2 − 2𝑏 + 5𝑐 − 2𝑎2 + 2𝑎 + 3𝑏 − 5𝑐] will give you the output 2𝑎 − 𝑎2 + 𝑏

Simplify[𝑎2 + 5𝑎 − 𝑏2 − 2𝑏 + 2𝑏 − 5𝑎] will give you the output 𝑎2 − 𝑏2

Example 7: Simplify the following radical expressions.

Simplify[𝑥2−9

𝑥+3] will give you the output 3 + x

Simplify[𝑥+3

𝑥−

2

𝑥] will give you the output 1 +

1

𝑥

Simplify[𝑥2−16

𝑥+4+

𝑥2−16

𝑥−4] will give you the output 2 x

Example 8: Simplify the following radical of numbers.

Simplify[√25] will give you the output 5

Simplify[√36

49] will give you the output

6

7

Simplify[√40] will give you the output 2√10

Example 9: You can also use it to simplify Radical expressions provided you give the Simplify

command extra information in the form of an assumptions/constraints on the value of the

variable.

Simplify[√𝑥2 − 4𝑥 + 4 ] will give you the output √(2 − 𝑥)2

Simplify[√𝑥2 − 4𝑥 + 4 ,x>0] will give you the output Abs(2 – x)

Simplify[√𝑥2 − 4𝑥 + 4 ,x>2] will give you the output 2 – x

Simplify[√𝑥2−9

√𝑥2−5𝑥+6, 𝑥 > 3] will give you the output √

3+𝑥

−2+𝑥

Introduction to Mathematica – Calculus I

Page 14 of 52

Example 10: You can use it to simplify many Trig Expressions (Identities)

Simplify[Sin[𝑥]^2 + Cos[𝑥]^2] will give you the output 1

Simplify[2Tan[𝑥]

1+Tan[𝑥]^2] will give you the output Sin[2x]

Simplify[2𝑆𝑖𝑛[𝑥]𝐶𝑜𝑠[𝑥]] will give you the output Sin[2x]

Note 1: The format of the output is in increasing powers so you do not get x + 3 as an output you

will get 3 + x. Also, if the output is a quadratic like Simplify[𝑥2 + 1 − 3𝑥] your output

will be 1 − 3𝑥 + 𝑥2

Note 2: Simplify and Together are not equivalent, although sometimes they will give the same

Outputs.

For example,

Simplify[𝑥+3

𝑥−

2

𝑥] gives an output 1 +

1

𝑥 whereas

Together [𝑥+3

𝑥−

2

𝑥] gives an output

1+𝑥

𝑥

Simplify[𝑥2−16

𝑥+4+

𝑥2−16

𝑥−4] gives an output 2 𝑥 and

Together[𝑥2−16

𝑥+4+

𝑥2−16

𝑥−4] gives an output 2 𝑥

Simplify[𝑥+3

𝑥+

𝑥

𝑥+3−

1

𝑥−1] will give the output 1 +

1

1−𝑥+

3

𝑥+

𝑥

3+𝑥 whereas

Together[𝑥+3

𝑥+

𝑥

𝑥+3−

1

𝑥−1] will give the output

−9+3𝑥2+2𝑥3

(−1+𝑥)𝑥(3+𝑥)

Note 3: Since Simplify and Together are not equivalent you must choose the appropriate

command for the type of output you are looking for. The Together command should be

used if you are combining several fractions together and you wish your output to be a

single simplified fraction. You should use the Simplify command if you wish to simplify

a single fraction and reduce its quotient remainder form. You should use the either

command if you wish the output to be simplify a single fraction and reduce it to its

simplest form

For example, if you want the output as single fraction in its simplified form use the

Together command.

Together [𝑥+3

𝑥−

2𝑥

𝑥+1] gives an output

1+𝑥

𝑥

If you want the output in its Quotient Remainder form use the Simplify command.

.

Simplify [𝑥+3

𝑥−

2𝑥

𝑥+1] gives an output

1+𝑥

𝑥

Introduction to Mathematica – Calculus I

Page 15 of 52

The Factor command is used to factor algebraic and Trig expressions.

The Factor command has the following syntax.

Factor[expression]

Factor[expression,Trig→ 𝑇𝑟𝑢𝑒]

Example 11: Factor the following polynomials.

Factor[𝑎2 − 5𝑎 + 6] gives an output (−3 + 𝑎)(−2 + 𝑎)

Factor[𝑦10 − 1] gives an output (1 + 𝑦2)(1 − 𝑦2 + 𝑦4 − 𝑦6 + 𝑦8)

Factor[𝑒2𝑥 − 6𝑒𝑥 + 9] gives an output (−3 + 𝑒𝑥)2

Factor[𝑥2𝑏 − 4𝑥𝑏 + 4] gives an output (−2 + 𝑥𝑏)2

Example 12: Factor the following Trig expressions

Format[trig expression, Trig→ True]

Factor[Sin[𝑥] + Sin[𝑦], Trig → True] gives an output 2Cos[𝑥

2−

𝑦

2]Sin[

𝑥

2+

𝑦

2]

Factor[Sin[𝑥] + Cos[𝑦], Trig → True] gives an output (Cos[𝑥

2−

𝑦

2] + Sin[

𝑥

2−

𝑦

2])(Cos[

𝑥

2+

𝑦

2] + Sin[

𝑥

2+

𝑦

2])

Factor[Tan[𝑥] + Cot[𝑥], Trig → True] gives an output Csc[𝑥]Sec[𝑥]

Factor[Sin[𝑥] − Sin[2𝑥], Trig → True] gives an output −2Cos[𝑥

2](−1 + 2Cos[𝑥])Sin[

𝑥

2]

Factor[Sin[𝑥]^2 − Cos[𝑥]^2, Trig → True] gives an output −Cos[2𝑥] Factor[Tan[𝑥]^2 − Sec[𝑥]^2, Trig → True] gives an output −1

The Expand command is essentially the inverse of the Factor command and has the following syntax.

Expand[expression]

Expand[(1 + 𝑥)5] gives an output 1 + 5𝑥 + 10𝑥2 + 10𝑥3 + 5𝑥4 + 𝑥5

Expand[(𝑥 + 𝑦)2(𝑥 − 𝑦)3] gives an output 𝑥5 − 𝑥4𝑦 − 2𝑥3𝑦2 + 2𝑥2𝑦3 + 𝑥𝑦4 − 𝑦5

If you use trig functions with the expand command you may not get the output in its simplest form.

Example 13: Simplify the following expressions as much as possible.

Expand[(Sin[𝑥] + Cos[𝑥])(Sin[𝑥] − Cos[𝑥])] gives an output −Cos[𝑥]2 + Sin[𝑥]2

If you then do Simplify[−Cos[𝑥]2 + Sin[𝑥]2] you get the output −Cos[2𝑥]

You could combine both commands to get

Simplify[Expand[(Sin[𝑥] + Cos[𝑥])(Sin[𝑥] − Cos[𝑥])]] and get the output −Cos[2𝑥]

Introduction to Mathematica – Calculus I

Page 16 of 52

6. Solving Equations Exactly and Numerically. The Solve command is used to solve an equation with respect to one variable and it can be extended to

solve a system of equations with respect to multiple variables. The syntax for the Solve[…] command is

Solve[{expression},{variable(s)}]

Solve[{expression},{variable(s)},domain]

An example of the Solve[….] command being used to solve an equation with only one variable would

be to solve the equation “2x3 + x = – 10x” with respect to x.

The expression is the equation to be solved such as 2x3 + x == – 10x

The variable in this case would be x

The domain in this case could be Integers, Reals or Complexes,

Example 14: Solve the equation 2𝑥3 − 9𝑥2 + 14𝑥 − 5 = 0

Solve[2𝑥3 − 9𝑥2 + 14𝑥 − 5 == 0, {𝑥}, Integers] The output is {}

Solve[2𝑥3 − 9𝑥2 + 14𝑥 − 5 == 0, {𝑥}, Reals] The output is {{𝑥 →1

2}}

Solve[2𝑥3 − 9𝑥2 + 14𝑥 − 5 == 0, {𝑥}, Complexes]] The output is {{𝑥 →1

2}, {𝑥 → 2 − 𝑖}, {𝑥 → 2 + 𝑖}}

Note 1: Notice the double = sign == used in equations, it is easy to miss it out, so be careful.

Note 2: The domain is typically Reals, Integers, and Complexes, in the third case it is called

Complexes , not the word Complex (that command is used for something else) also if you

do not put in a domain value it will use the default value of Complexes.

Note 3: The solution when x was an integer does not exist and so the solution in these cases will

be the output {}.

Note 4: The solution to the equation (The output) is not in the form you might have expected

{{𝑥 →1

2}}this means the solutions are x =

1

2 .

Another example of the Solve[….] command being used is in solving the equation “2b2 + 1 = – 19” with

respect to b.

The expression is the equation to be solved such as 2b2 + 1 == – 19

The variable in this case would be b

The domain in this case could be Integers, Reals or Complexes,

Solve[2b2 + 1 == – 19,{b},Integers] The output would be {}

Solve[2b2 + 1 == – 19,{b},Reals] The output would be {}

Solve[2b2 + 1 == – 19,{b},Complexes] The output would be {{𝑏 → −𝑖√10}, {𝑏 → 𝑖√10}}

Introduction to Mathematica – Calculus I

Page 17 of 52

Example 15: The following examples show the varying uses of the Solve command in solving one

variable equations.

If you introduce constants to the equation such as a,b,c you are still able to get solutions to the equation

in terms of these values.

Example 16: Solve the general quadratic equation ax2 + bx + c = 0

Solve[𝑎𝑥2 + 𝑏𝑥 + 𝑐 == 0, {𝑥}] the output will be {{𝑥 →−𝑏−√𝑏2−4𝑎𝑐

2𝑎}, {𝑥 →

−𝑏+√𝑏2−4𝑎𝑐

2𝑎}}

Note: Notice that a x2 has a gap between a and x2 , this is part of the syntax if you write ax2 it will not

be interpreted correctly and the Solve command will not work, this is an easy thing to miss so be

aware of it.

Example 17: Solve the general exponential equation aet = p

Solve[𝑎𝑒𝑡 == 𝑝, {𝑡}, Reals]

The output will be {{𝑡 → ConditionalExpression[Log[𝑝

𝑎], (𝑎 > 0&&𝑝 > 0)||(𝑎 < 0&&𝑝 < 0)]}}

Note: The output is not what you might expect, what the program is telling you is that the solution is

t = 𝐿𝑜𝑔 [𝑝

𝑞] but there are conditions on the solution for real values and these conditions are

𝑎 > 0&&𝑝 > 0 we interpret this as a > 0 and "&&" p > 0 || as “or”

𝑎 < 0&&𝑝 < 0 we interpret this as a < 0 and "&&" p < 0

So in English the real solution to the equation aet = p as t = 𝐿𝑜𝑔 [𝑝

𝑞] as long as a and p are both

positive or that a and p are both negative and if this is not true there will be no real solutions.

Equation Input Solutions

(Output)

2𝑥2 − 10𝑥 = −12 Solve[2𝑥2 − 10𝑥 == −12, {𝑥}, Integers] {{𝑥 → 2}, {𝑥 → 3}}

𝑥2 + 1

𝑥 − 1= 2𝑥 + 3 Solve[

𝑥2 + 1

𝑥 − 1== 2𝑥 + 3, {𝑥}, Reals]

{{𝑥 →1

2(−1 − √17)},

{𝑥 →1

2(−1 + √17)}}

4𝑥3 + 8𝑥 = 0 Solve[4𝑥3 + 8𝑥 == 0, 𝑥, Complexes] {{𝑥 → 0}, {𝑥 → −𝑖√2},

{𝑥 → 𝑖√2}}

5𝑏2 − 17𝑏 + 6 = 0 Solve[5𝑏2 − 17𝑏 + 6 == 0, {𝑏}, Integers] {{𝑏 → 3}}

5𝑏2 − 17𝑏 + 6 = 0 Solve[5𝑏2 − 17𝑏 + 6 == 0, {𝑏}, Reals] {{𝑏 →2

5}, {𝑏 → 3}}

Introduction to Mathematica – Calculus I

Page 18 of 52

If you wish to solve a system of equation with two unknown variables the syntax of the Solve[…]

command in this situation will be

Solve[{𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2}, {𝑥, 𝑦}, 𝑑𝑜𝑚𝑎𝑖𝑛]

Where {equation 1,equation 2} will be the two equations

{x,y} will be the two variables

Domain will be Integers , Reals or Complexes

Example 18: Solve the system of equations 2x + 3y = 12

4x – 5y = 15

Solve[{2𝑥 + 3𝑦 == 7,4𝑥 − 5𝑦 == 1}, {𝑥, 𝑦}, 𝑅𝑒𝑎𝑙𝑠] the output is {{𝑥 →19

11, 𝑦 →

13

11}}

Note : {equation 1,equation 2} are the two equations {2𝑥 + 3𝑦 == 7,4𝑥 − 5𝑦 == 1}

Example 19: Solve the system of equations x2 + y2 = 25

4x – 5y = 32

Solve[{𝑥2 + 𝑦2 == 25,4𝑥 − 5𝑦 == 32}, {𝑥, 𝑦}, 𝑅𝑒𝑎𝑙𝑠]

the output is {{𝑥 → 3, 𝑦 → −4}, {𝑥 →133

41, 𝑦 → −

156

41}}

Note : {equation 1,equation 2} are the two equations {𝑥2 + 𝑦2 == 25,4𝑥 − 5𝑦 == 32}

The solutions are (x = 3 and y = 4) and (x = 133

41 and y=−

156

41)

Example 20: Solve the system of equations x2 + y2 = – 55

x2 – 5y2 = – 79

Solve[{𝑥2 + 𝑦2 == −55, 𝑥2 − 5𝑦2 == −79}, {𝑥, 𝑦}, Reals] the output is {} there are no Real Solutions

Solve[{𝑥2 + 𝑦2 == −55, 𝑥2 − 5𝑦2 == −79}, {𝑥, 𝑦}, Complexes] The output is

{{𝑥 → −𝑖√59, 𝑦 → −2}, {𝑥 → −𝑖√59, 𝑦 → 2}, {𝑥 → 𝑖√59, 𝑦 → −2}, {𝑥 → 𝑖√59, 𝑦 → 2}}

Note 1: When the Domain used was Reals there were no real solutions and so the output was {}.

Note 2: When the Domain used was Complexes the solution exists and contained some complex

numbers.( x = ±𝑖√59 , y = ± 2 )

Introduction to Mathematica – Calculus I

Page 19 of 52

Example 21: We can introduce a constant like m to the system of equations so we can also solve

system of equations such as

y = mx

y = x2

Solve[{𝑦 == 𝑚𝑥, 𝑦 == 𝑥2}, {𝑥, 𝑦}, Complexes] The output is {{𝑥 → 0, 𝑦 → 0}, {𝑥 → 𝑚, 𝑦 → 𝑚2}}

Note: The solutions are (x = 0 and y = 0) and (x = m and y = m2 )

Example 22: We can introduce constants like a,b and c to the system of equations so we can also solve

system of equations such as, solve the system of equations.

ax + by= 1 cx2 – y2 = 0

Solve[{𝑎𝑥 + by == 1, 𝑐𝑥2 − 𝑦2 == 0}, {𝑥, 𝑦}, Reals]

The output is conditional on the value of c > 0

{{𝑥 → ConditionalExpression[

1−𝑏(−√𝑎2𝑐

(𝑎2−𝑏2𝑐)2+

𝑏𝑐

−𝑎2+𝑏2𝑐)

𝑎, 𝑐 > 0],

𝑦 → ConditionalExpression[−√𝑎2𝑐

(𝑎2 − 𝑏2𝑐)2+

𝑏𝑐

−𝑎2 + 𝑏2𝑐, 𝑐 > 0]},

{𝑥 → ConditionalExpression[

1 − 𝑏 (√𝑎2𝑐

(𝑎2 − 𝑏2𝑐)2 +𝑏𝑐

−𝑎2 + 𝑏2𝑐)

𝑎, 𝑐 > 0],

𝑦 → ConditionalExpression[√𝑎2𝑐

(𝑎2 − 𝑏2𝑐)2+

𝑏𝑐

−𝑎2 + 𝑏2𝑐, 𝑐 > 0]}}

If we use Solve[{𝑎𝑥 + by == 1, 𝑐𝑥2 − 𝑦2 == 0}, {𝑥, 𝑦}, Complexes]

The output is much simpler looking

{{𝑥 →𝑎 − 𝑏√𝑐

𝑎2 − 𝑏2𝑐, 𝑦 →

1 −𝑎2

𝑎2 − 𝑏2𝑐+

𝑎𝑏√𝑐𝑎2 − 𝑏2𝑐

𝑏}, {𝑥 →

𝑎 + 𝑏√𝑐

𝑎2 − 𝑏2𝑐, 𝑦 →

1 −𝑎2

𝑎2 − 𝑏2𝑐−

𝑎𝑏√𝑐𝑎2 − 𝑏2𝑐

𝑏}}

Introduction to Mathematica – Calculus I

Page 20 of 52

The Solve command always return the exact value of a solution, but sometimes this is not what you

require since exact solutions can be extremely complicated looking and impractical to use. If we only

wish to see the numerical value(s) of an equation we can use command NSolve[…..] its syntax is

NSolve[{expression},{variable(s)}]

NSolve[{expression},{variable(s)},domain]

Example 23: Solve the equation 𝑥3 − 5𝑥2 − 3𝑥 = 0

Input: Solve[𝑥3 − 5𝑥2 − 3𝑥 == 0, {𝑥}, Reals]

output {{𝑥 → 0}, {𝑥 →1

2(5 − √37)}, {𝑥 →

1

2(5 + √37)}}

If we solve the same equation using the command NSolve[…] we get.

NSolve[𝑥3 − 5𝑥2 − 3𝑥 == 0, {𝑥}, Reals] output is {{𝑥 → −0.541381}, {𝑥 → 0}, {𝑥 → 5.54138}}

We can alter the precision of the calculations by adding the command WorkingPrecision → 3

NSolve[𝑥3 − 5𝑥2 − 3𝑥 == 0, {𝑥}, Reals, WorkingPrecision → 3] output is {{𝑥 → −0.541}, {𝑥 → 0}, {𝑥 → 5.54}}

We can use NSolve[….] with a system of two equations.

Example 24: Solve the system of equations 4x + 5y = 1

2x2 – 4y2 = 0

NSolve[{4𝑥 + 5𝑦 == 1,2𝑥2 − 4𝑦2 == 0}, {𝑥, 𝑦}, Reals, WorkingPrecision → 5] output is {{𝑥 → 2.153, 𝑦 → −1.5224}, {𝑥 → 0.1327, 𝑦 → 0.09383}}

We can use NSolve[….] with a system of three equations.

Example 25: Solve the system of equations 2x – 6y – 4z = – 22

4x + 5y + 5z = 29

2x2 – 4y2 + z = – 11

NSolve[{2𝑥 − 6𝑦 − 4𝑧 == −22, 𝑥 + 5𝑦 + 5𝑧 == 29,2𝑥2 − 4𝑦2 + 𝑧 == −11}, {𝑥, 𝑦, 𝑧}, Reals, WorkingPrecision → 2]

Output is {{𝑥 → 0.19, 𝑦 → −1.1, 𝑧 → 3. }, {𝑥 → 1. , 𝑦 → 1.0, 𝑧 → 1. }}

Introduction to Mathematica – Calculus I

Page 21 of 52

We can solve Trig Equations exactly and Numerically. The syntax for the Solve[….] command in these

cases are.

Solve[{expression && restriction to x},{variable},domain]

NSolve[{expression && restriction to x},{variable},domain]

Example 26: Solve the trig equation sin(2x) – cos(x) = 0 for values of x in the range 0 ≤ 𝑥 ≤ 𝜋

Solve[{Sin[2𝑥] + Cos[𝑥] == 0&&0 ≤ 𝑥 ≤ 𝜋}, {𝑥}, Reals]

The output is {{𝑥 →𝜋

2}}

Note 1: To get the character ≤ you type in < = and the program will convert it into ≤.

Example 27: Solve the trig equation 2sin2x - sinx – 1 = 0 for values of x in the range 0 ≤ 𝑥 ≤ 2𝜋

Solve[{2Sin[𝑥]2 − Sin[𝑥] − 1 == 0 && 0 ≤ 𝑥 ≤ 2𝜋}, {𝑥}, Reals]

The output is {{𝑥 →𝜋

2}, {𝑥 →

𝜋

2}, {𝑥 →

7𝜋

6}, {𝑥 →

11𝜋

6}}

Note 1: The insertion of the information that x is in the range 0 ≤ 𝑥 ≤ 2𝜋 involved us adding

after the equation, the notation && 0 ≤ 𝑥 ≤ 2𝜋, it’s the equivalent to saying and x is

between 0 and 2𝜋.

Note 2: The solution sometimes contains duplicates, in this case, {𝑥 →𝜋

2}, {𝑥 →

𝜋

2} this

phenomenon is just an idiosyncrasy of Mathematica programming language.

Note 3: Notice that the term 2 sin2 x is written as 2 Sin[x]^2 in Mathematica

Example 28: Solve the trig equation 16cos2x + 2cosx – 3 = 0 for values of x in the range 0 ≤ 𝑥 ≤ 4𝜋

Solve[{16Cos[𝑥]^2 + 2Cos[𝑥] − 3 == 0 && 0 ≤ 𝑥 ≤ 4𝜋}, {𝑥}, Reals]

The output is

{{𝑥 →2𝜋

3}, {𝑥 →

4𝜋

3}, {𝑥 →

8𝜋

3}, {𝑥 →

10𝜋

3}, {𝑥 → 2𝜋 − ArcCos[

3

8]},

{𝑥 → 4𝜋 − ArcCos[3

8]}, {𝑥 → ArcCos[

3

8]}, {𝑥 → 2𝜋 + ArcCos[

3

8]}}

Note 1: The insertion of the information that x is in the range 0 ≤ 𝑥 ≤ 4𝜋 involved us adding

after the equation && 0 ≤ 𝑥 ≤ 4𝜋

Note 2: The solution that contains ArcCos[3

8] this is the same value as 𝑐𝑜𝑠−1 (

3

8)

Introduction to Mathematica – Calculus I

Page 22 of 52

If we do not put restrictions on the value of x then you will get an infinite number of solutions.

Example 29: Solve the trig equation 4cos2 x – 3 = 0 for all values of x.

Solve[{4Cos[𝑥]^2 − 3 == 0}, {𝑥}, Reals]

The output is {{𝑥 → ConditionalExpression[−5𝜋

6+ 2𝜋𝐶[1], 𝐶[1] ∈ Integers]},

{𝑥 → ConditionalExpression [−𝜋

6+ 2𝜋𝐶[1], 𝐶[1] ∈ Integers]},

{𝑥 → ConditionalExpression [𝜋

6+ 2𝜋𝐶[1], 𝐶[1] ∈ Integers]},

{𝑥 → ConditionalExpression[5𝜋

6+ 2𝜋𝐶[1], 𝐶[1] ∈ Integers]}}

Note: We interpret the solution {{𝑥 → ConditionalExpression[−5𝜋

6+ 2𝜋𝐶[1], 𝐶[1] ∈ Integers]},

to mean the solution is 𝑥 = −5𝜋

6+ 2𝜋𝑘 , 𝑤ℎ𝑒𝑟𝑒 𝑘 𝑖𝑠 𝑎𝑛 𝐼𝑛𝑡𝑒𝑔𝑒𝑟

The solution to some Trig equations do not yield exact values that are simple or easy to understand, so it

is a good idea in these situations to find the numerical solutions to the equation instead.

Example 30: Solve the trig equation cosx + tan(2x) = 0 for values of x in the range 0 ≤ 𝑥 ≤ 2𝜋

To find the Exact Solution of cosx + tan(2x) = 0 we would use

Solve[{Cos[𝑥] + 𝑇𝑎𝑛[𝑥] == 0 && 0 ≤ 𝑥 ≤ 2𝜋}, {𝑥}, Reals]

The output is

{{𝑥 → 2𝜋 + 2ArcTan[Root[1 + 2#1 − 2#12 + 2#13 + #14&,1]]}, {𝑥 → 2𝜋 + 2ArcTan[Root[1 + 2#1 − 2#12 + 2#13 + #14&,2]]}}

To find the Numeric Solution of cosx + tan(2x) = 0 we would use

NSolve[{Cos[𝑥] + 𝑇𝑎𝑛[𝑥] == 0 && 0 ≤ 𝑥 ≤ 2𝜋}, {𝑥}, Reals, WorkingPrecision → 3]

The output is {{𝑥 → 1.57}, {𝑥 → 3.51}, {𝑥 → 4.71}, {𝑥 → 5.91}}

Note 1: The Exact solutions to this trig equation are not easy to interpret or understand but if we

find the numerical solution it is much easier to see the values of the solution.

Example 31: Find the numeric solutions to the trig equation secx + tan(2x) = 0 for values of x in the

range 0 ≤ 𝑥 ≤ 2𝜋.

To find the Numeric Solution of sec(x) + tan(2x) = 0 we would use

NSolve[{Sec[𝑥] + 𝑇𝑎𝑛[𝑥] == 0 && 0 ≤ 𝑥 ≤ 2𝜋}, {𝑥}, Reals, WorkingPrecision → 3]

The output is {{𝑥 → 1.02}, {𝑥 → 2.11}, {𝑥 → 3.55}, {𝑥 → 5.87}}

Introduction to Mathematica – Calculus I

Page 23 of 52

In some situations, you may also want the solutions to be in degrees rather than in radians, this can be

done by changing the syntax to incorporate the use of the key word Degree.

Example 32: Solve the Trig equation sin(2x) + cos(x) = 0 for 00 ≤ 𝑥 ≤ 3600

NSolve[{Sin[2𝑥Degree] + Cos[𝑥Degree] == 0 && 0 ≤ 𝑥 ≤ 360}, {𝑥}, Reals]

The output is {{𝑥 →𝜋

2°}, {𝑥 →

7𝜋

6°}, {𝑥 →

3𝜋

2°}, {𝑥 →

11𝜋

6°}}

Version 2 used the NSolve[….] command which gives much more understandable

solutions.

NSolve[{Sin[2𝑥Degree] + Cos[𝑥Degree] == 0 &&0 ≤ 𝑥Degree ≤ 360°}, {𝑥}, Reals]

The output is {{𝑥 → 90. }, {𝑥 → 210. }, {𝑥 → 270. }, {𝑥 → 330. }}

Note 1: Notice the use of the word Degree, instead of Sin[2 x] you need to use Sin[2 x Degree].

Note 2: The exact solution gives an awkward form {𝑥 →𝜋

2°} and because of this when you are

using degrees it is always better to use the NSolve[…] command as the solutions will be

much easier to read and understand.

Example 33: Solve 𝑎

sin (650) =

4

sin (350)

NSolve[{𝑎

Sin[65Degree]==

4

Sin[35Degree] }, {𝑎}, Reals, WorkingPrecision → 3]

The output is {{𝑎 → 6.32}}

Example 34: Solve 2

sin (𝑏) =

14

sin (250)

NSolve[{2

Sin[𝑏Degree]==

14

Sin[25Degree]&&0 ≤ 𝑏Degree ≤ 180°}, {𝑏}, Reals, WorkingPrecision → 3]

The output is {{𝑏 → 3.46}, {𝑏 → 176. }}

Note 1: This Trig needed the restriction 00 ≤ 𝑏 ≤ 1800 as it came from a Sine Rule Problem.

Note 2: The solutions are b = 3.460 and b = 1760

Introduction to Mathematica – Calculus I

Page 24 of 52

7. Introduction to Functions.

We define a function by using the syntax

f[x_]:= expression

Once you have defined a function you can evaluate the function; graph the function or solve equations

that use the function.

To evaluate a function requires two lines of code the first line defines the function the second line of

code uses the function.

For example to evaluate f(5) for the function f(x) = 2𝑥2 − 10𝑥 − 12

The two lines of code will be as follows.

f[x_] := 2𝑥2 − 10𝑥 − 12 then type the normal keyboard ENTER to go to the next line

f[5] then type the number pad ENTER to evaluate the program.

The output will be – 12

We can also evaluate any function in terms of other variables.

For example we can evaluate f(a + h) for the function f(x) = x2 – 2x + 1

The two lines of code will be as follows.

f[x_] := x2 – 2x + 1 then type the normal keyboard ENTER to go to the next line

f[a+h] then type the number pad ENTER to evaluate the program.

The output will be 1 − 2(𝑎 + ℎ) + (𝑎 + ℎ)2

We could also use the Expand command to change the output into a more convenient form.

f[x_] := x2 – 2x + 1 then type the normal keyboard ENTER to go to the next line

Expand[f[a+h] ] then type the number pad ENTER to evaluate the program.

The output will be 1 − 2𝑎 + 𝑎2 − 2ℎ + 2𝑎ℎ + ℎ2

We could also use the Simplify command to change the output into a more convenient form.

f[x_] := x2 – 2x + 1 then type the normal keyboard ENTER to go to the next line

Simplify[f[a+h] ] then type the number pad ENTER to evaluate the program.

The output will be (−1 + 𝑎 + ℎ)2

Introduction to Mathematica – Calculus I

Page 25 of 52

Example 35: Here are some more examples of evaluating a function.

Example 36: We can also define functions with two or more variables and evaluate them.

f[x_,y_] := x2 – 2xy + y2 then type the normal keyboard ENTER to go to the next line

f[1,– 2]] then type the number pad ENTER to evaluate the program.

The output will be 9

Example 37: We can also evaluate any function in terms of other variables.

f[x_,y_] := x2 + y2 then type the normal keyboard ENTER to go to the next line

f[a + b,a – b] then type the number pad ENTER to evaluate the program.

The output will be (𝑎 − 𝑏)2 + (𝑎 + 𝑏)2

Example 38: We could also use the Expand command to change the output into a more convenient

form.

f[x_,y_] := x2 + y2 then type the normal keyboard ENTER to go to the next line

Expand[f[a + b,a – b]] then type the number pad ENTER to evaluate the program.

The output will be be 2𝑎2 + 2𝑏2

We could also use the Simplify command to change the output into a more convenient form.

f[x_] := x2 – 2x + 1 then type the normal keyboard ENTER to go to the next line

Simplify[f[a+h]] then type the number pad ENTER to evaluate the program.

The output will be 2(𝑎2 + 𝑏2)

Function Use Output

𝑓[𝑥_] ≔ 2𝑥2 − 10𝑥 − 12 f[5] – 12

𝑔[𝑥_] ≔ 𝑆𝑖𝑛[𝑥] + 𝐶𝑜𝑠[𝑥] g[𝜋

4] √2

ℎ[𝑡_] ≔ 50𝑒0.02𝑡 h[4] 54.1644

𝑝[𝑥_] ≔𝑥 − 1

𝑥2 + 1 p[0.1] −0.891089

𝑝[𝑥_] ≔𝑥 − 1

𝑥2 − 1 p[a+1]

𝑎

1 − (1 + 𝑎)2

Introduction to Mathematica – Calculus I

Page 26 of 52

A. How to Find the x-intercepts of a function

If you wish to find the x-intercepts of any given function f(x) then you can use these commands

Solve[f[x]==0,{x},Reals]

NSolve[f[x]==0, {x},Reals, WorkingPrecision → 5]

The Solve[…] Command is used if you wish to find the exact values of the x-intercepts

and the NSolve[…] Command is used to find the numerical values of the x-intercepts

Example 39: Find the exact values of the x-intercepts of the function f(x) = 2x4 – 5x2 + 3x

𝑓[x_]: = 2𝑥4 − 5𝑥2 + 3𝑥

Solve[𝑓[𝑥] == 0, {𝑥}, Reals]

Output: {{𝑥 → 0}, {𝑥 → 1}, {𝑥 →1

2(−1 − √7)}, {𝑥 →

1

2(−1 + √7)}}

The x-intercepts will occur when x = 0 , x = 1 x =1

2(−1 − √7) and x =

1

2(−1 + √7)

Example 40: Find the numerical value of the x-intercepts of the function f(x) = 2x4 – 5x2 + 3x

𝑓[x_]: = 2𝑥4 − 5𝑥2 + 3𝑥

NSolve[𝑓[𝑥] == 0, {𝑥}, Reals, WorkingPrecision → 4]

Output: {{𝑥 → −1.823}, {𝑥 → 0}, {𝑥 → 0.8229}, {𝑥 → 1.0}}

The x-intercepts will occur when x = – 1.823 , x = 0 , x =0.8229 and x = 1

If you only wish to find the x-intercepts in a specified domain then you can adapt the Solve[…]

command to incorporate this restriction.

Example 41: Find the exact values of the x-intercepts of the function f(x) = sin(x) – cos(2x) for values

of x in the range −𝜋 ≤ 𝑥 ≤ 𝜋

𝑓[x_]: = Sin[𝑥] − Cos[2𝑥] Solve[{𝑓[𝑥] == 0&& − 𝜋 ≤ 𝑥 ≤ 𝜋}, {𝑥}, Reals]

Output: {{𝑥 → −𝜋

2}, {𝑥 → −

𝜋

2}, {𝑥 →

𝜋

6}, {𝑥 →

5𝜋

6}}

The x-intercepts will occur when x = −𝜋

2 , x =

𝜋

6 and x =

5𝜋

6

Note: If we wanted the numerical solution we would have used command

𝑁Solve[{𝑓[𝑥] == 0&& − 𝜋 ≤ 𝑥 ≤ 𝜋}, {𝑥}, Reals, WorkingPrecision → 3]

Introduction to Mathematica – Calculus I

Page 27 of 52

B. How to Find the Point of Intersection of two Functions

If you wish to find the point(s) where two functions intersect then we can use these commands.

Solve[f[x]==g[x],{x},Reals]

NSolve[f[x]==g[x], {x},Reals, WorkingPrecision → 5]

The Solve[…] Command is used if you wish to find the exact values of the points of intersection.

and the NSolve[…] Command is used to find the numerical values of the points of intersection.

Example 42: Find the exact value of the point(s) of intersection of the functions f(x) = x3 – 5x + 7

and g(x) = x2 – 2x + 5

Input: 𝑓[x_]: = 𝑥3 − 5𝑥 + 7

𝑔[x_]: = 𝑥2 − 2𝑥 + 5

Solve[𝑓[𝑥] == 𝑔[𝑥], {𝑥}, Reals]

Output: {{𝑥 → 2}, {𝑥 →1

2(−1 − √5)}, {𝑥 →

1

2(−1 + √5)}}

The x-coordinates are x = 2 ,x = 1

2(−1 − √5) and x =

1

2(−1 + √5)

To find the y-coordinates to would need to evaluate these x-values with f(x)

The simplest way is to use to evaluate them separately.

f[2] Output 5

f[1

2(−1 − √5)] Output 7 −

5

2(−1 − √5) +

1

8(−1 − √5)3

f[1

2(−1 + √5)] Output 7 −

5

2(−1 + √5) +

1

8(−1 + √5)3

We could Simplify these values by using the Simplify Command.

Simplify[𝑓[2]] Output 5

Simplify[𝑓[1

2(−1 − √5)]] Output

3

2(5 + √5)

Simplify[𝑓[1

2(−1 + √5)]] Output −

3

2(−5 + √5)

So the simplified version of coordinates of the three intersection points are

(2,5) , (1

2(−1 − √5)],

3

2(5 + √5) ) and (

1

2(−1 + √5)], −

3

2(−5 + √5) )

Note: It is more efficient to miss out the stage where you calculate the exact value of each x-

coordinates in the command f[1

2(−1 − √5)] and use the simplified value directly by using the

command Simplify[𝑓[1

2(−1 − √5)]]

Introduction to Mathematica – Calculus I

Page 28 of 52

Example 43: Find the numerical points(s) of intersection of the functions f(x) = sin(2x) + cos(x) and

g(x) = 6 – x2 to 4 Significant Figures.

Input: 𝑓[x_]: = Sin[2𝑥] + Cos[𝑥] 𝑔[x_]: = 6 − 𝑥2

NSolve[𝑓[𝑥] == 𝑔[𝑥], {𝑥}, Reals, WorkingPrecision → 4]

Output: {{𝑥 → −2.395}, {𝑥 → 2.76}}

The x-coordinates are x = −2.395 and x = 2.76

To find the y-coordinates we calculate

f[−2.395] Output: 0.262983

f[2.76] Output: −1.6193

So the coordinates of the two intersection points are

(−2.395 , 0.262983) and (2.76 , −1.6193)

Example 44: Find the numerical points of intersection of the functions f(x) = sin(2x) – x and

g(x) = 6 – x4 in the range 0 ≤ 𝑥 ≤ 𝜋 to 3 Significant Figures.

Input: 𝑓[x_]: = Sin[2𝑥] −x

𝑔[x_]: = 6 − 𝑥4

NSolve[{𝑓[𝑥] == 𝑔[𝑥]&&0 ≤ 𝑥 ≤ 𝜋}, {𝑥}, Reals, WorkingPrecision → 3]

Output: {{𝑥 → 1.68}}

The x-coordinate of the point of intersection is x = 1.68

To find the y-coordinates we calculate

Input: f[1.68]

Output: −1.89668

So the coordinate of the intersection points is (1.68 , −1.89668)

Note: If we had used the command

NSolve[{𝑓[𝑥] == 𝑔[𝑥]&& − 𝜋 ≤ 𝑥 ≤ 𝜋}, {𝑥}, Reals, WorkingPrecision → 3] We would have found the second point of intersection at x = – 1.88 which would have

given us the points of intersection of (3.04 , −3.24179) and (−1.88 , 2.45974))

Introduction to Mathematica – Calculus I

Page 29 of 52

8. How to Graph a Function.

A. How to graph a single functions.

The syntax used to plot the graph of a function is

Plot[expression,{x,xmin,xmax},options }

expressions Is the formula for the functionit can be f[x] or it can be written the

form x3 – Sin[x]

{x,xmin,xmax} Is the domain of the function , for example {x,– 8 ,5} will plot the

graph in the range x = – 8 to x = 5

options Are a list of commands that effect the look and feel of the graph,

there are many attributes you could include in your plot.

Here is a list of the main ones that are typically used.

PlotRange → Full This defines the range of y-values if you use Full then it will try to

Plot the function containing all y-values in the domain of x.

PlotRange → {−2,5} This will graph the function from y = 0 – 2 to 5 and any portion

of the graph outside this range will not be shown.

PlotLabels → "Expressions" This adds a label at the top of the graph.

AxesLabel → {"x", "y"} Puts a label x on the x-axis, and y on the y-axis.

PlotStyle → (Red, Thick} This gives the color of the graph, it can be Red , Blue , Green as

well as Thick , Thin , Dotted etc…

Ticks → Automatic This will put ticks on both axis between the major values.

Ticks → {{π, 2π, 3π}, {−1,1}} This will only put ticks at 𝑥 = π, 𝑥 = 2π 𝑎𝑛𝑑 𝑥 = 3π on the x-axis

and at y = – 1 and y = 1 on the y-axis.

GridLines → Automatic This will add equally spaced gridlines to the x and y axis at

positions that Mathematica decides automatically.

GridLines → {{π, 2π}, {−1,1}} This will only put Grid Lines at 𝑥 = π 𝑎𝑛𝑑 𝑥 = 2π on the x-axis

and at y = – 1 and y = 1 on the y-axis.

Introduction to Mathematica – Calculus I

Page 30 of 52

Example 45: Graph the function y = sin(x2) for values of x in the domain −2𝜋 ≤ 𝑥 ≤ 2𝜋.

Input: Plot[ Sin[𝑥2], {𝑥, −2𝜋, 2𝜋}, PlotStyle → {Red, Thick}

, ]

Sin[x^2] Is the graph being plotted

{𝑥, −2𝜋, 2𝜋} Is the domain being graphed in this case −2𝜋 ≤ 𝑥 ≤ 2𝜋

PlotStyle → {Red, Thick}] Makes the graph Red and Thick.

Output

Note 1: We could have written the code in the form

Plot[{Sin[𝑥^2]}, {𝑥, −2𝜋, 2𝜋}, PlotStyle → {Red, Thick}]

But it is goof practice to write code in a separated form to help with reading the code and

to help with debugging when errors occur.

Note 2: Notice that as the code for a single command get longer it is very difficult to read and to

keep track of the brackets. For this reason it is good practice to set out the Plot[….]

Command in the format shown above.

Note 2: Notice that you start with Plot[ and the last line is ] and that each option is written on its

own line with a comma at the end.

6 4 2 2 4 6

1.0

0.5

0.5

1.0

Introduction to Mathematica – Calculus I

Page 31 of 52

Example 46: Graph the function y = x3-4x2+3x+1 for values of x in the domain [−2,4]..

Input: 𝑓[x_]: = 𝑥3 − 4𝑥2 + 3𝑥 + 1

Plot[ 𝑓[𝑥], {𝑥, −2,4}, PlotLabel → "f(x) = "x3" − 4"x2" + 3x + 1", PlotStyle → {Blue, Thin}, AxesLabel → {"x", "y"}

]

f[x] Is the graph being plotted

{𝑥, −2,4} Is the domain being graphed in this case −2 ≤ 𝑥 ≤ 4

PlotLabel→"f(x)" Is the label at the top of the graph f(x)

PlotStyle →{Blue,Thin}] Makes the graph Blue and Thin.

AxesLabel → {x, y} Adds the labels x and y to the axes

Output

Note: We could have written the program using one line of code.

Plot[f[x],{x,-2,4},PlotLabel→"f(x)",PlotStyle →{Blue,Thin}, AxesLabel → {x, y}

2 1 1 2 3 4x

15

10

5

5

10

y

f x x3

4x2

3x 1

Introduction to Mathematica – Calculus I

Page 32 of 52

Example 47: Graph the function f(x) = 𝑥3 − 4𝑥 for values of x in the domain [– 3 , 3].

Input: Plot[ 𝑓[𝑥], {𝑥, −3,3}, PlotLabel → Style["f(x)=x3-4x", Red], PlotStyle → {Blue, Thick}, AxesLabel → {"x", "y"}

]

f[x] Is the graph being plotted

{𝑥, −3,3} Is the domain being graphed in this case −2 ≤ 𝑥 ≤ 2

PlotRange → {−9,20} Restrict the y-values to the range – 9 to 20

Style["f(x) = "x3 − 4x", Red] Is the label at the top of the graph f(x) = x3 − 4x but

it will be Red in color

PlotStyle →{Green,Thick}] Makes the graph Green and Thick.

AxesLabel → {x, y} Adds the labels x and y to the axes

Output

When you use the format you get the added benefit that you can add comments to your program by

typing (* whatever you want to say *) beside each line of code.

Plot[ (*The start of the Plot command *)

𝑓[𝑥]{𝑥, −3,3}, PlotLabel → Style[f(x)=x3-4x, Red], PlotStyle → {Blue, Thick}, (*This makes the graph Blue and Thick*)

AxesLabel → {x, y}

] (*The end of the Plot command *)

3 2 1 1 2 3x

5

5

10

15

20y

f x x3

4x

Introduction to Mathematica – Calculus I

Page 33 of 52

Example 48: Graph the function v(t) = sin(t) + 2cos2(t) for values of t in the domain 0 ≤ 𝑡 ≤ 2𝜋.

Input: 𝑣[t_]: = Sin[𝑡] + 2Cos[𝑡]^2 Plot[ 𝑣[𝑡], {𝑡, −2𝜋, 2𝜋},

PlotLabel → Style["v(t) = sin(t) + 2"cos2"(t)", {Blue, Thick}], PlotStyle → {Red, Thick}, AxesLabel → {"t (time)", "v (velocity)"}, Ticks → {{−2𝜋, −𝜋, 0, 𝜋, 2𝜋}, {−2, −1.5, −1, −0.5,0.5,1.5,2}}, GridLines → {{−2𝜋, −𝜋, 0, 𝜋, 2𝜋}, {−2, −1.5, −1, −0.5,0,0.5,1,1.5,2}} ]

v[t] Is the graph being plotted {𝑡, −2𝜋, 2𝜋} Is the domain being graphed in this case −2π ≤ 𝑡 ≤ 2π

PlotLabel → Style, [”f(t)= Sin[t]+2cos[t]^2”,{Blue,Thick}]

Is the label at the top of the graph v(t) = sin(t) + 2cos2(t) , Blue in color and Thick

PlotStyle →{Red,Thick}] Makes the graph Red and Thick.

AxesLabel→{"t (time)","v (velocity)"} Adds the labels t (time) and v (velocity) to the axes

Ticks→{{-2π,-π,0,π,2π},{-2,-1.5,-1,-0.5,0.5,1.5,2}} Puts tick marks on the x-axis at positions -2π,-π,0,π,2π and Puts tick marks on the y-axis -2,-1.5,-1,-0.5,0.5,1.5,2

GridLines→{{-2π,-π,0,π,2π},{-2,-1.5,-1,-0.5,0,0.5,1,1.5,2}} Puts grid lines on the x-axis at positions -2π,-π,0,π,2π and Puts grid lines on the y-axis -2,-1.5,-1,-0.5,0.5,1.5,2

Output

Introduction to Mathematica – Calculus I

Page 34 of 52

B. How to graph multiple functions.

Plot[{expression1,expression2},{x,xmin,xmax},options }

expressions 1,expression2 Are the two formulas for the functions we can use f[x] ,g[x] it can

or it can be in the form x3 – Sin[x], 2x2 – x + 1

{x,xmin,xmax} Is the domain of the functions , for example {x,– 8 ,5} will plot

the graph of the two functions in the range x = – 8 to x = 5

options Are a list of commands that effect the look and feel of the graph,

there are many options you could include in your Plot command.

PlotRange → Full This defines the range of y-values if you use Full then it will try to

Plot the function containing all y-values in the domain of x.

PlotRange → {−2,5} This will graph the function from y = 0 – 2 to 5 and any portion

of the graph outside this range will not be shown.

PlotLegends→ "Expressions" This adds a legend to the side of the graph to indicate the function.

PlotLabel →"heading title here" This adds a heading at the top of the graph.

PlotLabels → "Expressions" This adds a label next to each graph.

AxesLabel → {"x", "y"} Puts a label x on the x-axis, and y on the y-axis.

PlotStyle → (Red, Thick} This gives the color of the graph, it can be Red , Blue , Green as

well as Thick , Thin , Dotted etc…

Ticks → Automatic This will put ticks on both axis between the major values.

Ticks → {{π, 2π, 3π}, {−1,1}} This will only put ticks at 𝑥 = π, 𝑥 = 2π 𝑎𝑛𝑑 𝑥 = 3π on the x-axis

and at y = – 1 and y = 1 on the y-axis.

GridLines → Automatic This will add equally spaced gridlines to the x and y axis at

positions that Mathematica decides automatically.

GridLines → {{π, 2π}, {−1,1}} This will only put Grid Lines at 𝑥 = π 𝑎𝑛𝑑 𝑥 = 2π on the x-axis

and at y = – 1 and y = 1 on the y-axis.

Introduction to Mathematica – Calculus I

Page 35 of 52

Example 49: Graph the functions y = sin(x) , y = cos(x) for values of x on the domain −2𝜋 ≤ 𝑥 ≤ 2𝜋.

Input: Plot[ {Sin[𝑥], Cos[𝑥]}, {𝑥, −2𝜋, 2𝜋}, PlotStyle → {{Red, Thick}, {Blue, Thin}}

]

Sin[x] and Cos[x] Are the graphs being plotted.

{𝑥, −2𝜋, 2𝜋} Is the domain being graphed in this case −2𝜋 ≤ 𝑥 ≤ 2𝜋

PlotStyle → {{Red, Thick}, {𝐵𝑙𝑢𝑒, 𝑇ℎ𝑖𝑛}]

Makes the first graph Red and Thick and the second graph Blue and Thin.

Output

6 4 2 2 4 6

1.0

0.5

0.5

1.0

Introduction to Mathematica – Calculus I

Page 36 of 52

Example 50: Graph the functions f(x) = xsin(x) and g(x) = csc(x) for values of x on the domain

−𝜋 ≤ 𝑥 ≤ 2𝜋.

𝑓[x ]: = 𝑥Sin[𝑥] 𝑔[x_]: = Csc[𝑥] Plot[ {f[𝑥], g[𝑥]},

{𝑥, −𝜋, 2𝜋},

PlotStyle → {{Red, Thick}, {Blue, Thin}}, AxesLabel → {"x", "y"},

PlotLegends → {"f(x) = x sin(x)", "g(x) = sec(x)"}

]

PlotStyle → {{Red, Thick}, {Blue, Thin}}

Draws the graph of f(x) in Thick Red color and the graph of g(x) in a Thin Blue color.

AxesLabel → {"x", "y"} Adds labels to the x and y – axis.

PlotLegends → {"f(x) = x sin(x)", "g(x) = sec(x)"}

gives labels to each graph in the form of a Legend at the right-hand side of the graph.

Output

Note 1: When you add an option such as PlotStyle → {{Red, Thick}, {Blue, Thin}} the first

attribute is applied to the first function being plotted (in this case f[x] ) and the second

attribute is applied to the second function being plotted (in this case g[x] )

Note 2: You can add as many functions to the plot command by changing Plot[{f[x],g[x]}, ……]

Into the command Plot[{f[x],g[x],h[x],p[x]},…….]

2 2 4 6x

5

5

y

Introduction to Mathematica – Calculus I

Page 37 of 52

Example 51: Graph the functions f(x) = ex and g(x) = x3 – 4x for values of x on the domain

−3 ≤ 𝑥 ≤ 2.5.

Input: 𝑓[x_]: = 𝑒𝑥

𝑔[x_]: = 𝑥3 − 4𝑥

Plot[ {𝑓[𝑥], 𝑔[𝑥]}, {𝑥, −3,2.5}, PlotStyle → {{Black, Thick}, {Green, Thick}},

AxesLabel → {x,y}, PlotLabel → The graphs of f(x) and g(x)}, GridLines → Automatic

GridLinesStyle → 𝑅𝑒𝑑 ]

PlotLabels→{"f(x)= ex","g(x) = x3-4x"}]

adds labels to the end of each function.

GridLines → Automatic adds gridlines at suitable evenly spaced places.

GridLinesStyle → 𝑅𝑒𝑑

Make the horizontal and vertical gridlines Red.

Output

Note : We could have added many other options to change the appearance of the graph, for

example, we could have added GridLinesStyle → {{Red, Thick}, {Blue, Thin}} which

would affect how the grid lines are drawn.

Look up the Help menu for the other option choices that can be used with the Plot[…]

command – Just type Plot in the Help in wolfram documentation Tab.

f x ex

g x x3

4x

3 2 1 1 2x

10

5

5

10

y

The graphs of f x and g x

Introduction to Mathematica – Calculus I

Page 38 of 52

C. How to Use Manipulate with Graphs of Functions

The manipulate command allows us to introduce another variable that we can alter its value interactively

and it will alter the graph being plotted.

The Syntax for the Manipulate[….] Command are

Manipulate[Plot[……..],{a,amin ,amax }]

Manipulate[Plot[……..],{ a,amin ,amax,increnents}]

Example 52: Create a Manipulate form of the graph of sin(ax) for values of x in the domain

−2𝜋 ≤ 𝑥 ≤ 2𝜋 and with a varying from a = – 5 to a = 5

Input: Manipulate[ Plot[ Sin[𝑎𝑥], {𝑥, −2𝜋, 2𝜋}], {𝑎, 0,4}

]

Output:

You can move the slider at the top and as each

position corresponds to a value of a you will get

an updated graph of Sin [a x].

Also, if you click on the + sign on the right you

get a set of controls that allow you to animate

the graph as well as other options.

Introduction to Mathematica – Calculus I

Page 39 of 52

Example 53: Create a Manipulate form of the graphs y = ex + a and y = x3 + bx for values of x in the

domain −2 ≤ 𝑥 ≤ 2 and with a varying from a = – 5 to a = 5 and b varying from

b = – 4 to b = 4

Input: Manipulate[

Plot[ {𝑒𝑥 + 𝑎, 𝑥3 + 𝑏𝑥}, {𝑥, −2,2}, PlotStyle → {{Black, Thick}, {Green, Thick}}, AxesLabel → {"x", "y"}, PlotLabel → "The graphs of f(x) and g(x)}", PlotLabels → {"f(x) = "ex" + a", "g(x) = "x3" + bx"}, GridLines → Automatic, GridLinesStyle → Red ]

{𝑎, −5,5,1}, {𝑏, −4,4,0.1}

]

Output:

Note 1: Notice that we had to change the program and not define f[x_] and g[x_] but to use their

formulas inside the Plot[…] Command as Plot[{𝑒𝑥 + 𝑎, 𝑥3 + 𝑏𝑥}, … ..

Note 2: If we added the option PlotRange → {−5,5} then the y-values will be fixed and all the

variations of the graphs will be contained in the same diagram.

Introduction to Mathematica – Calculus I

Page 40 of 52

9. Finding Limits.

To find the limit of an expression we use the following Syntax.

Limit[expression, 𝑥 → 𝑣𝑎𝑙𝑢𝑒]

Limit[expression, 𝑥 → 𝑣𝑎𝑙𝑢𝑒, 𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 → 1]

Limit[expression, 𝑥 → 𝑣𝑎𝑙𝑢𝑒, 𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 → −1]

expression is the algebraic expression that the limit is using

𝑥 → 𝑣𝑎𝑙𝑢𝑒 is in the form 𝑥 → 3 or 𝑥 → ∞

𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 → 1 means that you will be evaluating a right-hand limit like 𝑥 → 3+

𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 → −1 means that you will be evaluating a left-hand limit like 𝑥 → 3−

Example 54: Here are some examples of using the Limit[…] Command.

Note: ln(x) is written as Log[x] if we wanted to have log10(x) we would use the command

Log10[x] – you can find both these commands in the Advanced Tab of the Basic Math

Palette.

Limit Input Format Output

lim𝑥→0

sin (𝑥)

𝑥

Limit[

Sin[𝑥]

𝑥, 𝑥 → 0] 1

lim𝑥→1

𝑥 − 3

𝑥2 − 9

Limit[

𝑥 − 3

𝑥2 − 9, 𝑥 → 3]

1

6

lim𝑥→4

√𝑥 + 5 − 3

𝑥 − 4

Limit[

√𝑥 + 5 − 3

𝑥 − 4, 𝑥 → 4]

1

6

lim𝑥→0+

𝑥𝑙𝑛(𝑥)

Limit[𝑥Log[𝑥], 𝑥 → 0, Direction → 1] 0

lim𝑥→7−

𝑥3 + 10

𝑥 − 7

Limit[

𝑥3 + 10

𝑥 − 7, 𝑥 → 7, Direction → −1] ∞

lim𝑥→∞

𝑥 − 7

𝑥2 − 2𝑥 + 6

Limit[

𝑥 − 7

𝑥2 − 2𝑥 + 6, 𝑥 → ∞] 0

lim𝑥→−∞

2𝑥3 + 4𝑥 − 1

6𝑥3 − 𝑥

Limit[

2𝑥3 + 4𝑥 − 1

6𝑥3 − 𝑥, 𝑥 → −∞]

1

3

Introduction to Mathematica – Calculus I

Page 41 of 52

We can use limits to find the slope of a tangent line at any given point using one of the two definitions

below.

mtan = limℎ→0

f(𝑎+ℎ)−𝑓(𝑎)

ℎ mtan = lim

𝑥→𝑎

f(𝑥))−𝑓(𝑎)

𝑥−𝑎

Example 55: Find the slope of the tangent line to the curve f(x) = x3 + x2 + x at x = 2

Solution: We find mtan = limℎ→0

f(2+ℎ)−𝑓(2)

Input 𝑓[x_]: = 𝑥3 + 𝑥2 + 𝑥

Limit[𝑓[2 + ℎ] − 𝑓[2]

ℎ, ℎ → 0]

Output: 17

So the slope of the tangent line at x = 2 is 17.

Alternate Solution: We find mtan = lim𝑥→2

f(𝑥)−𝑓(2)

𝑥−2

Input 𝑓[x_]: = 𝑥3 + 𝑥2 + 𝑥

Limit[𝑓[𝑥] − 𝑓[2]

𝑥 − 2, 𝑥 → 0]

Output: 17

So the slope of the tangent line at x = 2 is 17.

Example 56: Find the slope of the tangent line to the curve f(x) = 𝑥+5

𝑥2+1 at x = a

Solution: We find mtan = limℎ→0

f(𝑎+ℎ)−𝑓(𝑎)

Input 𝑓[x_]: =𝑥+5

𝑥2+1

Limit[𝑓[𝑎 + ℎ] − 𝑓[𝑎]

ℎ, ℎ → 0

Output: −−1+10𝑎+𝑎2

(1+𝑎2)2

So, the slope of the tangent line at x = a is −−1+10𝑎+𝑎2

(1+𝑎2)2

Introduction to Mathematica – Calculus I

Page 42 of 52

10. Finding Derivatives.

A. Finding First Derivatives

To find the derivative of a function we use the following Syntax. D[f[x],x] or 𝑓′[𝑥]

Example 57: Here are some examples of finding Simple derivatives.

Note 1: Some of the derivatives are not simplified as much as they could be, you can fix this by

combining the derivative command with others to achieve a more efficient form of the

derivative, for example

Simplify[𝑒Sin[𝑥]Cos[𝑥]2 − 𝑒Sin[𝑥]Sin[𝑥]] output 𝑒Sin[𝑥](Cos[𝑥]2 − Sin[𝑥])

Together[Cos[𝑥]

𝑥−

Sin[𝑥]

𝑥2 ] output 𝑥Cos[𝑥]−Sin[𝑥]

𝑥2

Together [2𝑥

−1+𝑥2 −2𝑥(1+𝑥2)

(−1+𝑥2)2] output −4𝑥

(−1+𝑥2)2

Note 2: You can combine the two commands together to achieve the same effect so we could

write Together[𝐷[𝑥2+1

𝑥2−1, 𝑥]] to achieve the final output

2𝑥

−1+𝑥2 −2𝑥(1+𝑥2)

(−1+𝑥2)2

Note 3: Be careful when using exponential functions like ex or esinx as the e is a special button on

the Basic Math Palette, so be careful and don’t use the keyboard e as it will not work.

Function Input Format Output

f(x) = sin (𝑥)

𝑥 D[

Sin[𝑥]

𝑥, {𝑥}]

Cos[𝑥]

𝑥−

Sin[𝑥]

𝑥2

g(x) = 𝑥2+1

𝑥2−1 𝐷[

𝑥2 + 1

𝑥2 − 1, {𝑥}]

2𝑥

−1 + 𝑥2−

2𝑥(1 + 𝑥2)

(−1 + 𝑥2)2

h(x) = 𝑒sin (𝑥)cos (𝑥) 𝐷[𝑒Sin[𝑥]Cos[𝑥], {𝑥}] 𝑒Sin[𝑥]Cos[𝑥]2 − 𝑒Sin[𝑥]Sin[𝑥]

f(x) = √𝑠𝑖𝑛𝑥 + 𝑐𝑜𝑠𝑥 𝐷[√Sin[𝑥] + Cos[𝑥], {𝑥}] Cos[𝑥] − Sin[𝑥]

2√Cos[𝑥] + Sin[𝑥]

g(x) = xx 𝐷[𝑥𝑥 , {𝑥}] 𝑥𝑥(1 + Log[𝑥])

h(x) = (𝑥 +1

𝑥)

10

𝐷[(𝑥 +1

𝑥)10, {𝑥}] 10(1 −

1

𝑥2)(

1

𝑥+ 𝑥)9

Introduction to Mathematica – Calculus I

Page 43 of 52

B. Finding Second and Higher Derivatives using 𝑓′′[𝑥]

To find second or higher derivatives we use the syntax.

𝑓′′[𝑥]

Example 58: Find the first three derivatives of f(x) = x3 – 6sin(x2)

Input: 𝑓[x_]: = 𝑥3 − 6Sin[𝑥2]

𝑓′[𝑥] 𝑓′′[𝑥] 𝑓′′′[𝑥]

Output 3𝑥2 − 12𝑥Cos[𝑥2] 6𝑥 − 12Cos[𝑥2] + 24𝑥2Sin[𝑥2] −12𝑥Cos[𝑥2] + 8𝑥3Sin[𝑥2]

Note : If you wish to give the derivative in a simpler form you can combine the two commands

by adding Simplify[….] or Together[…] with the derivative command.

𝑓[x_]: = 𝑥3 − 6Sin[𝑥2]

Together[𝑓′[𝑥]]

Output 3𝑥(𝑥 − 4Cos[𝑥2])

Example 59: Find the 5th derivative of g(x) = xexsin(x)

Input: 𝑔[x_]: = 𝑥𝑒𝑥Sin[𝑥]

𝑓′′′′′[𝑥]

Output −4𝑒𝑥𝑥Cos[𝑥] − 20𝑒𝑥Sin[𝑥] − 4𝑒𝑥𝑥Sin[𝑥]

Note 1: We can simplify the result by using Simplify[𝑓′′′′′[𝑥]]

Output: −4𝑒𝑥(𝑥Cos[𝑥] + (5 + 𝑥)Sin[𝑥])

Note 2: This notation is very cumbersome for Higher derivatives such as 𝑔′′′′′′′′′′[𝑥] , the tenth

derivative. So it is more efficient to use the syntax D[g[x],{x,10}]

Introduction to Mathematica – Calculus I

Page 44 of 52

C. Finding Second and Higher Derivatives using D[f[x],{x,n}]

To find second or higher derivatives we use the syntax.

. D[f[x],{x,n}]

f[x] is the function

{x,n} is the variable we to differentiate with respect to and n is the level of the derivative.

Example 60: Find the 10th derivative of g(x) = ex cos(x)

Input: 𝑔[x_]: = 𝑒𝑥Cos[𝑥] 𝐷[𝑔[𝑥], {𝑥, 10}]

Output: −32𝑒𝑥Sin[𝑥]

Example 61: For the position function s(t) = t2 + 5t – 4cos(t) find the velocity function v(t) and the

acceleration functions a(t).

The velocity function is the first derivative of the position function s(t) and

the acceleration function is the second derivative of the position function s(t)

Input: 𝑠[𝑡]: = 𝑡2 + 5𝑡 − 4Cos[𝑡] (*the position function*) 𝑣[𝑡 ] ≔ 𝐷[𝑠[𝑡], {𝑡, 1}] (*the velocity function*)

𝑎[𝑡 ] ≔ 𝐷[𝑠[𝑡], {𝑡, 2}] (*the acceleration function*) s[t_]

v[t_]

a[t_]

Output: 𝑡2 + 5𝑡 − 4Cos[𝑡] 5 + 2𝑡 + 4Sin[𝑡]

2 + 4Cos[𝑡]

So the velocity function will be v(t) = 5 + 2𝑡 + 4Sin[𝑡] The acceleration function will be a(t) = 2 + 4Cos[𝑡]

Note : In this program, we added comments to the right hand side of each command to help the

reader understand what the line of code is doing.

The format for comments command is (* …….put comment here ………….. *)

Introduction to Mathematica – Calculus I

Page 45 of 52

D. Implicit Differentiation.

It is possible to find the derivative of implicit formula f(x,y) = 0 by finding the value of the expression.

−𝐷[𝑓[𝑥, 𝑦], {𝑦, 1}]

𝐷[𝑓[𝑥, 𝑦], {𝑥, 1}]

Example 62: Find the first derivative of implicit formula x3 + 5xy + exy = 0

Input: 𝑓[𝑥, 𝑦]: = 𝑥3 + 5𝑥𝑦 + 𝑒𝑥𝑦

−𝐷[𝑓[𝑥,𝑦],{𝑦,1}]

𝐷[𝑓[𝑥,𝑦],{𝑥,1}]

Output: −5𝑥+ⅇ𝑥𝑦𝑥

3𝑥2+5𝑦+ⅇ𝑥𝑦𝑦

So 𝑑𝑦

𝑑𝑥 = −

5𝑥+ⅇ𝑥𝑦𝑥

3𝑥2+5𝑦+ⅇ𝑥𝑦𝑦

Note: We could have simplified the result by using this code.

𝑓[𝑥, 𝑦]: = 𝑥3 + 5𝑥𝑦 + 𝑒𝑥𝑦

Simplify[−𝐷[𝑓[𝑥,𝑦],{𝑦,1}]

𝐷[𝑓[𝑥,𝑦],{𝑥,1}]]

Output: −(5+ⅇ𝑥𝑦)𝑥

3𝑥2+(5+ⅇ𝑥𝑦)𝑦

Example 63: Find the first derivative of 𝑙𝑛(𝑥 + 𝑦) + 𝑥 – ⅇ𝑥

√𝑥+𝑦 = 0

Input: 𝑓[𝑥, 𝑦]: =Log[𝑥+𝑦]+𝑥−ⅇ𝑥

√𝑥+𝑦

Simplify[−𝐷[𝑓[𝑥,𝑦],{𝑦,1}]

𝐷[𝑓[𝑥,𝑦],{𝑥,1}]]

Output: 2+ⅇ𝑥−𝑥−Log[𝑥+𝑦]

−2−𝑥−2𝑦+ⅇ𝑥(−1+2𝑥+2𝑦)+Log[𝑥+𝑦]

So 𝑑𝑦

𝑑𝑥 =

2+ⅇ𝑥−𝑥−Log[𝑥+𝑦]

−2−𝑥−2𝑦+ⅇ𝑥(−1+2𝑥+2𝑦)+Log[𝑥+𝑦]

Note 1: We used the command Simplify[−𝐷[𝑓[𝑥,𝑦],{𝑦,1}]

𝐷[𝑓[𝑥,𝑦],{𝑥,1}]] to make the final derivative as simplified

as possible, if we did not do this the result would have been very complicated looking.

Note 2: ln(x + y) is written as Log[x + y] this is an idiosyncracy of Mathematica , also if you

wanted to write log10(x) it would be written as Log10[x] in Mathematica.

Introduction to Mathematica – Calculus I

Page 46 of 52

E. Derivatives with Constants.

Mathematica can deal with derivatives of functions that contain constant terms.

Example 64: Find the Derivative of the general quadratic function f(x) = ax2 + bx + c

Input: 𝑓[x_]: = 𝑎𝑥2 + 𝑏𝑥 + 𝑐

𝑓′[𝑥]

Output: 𝑏 + 2𝑎𝑥

So 𝑓′(𝑥) = 2𝑎𝑥 + 𝑏

Note: You must be careful when typing in ax2 + bx + c , you must put spaces betwee the

constants and the variable x as follows a x2 + b x + c.

This is a very simple thing to omit and causes a lot of problems if you are not careful.

Example 65: Find the first and second derivative of f(x) = 𝑎𝑥+𝑏

𝑏𝑥+𝑎

Input: 𝑓[x_]: =𝑎𝑥+𝑏

𝑏𝑥+𝑎

𝑓′[𝑥] 𝑓''[𝑥]

Output: −𝑏(𝑏+𝑎𝑥)

(𝑎+𝑏𝑥)2 +𝑎

𝑎+𝑏𝑥

2𝑏2(𝑏+𝑎𝑥)

(𝑎+𝑏𝑥)3 −2𝑎𝑏

(𝑎+𝑏𝑥)2

This means that f(x) = −𝑏(𝑏+𝑎𝑥)

(𝑎+𝑏𝑥)2 +𝑎

𝑎+𝑏𝑥 and 𝑓′(𝑥) =

2𝑏2(𝑏+𝑎𝑥)

(𝑎+𝑏𝑥)3 −2𝑎𝑏

(𝑎+𝑏𝑥)2

We could make these expressions much simler looking by adding the Together[….]

command so that the new program and output would become.

Input: 𝑓[x_]: =𝑎𝑥+𝑏

𝑏𝑥+𝑎

Together[𝑓′[𝑥]] Together[𝑓''[𝑥]]

Output: 𝑎2−𝑏2

(𝑎+𝑏𝑥)2

2(−𝑎2𝑏+𝑏3)

(𝑎+𝑏𝑥)3

This means that f(x) = 𝑎2−𝑏2

(𝑎+𝑏𝑥)2and 𝑓′(𝑥) =2(−𝑎2𝑏+𝑏3)

(𝑎+𝑏𝑥)3

Introduction to Mathematica – Calculus I

Page 47 of 52

11. Application of Derivatives.

A. Evaluating Derivatives

Example 66: Find the exact value of 𝑓′(𝜋

3) for the function f(x) = xesinx

Input: (version 1) 𝑓[x_]: = 𝑥𝑒Sin[𝑥]

𝑓′[𝜋

3]

Output: 𝑒√3

2 +1

6𝑒

√3

2 𝜋 So 𝑓′(𝜋

3) = 𝑒

√3

2 +1

6𝑒

√3

2 𝜋

Input: (version 2) 𝑓[x_]: = 𝑥𝑒Sin[𝑥]

Simplify[𝑓′[𝜋

3]]

Output: 1

6𝑒

√3

2 (6 + 𝜋) So 𝑓′(𝜋

3) =

1

6𝑒

√3

2 (6 + 𝜋)

Example 67: Find the numerical value of 𝑓′(√2) for the function f(x) = 𝑥+2𝑥3

𝑥−6 correct to 4 significant

figures.

Input: 𝑓[x_]: =𝑥+2𝑥3

𝑥−6

𝑁[𝑓′[√2],4]

Output: −3.171

So the numerical value of 𝑓′(√2) = −3.171 (to 4 significant figures)

Example 68: What is the acceleration of the object with position function s(t) = 4t3 + 8√𝑡 when t = 4.

To find the acceleration at t = 4 seconds we need to find 𝑓′′(𝑡) at t = 4.

Input: 𝑓[t_]: = 4𝑡3 + 8√𝑡

𝑓′′[4]

Output: 383

4

So the velocity of the object at t = 4 sec is 383

4 m/sec.

Introduction to Mathematica – Calculus I

Page 48 of 52

B. Graphing Derivatives

To graph a derivative and the original function we will use the syntax.

Plot[{f[x],𝑓′[𝑥]},{x,xmin,xmax},options }

f[x] will be the original function

𝑓′[𝑥] will be the first derivative of f[x]

{x,xmin,xmax} Is the domain of the function, for example {x,-4,6} will plot the graph of the two

Functions in the range x = – 4 to x = 6.

options Are a list of commands that effect the look and feel of the graph , there are many

options to see a list look up How to plot a function section.

Example 69: Plot the function f(x) = sin(x) + cos(x) + x and its derivative 𝑓′[𝑥] in the interval

−2𝜋 ≤ 𝑥 ≤ 2𝜋.

Input: f[x_]:=Sin[x] + Cos[x] + x

Plot[

{𝑓[𝑥], 𝑓′[𝑥]}, {𝑥, −2𝜋, 2𝜋},

PlotStyle → {{Blue, Thick}, {Green, Thick}}, AxesLabel → {"x", "y"}, AxesStyle → {{Black, Thick}, {Black, Thick}},

PlotLabel → "The graphs of f(x) and f′(x)}", PlotLabels → {"f(x)", "f′(x)"},

GridLines → Automatic, GridLinesStyle→{{Red,Thin},{Red,Thin}}

]

Output:

Introduction to Mathematica – Calculus I

Page 49 of 52

Example 70: Plot the function f(x) = x3 + 5x2 – 6x and its derivative 𝑓′[𝑥] and 𝑓′′[𝑥] in the interval

−2 ≤ 𝑥 ≤ 2

Input: [x_]: = 𝑥3 + 5𝑥2 − 6𝑥 Plot[ {𝑓[𝑥], 𝑓′[𝑥], 𝑓''[𝑥]}, {𝑥, −2,2}, PlotStyle → {{Blue, Thick}, {Green, Thick}, {Orange, Thick}}, AxesLabel → {"x", "y"}, AxesStyle → {{Black, Thick}, {Black, Thick}}, PlotLabel → The graphs of f(x), f'[x] and f''(x)}, PlotLabels → {"f(x)", "f′(x)", "f′′(x)"}, GridLines → Automatic,

GridLinesStyle → {{Red, Thin}, {Red, Thin}}

]

Output:

f x

f' x

f'' x

2 1 1 2x

10

10

20

y

The graphs of f x , f' x and f'' x

Introduction to Mathematica – Calculus I

Page 50 of 52

C. Finding and graphing Tangent Lines.

Example 71: Find the equation of the tangent line to the function f(x) = x4 – 7x2 + 6 at x = 2 and

sketch f(x) and the tangent line t(x) using values of x in the interval [ – 1 ,4]

We find the slope of the tangent line at x = 2 by finding 𝑓′(2) and the general equation of

the tangent line at x = a is given by f(a) + 𝑓′(𝑎)(x – a)

Input: 𝑓[x_]: = 𝑥4 − 7𝑥2 + 6

𝑓′[2]

Output 4 So the slope of the tangent line at x = 2 is 4

The equation of the tangent line at x = 2 will be t(x) = f(2) + 𝑓′(2)(x – 2)

Input: 𝑡[x_]: = 𝑓[2] + 𝑓′[2](𝑥 − 2)

Simplify[𝑡[𝑥]]

Output −14 + 4𝑥 So the equation of the tangent line at x = 2 is t(x) = −14 + 4𝑥

Input: Plot[

{𝑓[𝑥], 𝑡[𝑥]}, {𝑥, −1,3},

PlotStyle → {{Blue, Thick}, {Green, Thick}}, AxesLabel → {"x", "y"},

AxesStyle → {{Black, Thick}, {Black, Thick}},

PlotLabel → "The graphs of f(x) and the tangent line t(x)}", PlotLabels → {"f(x)", "t(x)"},

GridLines → Automatic, GridLinesStyle → {{Red, Thin}, {Red, Thin}} ]

Output:

Introduction to Mathematica – Calculus I

Page 51 of 52

D. Optimization Problems.

Example 72: Find the coordinates of the local maximums and minimums of the function

f(x) = cos(x) – sin(2x) in the range −𝜋 ≤ 𝑥 ≤ 𝜋.

A sketch of this function in the range −𝜋 ≤ 𝑥 ≤ 𝜋 shows us that there are 4 vertices.

Input: f[x_]:=Cos[x]-Sin[2x] Plot[ f[x], {x,-π,π}, PlotStyle→{Red,Thick}, AxesLabel→{"x","y"},

AxesStyle→{{Black,Thick},{Black,Thick}}, PlotLabel→"The graphs of f(x)= cos(x)- sin(2x)", GridLines→Automatic,

GridLinesStyle→{{Blue,Thin},{Blue,Thin}} ]

Since there are no horizontal points of inflection all the vertices will happen when 𝑓′(𝑥) = 0

Input: 𝑓[x_]: = Cos[𝑥] − Sin[2𝑥] NSolve[𝑓′[𝑥] == 0&& − 𝜋 ≤ 𝑥 ≤ 𝜋, 𝑥, Reals]

Output: {{𝑥 → −2.50673}, {𝑥 → −0.63487}, {𝑥 → 1.00297}, {𝑥 → 2.13863}}

So the vertices are at the points x = −2.50673 ,

x = −0.63487

𝑥 → 1.00297

x = 𝑥 → 2.13863

3 2 1 1 2 3x

1.5

1.0

0.5

0.5

1.0

1.5

y

The graphs of f x cos x sin 2x

Introduction to Mathematica – Calculus I

Page 52 of 52

Example 73: Find the coordinates of the Absolute maximum and minimum value of the function

f(x) = x3 + 2x2 – 3x + 4 in the range [ – 3,2]

Input: 𝑓[x_]: = 𝑥3 + 2𝑥2 − 3𝑥 + 4

Solve[𝑓′[𝑥] == 0&& − 3 ≤ 𝑥 ≤ 2, 𝑥, Reals]

Output: {{𝑥 →1

3(−2 − √13)}, {𝑥 →

1

3(−2 + √13)}}

We now evaluate f(x) at the two endpoints x = – 3 and x = 2 and at x = 1

3(−2 − √13)

and at x = 1

3(−2 + √13)

Simplify[f[– 3 ]] 4

Simplify[𝑓[1

3(−2 − √13)]]

2

27(89 + 13√13)

Simplify[ 𝑓 [1

3(−2 + √13)]] −

2

27(−89 + 13√13)

Simplify[𝑓[2]] 14

The largest of these four y-values is 14 so the coordinates of the maximum value of

f(x) occur at (2,14).

The smallest of these four y-values is −2

27(−89 + 13√13)) so the coordinates of the

maximum value of f(x) occur at (1

3(−2 + √13) , −

2

27(−89 + 13√13))

Example 74: Find the coordinates of the vertex of the general quadratic function f(x) = ax2 + bx + c

Solution: We find the vertex of the quadratic by finding where its derivative is zero.

Input : 𝑓[x_]: = 𝑎𝑥2 + 𝑏𝑥 + 𝑐

Solve[𝑓′[𝑥] == 0, {𝑥}, Reals]

Output: {{𝑥 → −𝑏

2𝑎}}

So 𝑓′(𝑥) = 0 at x = −𝑏

2𝑎

To find the y-coordinate we evaluate f(−𝑏

2𝑎), we use the Together[…] command to

simplify the result.

Together[𝑓[−𝑏

2𝑎]]

Output: −𝑏2+4𝑎𝑐

4𝑎

This means that the coordinates of the vertex are (−𝑏

2𝑎 ,

−𝑏2

+4𝑎𝑐

4𝑎 )