Calculus II - Spring 2019

AuthorJorge Basilio
Date2019-03-29T05:50:42
Project37bc3906-ade8-480b-a982-5ce07ae4200c
LocationLabs/Lab_0/Lab_0.sagews
Original fileLab_0.sagews
# Jorge Basilio - PCC%md# Calculus II - Spring 2019## Instructor: *Dr. Basilio*# Lab 0## Introduction to Sage<span style="font-size:18pt; color:red">Due: Tuesday, April 9 by 11:59pm via Canvas</span>## Objectives1. Learn what `SageMath` is and why you are asked to learn it2. Become familiar with performing basic arithmetic calculations with `SageMath`3. Learn how to calculate: limits, derivatives, integrals with `SageMath`4. Learn how to make a PDF of your work to save and submit# 0. Introduction## Why use SageMath?- It's free!- Using it on web is free (hassle-free, no messy downloading needed)- Dowloading it is free (if you want to use it without internet)- It's open source!- No hidden algorithms (you can look at source code if you wish--and look "under the hood" so to speak)- It will prepare you for the future!    - You will likely need to learn some basic programming no matter what you study in college    - In Pyschology, for example, it's common to learn Python (and the R package) when learning statistics# 1. Some reading assignments:## - Read: [Why use SageMath?](https://github.com/sagemathinc/cocalc/wiki/SageInCalculus)> *An excerpt:*> > #### Why not just use graphing calculators?> > Back in their day, graphing calculators were rather popular. I used one in high school in the 1990s.> > - Let's say you're working with a large data set. Using a system like Sage, a professor can upload data into a project, and distribute it to all of his students with a click. With a graphing calculator, the data would have to be entered by each student, by hand.> > - Students can take the images and outputs of their computations in Sage and easily add them to any document for their classes, or undergraduate research papers suitable for publication. A picture on a graphing calculator is idle and immovable.> > - The appearance of graphs and 3D plots on a computer is vastly more realistic and comprehensible than the display of a graphing calculator.> > - The "online help" systems available (such as web-pages) such as Sage's wiki can be a tremendous boon to the student who is new to Sage. A graphing calculator just has a manual.> > - Many faculty working with Sage have made online videos, to help new students learn Sage.> > - If a student learns Sage, then the student learns Python "along the way." Python is an extremely popular computer programming language, used in industry. (Ranked #3 in this article published in IEEE Spectrum.)## - Read: [Getting Started with SageMath](https://mosullivan.sdsu.edu/sagetutorial/about.html#getting-started)> - Read: **About Sage**> - Read: **Sage as a Calculator**> - Read: Section: Arithmetic and Functions>      1. Basic Arithmetic>      2. Integer Division and Factoring>      3. Standard Functions and Constants## - Reference: [Sage for Undergraduates](http://www.gregorybard.com/Sage.html)> - Reference: this site has an entire book you can download for more information# 2. Getting Started1. Make an account at the [CoCalc website](https://cocalc.com/) page so you can **login** to the free Sage server. No nosy questions, just make up a username and set a password. Just be sure to use a modern web browser (Google Chrome, Mozilla Firefox, etc).2. Create a new **Sage Worksheet** and begin experimenting, ORUpload worksheets using the "Upload" link in the upper-left corner, ORIf you are making a worksheet to submit an assignment, give the worksheet a title like **"Math5B-Lab_0– YourLastName_YourFirstName-S19"**.3. At the beginning of your worksheet include course info and lab info by using **comments** (see the template you can follow)    - By looking at this document, you are encouraged to copy and paste lines of code and modify them :-)4. Have some fun and make a few calculations# 3. Handy Short Cuts- `Command+Enter` (on Mac) or `Shift+Enter` (on PC) runs the code and gives you an output# 4. Quick Examples

Calculus II - Spring 2019

Instructor: Dr. Basilio

Lab 0

Introduction to Sage

Due: Tuesday, April 9 by 11:59pm via Canvas

Objectives

  1. Learn what SageMath is and why you are asked to learn it
  2. Become familiar with performing basic arithmetic calculations with SageMath
  3. Learn how to calculate: limits, derivatives, integrals with SageMath
  4. Learn how to make a PDF of your work to save and submit

0. Introduction

Why use SageMath?

1. Some reading assignments:

- Read: Why use SageMath?

An excerpt:

Why not just use graphing calculators?

