Presenting:
Karl-Dieter Crisman, Gordon College (MA)
Abstract:
This introduction to Sage will be short and sweet. We'll talk a little bit about how to use the notebook and the range of functionality, but focus mostly on calculus and a little bit of doing modeling. I'll also show how to use R in the notebook, and perhaps a bit of collaborative functionality in the notebook.
Thank you to the organizers for inviting me to give this talk!
We'll do the following:
We'll be fairly quick about it, as it's best to learn while doing, so let's get started!
There are many Sage servers out there, and some allow anyone to create an account.
Basically, there is not so much to do:
If you're in this workshop, you should be able to do this fairly easily.
So what can you do with Sage? Well... what do you want to do?
10333147966386144929666651337523200000000 10333147966386144929666651337523200000000 |
We can do various plots, as one would expect.
|
|
There is lots of functionality in various topics. The graph editor is nice.
|
|
But allows for more advanced usage!
|
|
Interactive examples are fun. I love doing this myself, and is the primary way I use Sage in the classroom. Can you find the pattern?
Click to the left again to hide and once more to show the dynamic interactive window |
Naturally, you are here to talk about calculus. Sage has the usual functionality you'd expect from a computer algebra system.
Do you remember how to calculate
|
|
We can do computations inside of the things we are trying to learn about, and typeset them correctly. (Incidentally, to get nice formulas in between the computational cells, just double click on one of the text areas!)
|
|
I might want to find help. Tabbing and the question mark are your ways to success.
|
|
|
|
We can also try to find fits for models of various types, using one of the many components of Sage - in this case, SciPy.
|
|
|
Because Python, the programming language Sage is based on, is a very powerful tool, we have everything we need to import data.
|
|
Now we'll make two possible models for the data from the bomb blast in the earlier talk Danny gave.
|
|
|
|
We've now found fits for each model. Now we just extract the information and plot!
|
|
Like Danny said, which one is better?
As another example of what can be done, let's see how to use R from the notebook. All I have to do is insert '%r' at the beginning of a cell, and then everything is done in R. (It's also possible to have a whole worksheet evaluate in a given system.)
Here, I'll first load the library from the MOSAIC project's R package. You'll need internet for this, of course.
[1malso installing the dependency ‘Hmisc’
[0m[1mtrying URL
'http://cran.r-project.org/src/contrib/Hmisc_3.9-0.tar.gz'
[0m[1mContent type 'application/x-gzip'[0m[1m length 572432 bytes
(559 Kb)
[0m[1mopened URL
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m
[0m[1mdownloaded 559 Kb
[0m[1mtrying URL
'http://cran.r-project.org/src/contrib/mosaic_0.2-3.tar.gz'
[0m[1mContent type 'application/x-gzip'[0m[1m length 839835 bytes
(820 Kb)
[0m[1mopened URL
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=\
[0m[1m=[0m[1m=[0m[1m
[0m[1mdownloaded 820 Kb
[0m* installing *source* package ‘Hmisc’ ...
** libs
gcc -std=gnu99
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c Hmisc.c
-o Hmisc.o
sage_fortran -fPIC -g -O2 -c cidxcn.f -o cidxcn.o
sage_fortran -fPIC -g -O2 -c cidxcp.f -o cidxcp.o
sage_fortran -fPIC -g -O2 -c hoeffd.f -o hoeffd.o
sage_fortran -fPIC -g -O2 -c jacklins.f -o jacklins.o
sage_fortran -fPIC -g -O2 -c largrec.f -o largrec.o
gcc -std=gnu99
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c
mChoice.c -o mChoice.o
gcc -std=gnu99
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c nstr.c
-o nstr.o
gcc -std=gnu99
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c
ranksort.c -o ranksort.o
sage_fortran -fPIC -g -O2 -c rcorr.f -o rcorr.o
gcc -std=gnu99
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC
-I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c
string_box.c -o string_box.o
sage_fortran -fPIC -g -O2 -c wclosest.f -o wclosest.o
gcc -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -o Hmisc.so
Hmisc.o cidxcn.o cidxcp.o hoeffd.o jacklins.o largrec.o mChoice.o nstr.o
ranksort.o rcorr.o string_box.o wclosest.o
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc/i686-appl\
e-darwin8/4.2.3/x86_64
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc/i686-appl\
e-darwin8/4.2.3
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc
-L/usr/local/lib -lgfortran
-L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R//lib -lR
-Wl,-framework -Wl,CoreFoundation
** R
** inst
** preparing package for lazy loading
Loading required package: splines
** help
*** installing help indices
** building package indices ...
* DONE (Hmisc)
* installing *source* package ‘mosaic’ ...
** R
** data
** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
Loading required package: survival
Loading required package: splines
Hmisc library by Frank E Harrell Jr
Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')
to see overall documentation.
NOTE:Hmisc no longer redefines [.factor to drop unused levels when
subsetting. To get the old behavior of Hmisc type dropUnusedLevels().
Attaching package: 'Hmisc'
The following object(s) are masked from package:survival :
untangle.specials
The following object(s) are masked from package:base :
format.pval,
round.POSIXt,
trunc.POSIXt,
units
Creating a generic for "mean" in package "mosaic"
(the supplied definition differs from and overrides the implicit
generic
in package "base": Classes: "nonstandardGenericFunction",
"standardGeneric")
In method for function "var": expanding the signature to include
omitted arguments in definition: data = "missing"
Creating a new generic function for "print" in "mosaic"
** help
*** installing help indices
** building package indices ...
* DONE (mosaic)
The downloaded packages are in
‘/private/var/folders/Yy/YytEJm5VEB0+pBRD7JNLe++++TQ/-Tmp-/RtmpC1m0k6/d\
ownloaded_packages’
[1mUpdating HTML index of packages in '.Library'
[1malso installing the dependency ‘Hmisc’
[0m[1mtrying URL 'http://cran.r-project.org/src/contrib/Hmisc_3.9-0.tar.gz'
[0m[1mContent type 'application/x-gzip'[0m[1m length 572432 bytes (559 Kb)
[0m[1mopened URL
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m
[0m[1mdownloaded 559 Kb
[0m[1mtrying URL 'http://cran.r-project.org/src/contrib/mosaic_0.2-3.tar.gz'
[0m[1mContent type 'application/x-gzip'[0m[1m length 839835 bytes (820 Kb)
[0m[1mopened URL
[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m=[0m[1m
[0m[1mdownloaded 820 Kb
[0m* installing *source* package ‘Hmisc’ ...
** libs
gcc -std=gnu99 -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c Hmisc.c -o Hmisc.o
sage_fortran -fPIC -g -O2 -c cidxcn.f -o cidxcn.o
sage_fortran -fPIC -g -O2 -c cidxcp.f -o cidxcp.o
sage_fortran -fPIC -g -O2 -c hoeffd.f -o hoeffd.o
sage_fortran -fPIC -g -O2 -c jacklins.f -o jacklins.o
sage_fortran -fPIC -g -O2 -c largrec.f -o largrec.o
gcc -std=gnu99 -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c mChoice.c -o mChoice.o
gcc -std=gnu99 -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c nstr.c -o nstr.o
gcc -std=gnu99 -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c ranksort.c -o ranksort.o
sage_fortran -fPIC -g -O2 -c rcorr.f -o rcorr.o
gcc -std=gnu99 -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R/include -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -fPIC -I/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/include -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -c string_box.c -o string_box.o
sage_fortran -fPIC -g -O2 -c wclosest.f -o wclosest.o
gcc -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/ -o Hmisc.so Hmisc.o cidxcn.o cidxcp.o hoeffd.o jacklins.o largrec.o mChoice.o nstr.o ranksort.o rcorr.o string_box.o wclosest.o -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64 -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc/i686-apple-darwin8/4.2.3 -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/gcc -L/usr/local/lib -lgfortran -L/Users/karl-dietercrisman/Downloads/sage-4.7.2/local/lib/R//lib -lR -Wl,-framework -Wl,CoreFoundation
** R
** inst
** preparing package for lazy loading
Loading required package: splines
** help
*** installing help indices
** building package indices ...
* DONE (Hmisc)
* installing *source* package ‘mosaic’ ...
** R
** data
** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
Loading required package: survival
Loading required package: splines
Hmisc library by Frank E Harrell Jr
Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')
to see overall documentation.
NOTE:Hmisc no longer redefines [.factor to drop unused levels when
subsetting. To get the old behavior of Hmisc type dropUnusedLevels().
Attaching package: 'Hmisc'
The following object(s) are masked from package:survival :
untangle.specials
The following object(s) are masked from package:base :
format.pval,
round.POSIXt,
trunc.POSIXt,
units
Creating a generic for "mean" in package "mosaic"
(the supplied definition differs from and overrides the implicit generic
in package "base": Classes: "nonstandardGenericFunction", "standardGeneric")
In method for function "var": expanding the signature to include
omitted arguments in definition: data = "missing"
Creating a new generic function for "print" in "mosaic"
** help
*** installing help indices
** building package indices ...
* DONE (mosaic)
The downloaded packages are in
‘/private/var/folders/Yy/YytEJm5VEB0+pBRD7JNLe++++TQ/-Tmp-/RtmpC1m0k6/downloaded_packages’
[1mUpdating HTML index of packages in '.Library'
|
[1mLoading required package: lattice [0m[1mLoading required package: grid [0m[1mLoading required package: Hmisc [0m[1mLoading required package: survival [0m[1mLoading required package: splines [0m[1mHmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). [0m[1m Attaching package: 'Hmisc' [0m[1m The following object(s) are masked from package:survival : untangle.specials [0m[1m The following object(s) are masked from package:base : format.pval, round.POSIXt, trunc.POSIXt, units [0m[1m Attaching package: 'mosaic' [0m[1m The following object(s) are masked from package:Hmisc : do [0m[1m The following object(s) are masked from package:stats : binom.test, D, median, prop.test, sd, var [0m[1m The following object(s) are masked from package:base : max, mean, min, print, print.function, sample [1mLoading required package: lattice [0m[1mLoading required package: grid [0m[1mLoading required package: Hmisc [0m[1mLoading required package: survival [0m[1mLoading required package: splines [0m[1mHmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). [0m[1m Attaching package: 'Hmisc' [0m[1m The following object(s) are masked from package:survival : untangle.specials [0m[1m The following object(s) are masked from package:base : format.pval, round.POSIXt, trunc.POSIXt, units [0m[1m Attaching package: 'mosaic' [0m[1m The following object(s) are masked from package:Hmisc : do [0m[1m The following object(s) are masked from package:stats : binom.test, D, median, prop.test, sd, var [0m[1m The following object(s) are masked from package:base : max, mean, min, print, print.function, sample |
We can use the functions from the package immediately.
result 1 3 2 3 3 3 4 3 5 3 result 1 3 2 3 3 3 4 3 5 3 |
Graphics work, too, if you create a graphics device. Here, I'm using the D and fplot functions from the MOSAIC project's R package.
|
|
If you want to do a whole worksheet in R (or GAP, or Octave, or even Mathematica, if you own it) that is supported as well.
Finally, how might one use Sage in terms of pedagogy? Here, the answer is just as broad as your own interests, and I'll focus on collaboration. Here are several ideas.
For example, in a calculus class, just giving a worksheet to upload with prototypes of syntax could help a lot for routine problems.
|
|
Just click the 'Share' button at the top and fill in the usernames of the people who should share the worksheet! Some people use this for turning in labs, for instance.
With this option, anyone on the server can look at your worksheet, and edit a copy for themselves. This is especially effective when you want to post something for students to try out or use for homework, or to make easily available to colleagues elsewhere.
In fact, I'm going to publish THIS VERY WORKSHEET right now on the server for this workshop! And then you can download it and try it yourself.
Well, I think that's all we have time for. Please see www.sagemath.org for more discussion of download options for all platforms, places to try out Sage, and discussion forums. We value your feedback!
This talk is also available at http://www.sagenb.org/home/pub/3932 .
Questions?
|
|
|
|