Back in their day, graphing calculators were rather popular. I used one in high school in the 1990s.

  • Let's say you're working with a large data set. Using a system like Sage, a professor can upload data into a project, and distribute it to all of his students with a click. With a graphing calculator, the data would have to be entered by each student, by hand.
  • Students can take the images and outputs of their computations in Sage and easily add them to any document for their classes, or undergraduate research papers suitable for publication. A picture on a graphing calculator is idle and immovable.
  • The appearance of graphs and 3D plots on a computer is vastly more realistic and comprehensible than the display of a graphing calculator.
  • The "online help" systems available (such as web-pages) such as Sage's wiki can be a tremendous boon to the student who is new to Sage. A graphing calculator just has a manual.
  • Many faculty working with Sage have made online videos, to help new students learn Sage.
  • If a student learns Sage, then the student learns Python "along the way." Python is an extremely popular computer programming language, used in industry. (Ranked #3 in this article published in IEEE Spectrum.)

- Read: Getting Started with SageMath

- Reference: Sage for Undergraduates

2. Getting Started

  1. Make an account at the CoCalc website page so you can login to the free Sage server. No nosy questions, just make up a username and set a password. Just be sure to use a modern web browser (Google Chrome, Mozilla Firefox, etc).

  2. Create a new Sage Worksheet and begin experimenting, OR Upload worksheets using the "Upload" link in the upper-left corner, OR If you are making a worksheet to submit an assignment, give the worksheet a title like "Math5B-Lab_0– YourLastName_YourFirstName-S19".

  3. At the beginning of your worksheet include course info and lab info by using comments (see the template you can follow)

    • By looking at this document, you are encouraged to copy and paste lines of code and modify them :-)
  4. Have some fun and make a few calculations

3. Handy Short Cuts

4. Quick Examples

# this a SageMath worksheet# comments are designated by a hashtag and are not read by the program# how to add; hit `Run` when you are ready to tell SageMath to compute2+2
4
# evaluating a functionf(x) = x^2 # defines f; note the notation is similar to math notation!f(-2)
4
# graphing a function# this will graph f(x)=x^2 with x in (-2,2)plot(x^2,x,-2,2)
# limitsf(x)=x*e^(-x) # note: must use * to multiplylimit(f,x=ln(2))
x |--> 1/2*log(2)
# another limitf(x)=1/xlimit(f,x=0)
x |--> Infinity
# notice we have to be careful in the above limit!# the above example doesn't give us the expected 'DNE' (Recall: LHL is -Infinity whereas RHL is +Infinity)# to do a one sided limit:f(x)=1/xlimit(f, x=0, dir="left") # this means `approaches from the left`
x |--> -Infinity
# and the RHLf(x)=1/xlimit(f,x=0, dir="right")
x |--> +Infinity
# derivativef(x)=x^3*e^(sqrt(x))derivative(f,x) # 'd(f,x)' is basically 'df/dx'
x |--> 1/2*x^(5/2)*e^sqrt(x) + 3*x^2*e^sqrt(x)
# the above is correct but not easy to look at# we can use show() function to make the output look prettierf(x)=x^3*e^(sqrt(x))show(derivative(f,x))
$\displaystyle x \ {\mapsto}\ \frac{1}{2} \, x^{\frac{5}{2}} e^{\sqrt{x}} + 3 \, x^{2} e^{\sqrt{x}}$
# better way to use show()f(x)=x^3*e^(sqrt(x))g=derivative(f,x)show(g)
$\displaystyle x \ {\mapsto}\ \frac{1}{2} \, x^{\frac{5}{2}} e^{\sqrt{x}} + 3 \, x^{2} e^{\sqrt{x}}$
# anti-derivatives or indefinite integralsintegral(x^3,x) # integral(f,x) the ",x" is like our "dx"
1/4*x^4
# definite integralintegral(x^3*sin(x),x,-1,1)
10*cos(1) - 6*sin(1)
# a hard integralI=integrate(x^4*exp(x),x)show(I)
$\displaystyle {\left(x^{4} - 4 \, x^{3} + 12 \, x^{2} - 24 \, x + 24\right)} e^{x}$
# variables have to be declared (x is predefined for convenience)var('t')show(plot(sin(t),(t,-1,4*pi)), axes_labels = ['t','P']) # t for time and P for population
t
# Assignment for Lab_0%md# 5. Assignment1. Evaluate: $\cos(\pi/8)$, $e^8$, $\sqrt{8}$, $\ln(8)$2. Now, have Sage compute numerical approximations for the expression in \#1. *(Consult the reading from above "Getting Started with Sage")*3. Compute $e$ to one hundred decimal places.4. Let $f(x)=x^3+7^x-\ln(e^{x^2}\cdot \sqrt{x})$.    a. Compute: $\lim_{x \to 1} f(x)$.    b. Compute: $f'(x)$.    c. Compute: $\int f(x) dx$.    d. Verify the Fundamental Theorem of Calculus by defining $F(x)=\int f(x)dx$ and checking that $F'(x)=f(x)$.    e. Compute: $\int_2^8 f(x) dx$.    f. Plot $f$ for $x \in (2,8)$.    g. Make your plot prettier by labeling the $x$ and $f(x)$ axes appropriately.5. Download your Sage worksheet *(extension .sagews)* and submit it via Canvas.6. Submit a pdf of your lab via Canvas.**Note:** Use comments to indicate which problem you are working on (see template)

5. Assignment

  1. Evaluate: $\cos(\pi/8)$, $e^8$, $\sqrt{8}$, $\ln(8)$

  2. Now, have Sage compute numerical approximations for the expression in #1. (Consult the reading from above "Getting Started with Sage")

  3. Compute $e$ to one hundred decimal places.

  4. Let $f(x)=x^3+7^x-\ln(e^{x^2}\cdot \sqrt{x})$.

    a. Compute: $\lim_{x \to 1} f(x)$.

    b. Compute: $f'(x)$.

    c. Compute: $\int f(x) dx$.

    d. Verify the Fundamental Theorem of Calculus by defining $F(x)=\int f(x)dx$ and checking that $F'(x)=f(x)$.

    e. Compute: $\int_2^8 f(x) dx$.

    f. Plot $f$ for $x \in (2,8)$.

    g. Make your plot prettier by labeling the $x$ and $f(x)$ axes appropriately.

  5. Download your Sage worksheet (extension .sagews) and submit it via Canvas.

  6. Submit a pdf of your lab via Canvas.

Note: Use comments to indicate which problem you are working on (see template)

# printing PDF%md# 6. How to create a PDFWhen you have completed the assignment, download the worksheet and also a PDF version of your file and submit both files via Canvas. To accomplish this, select `Print` (*You'll see a prompt that says "Conver to HTML") then select `Download`. A pop-up will give you a PDF of your worksheet. You may now downnload and save it to your computer. As before, give your file the name **"Math5B-Lab_0– YourLastName_YourFirstName-S19.pdf"**.**Note \#1:** Do **not** use `Convert to PDF` *(try it if your curious but the formatting is not as nice looking as when it is converted to html then printed)***Note \#2:** Do **not** use `Ctrl+P`. It doesn't seem to print the entire document.

6. How to create a PDF

When you have completed the assignment, download the worksheet and also a PDF version of your file and submit both files via Canvas. To accomplish this, select Print (*You'll see a prompt that says "Conver to HTML") then select Download. A pop-up will give you a PDF of your worksheet. You may now downnload and save it to your computer. As before, give your file the name "Math5B-Lab_0– YourLastName_YourFirstName-S19.pdf".

Note #1: Do not use Convert to PDF (try it if your curious but the formatting is not as nice looking as when it is converted to html then printed)

Note #2: Do not use Ctrl+P. It doesn't seem to print the entire document.

# Bonus%md# 7. Bonus Section (Optional): Python`SageMath` is built using the `Python` programming language.In fact, you can type `Python` code directly on Sage Worksheets without any special instructions.Below, I'll give a few simple examples for those of you who are  curious ;-)

7. Bonus Section (Optional): Python

SageMath is built using the Python programming language. In fact, you can type Python code directly on Sage Worksheets without any special instructions.

Below, I'll give a few simple examples for those of you who are curious ;-)

# example of python codeprint("Hello World!")
Hello World!
# example of python code# defining a more complicated functiondef f(x):    if -1 <= x <=0:        return -x    elif 0 < x < 0.5:        return x    else:        return 0.5f(-0.1)
0.100000000000000
f(0)
0
f(0.1)
0.100000000000000
#mix and match; use sage to plot the function f defined with pythonplot(f)