Software Demo: Sage
Speaker: Karl-Dieter Crisman, Gordon College
Thank you to the organizers for the opportunity to bring a tool I very much enjoy using to a wider audience!
I usually start my talks about Sage with some easy examples of things you don't really need software to do, but which illustrate that there are nice commands.
4 4 |
1/4*x^4 1/4*x^4 |
[x == -I, x == I] [x == -I, x == I] |
Something I show a few things that are harder, and possibly even inspired by talks earlier in the conference.
933262154439441526816992388562667004907159682643816214685929638952175999\ 932299156089414639761565182862536979208272237582511852109168640000000000\ 00000000000000 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 |
3/50*sqrt(25*x^2 - 3)*x + 9/250*log(50*x + 10*sqrt(25*x^2 - 3)) 3/50*sqrt(25*x^2 - 3)*x + 9/250*log(50*x + 10*sqrt(25*x^2 - 3)) |
|
|
[ 2 -1 -1 0] [-1 3 -1 -1] [-1 -1 3 -1] [ 0 -1 -1 2] [ 2 -1 -1 0] [-1 3 -1 -1] [-1 -1 3 -1] [ 0 -1 -1 2] |
Or, in this case, I can talk about some of the other open source friends being discussed here today.
[1] 22.36559
MPG.city
Origin 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 39 42 46
USA 2 3 4 5 8 3 3 4 7 2 2 0 1 2 0 2 0 0 0 0 0
non-USA 0 0 4 7 2 5 3 3 1 3 4 2 1 4 1 0 1 1 1 1 1
[1] 22.36559
MPG.city
Origin 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 39 42 46
USA 2 3 4 5 8 3 3 4 7 2 2 0 1 2 0 2 0 0 0 0 0
non-USA 0 0 4 7 2 5 3 3 1 3 4 2 1 4 1 0 1 1 1 1 1
|
<permutation group with 1 generators> true <permutation group with 1 generators> true |
And sometimes I even type a few things in my notes, so that I don't forget them.
|
But today I have a slightly different goal than just showing off various fun things you can do with Sage.
My main use of Sage over the years has not been for student homework or labs, over the years. Instead, I enjoy using it for quick, accurate, interactive demonstration of difficult concepts.
Let me give an example of what I mean. We've likely all taught Newton's method of root-finding at some point.
So let's take a typical example of bad behavior (cubics!) and make it interactive.
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||||||||||
Naturally, there are other packages which do this. I'll just make the quick plug that Sage is free, powerful, and can be run off a server in your web browser. You probably know this, or you wouldn't be here.
(But go to www.sagemath.org if you didn't know this, and start poking around.)
Here are a few other things I and others have done recently that you might like.
Modular exponentiation theorems
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||
Singular value decomposition and images
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||||
Linear transformations of "Smiley Guy"
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||||||
Mean Value Theorem
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||||||
|
__Users_ka...0_code_sage21_spyx.c   __Users_ka...ode_sage21_spyx.html   __Users_ka...90_code_sage7_spyx.c   __Users_ka...code_sage7_spyx.html   __sagenb_s...70_code_sage7_spyx.c   __sagenb_s...code_sage7_spyx.html
|
Newton basins
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||||||||||||
It turns out that creating such things for your own students - interactive things you can use in class, a lab, or elsewhere - does not require great amounts of programming talent or other expertise.
For the rest of the time, I'd like to create one of these "interacts" in a step-by-step fashion for you. If I'm brave, I'll even do it with your ideas for what you want to show interactively.
|
|
|
|
The following is based on materials developed for the MAA PREP Workshop "Sage: Using Open-Source Mathematics Software with Undergraduates" (funding provided by NSF DUE 0817071). You can sign up for it again this summer!
Invaluable resources are the Sage wiki http://wiki.sagemath.org/interact (type "sage interact" into Google) and the interact documentation.
|
|
Start by getting the commands for what you want the output to look like. Here we just want a simple plot.
|
|
Then abstract out the parts you want to change. We'll be letting the user change the function, so let's make that a variable f.
|
|
Now make this a "def" function. The "show" or "print" is needed since the output is not automatically printed from within a function. Note also that we give the variable a default value of x^2. This is what f is if the user does not specify a value for f.
|
|
Let's test the def function myplot by just calling it.
|
|
If we call it with a different value for f, we should get a different plot.
|
|
Now to make a control to enter the function, we just preface the function with @interact.
Click to the left again to hide and once more to show the dynamic interactive window |
|||||||||||||||
Tech tip: Technically what the @interact does is wrap the function, so the above is equivalent to:
def myplot(..): ...
myplot=interact(myplot)
Note that we can still call our function, even when we've used @interact. This is often useful in debugging it.
|
|
We can go ahead and replace other parts of the expression with variables. Note the "_" is the function name now. That is a convention for throw-away names that we don't care about.
Click to the left again to hide and once more to show the dynamic interactive window |
|
|
If we pass ('label', default_value) in for a control, then the control gets the label when printed.
Click to the left again to hide and once more to show the dynamic interactive window |
We can specify the type of control explicitly, along with options.
Click to the left again to hide and once more to show the dynamic interactive window |
Here's another type of control: a color picker.
Click to the left again to hide and once more to show the dynamic interactive window |
|
|
|
|
Here are a bunch of options. Notice the new controls:
Click to the left again to hide and once more to show the dynamic interactive window |
That was a bit ugly because all of the controls were stacked on top of each other. We can layout the controls in a grid in the top, bottom, left, or right using the 'layout' parameter.
Click to the left again to hide and once more to show the dynamic interactive window |
Sage has:
We illustrate some of these.
Click to the left again to hide and once more to show the dynamic interactive window |
Click to the left again to hide and once more to show the dynamic interactive window |
Click to the left again to hide and once more to show the dynamic interactive window |
|
|
By default, ranges are sliders that divide the range into 500 steps (I think that's the right number...)
Click to the left again to hide and once more to show the dynamic interactive window |
You can set the step size to get, for example, just integer values.
Click to the left again to hide and once more to show the dynamic interactive window |
Or you can explicitly specify the slider values.
Click to the left again to hide and once more to show the dynamic interactive window |
And the slider values don't even have to be numbers!
Click to the left again to hide and once more to show the dynamic interactive window |
|
|
Matrices are automatically converted to a grid of input boxes.
Click to the left again to hide and once more to show the dynamic interactive window |
Here's how to get vectors from a grid of boxes.
Click to the left again to hide and once more to show the dynamic interactive window |
Sometimes we don't want any updates until we specifically say so. We can use the auto_update=False option for that.
Click to the left again to hide and once more to show the dynamic interactive window |
|
|
I hope this was fun! The take-home message?
Remember, this talk is available at http://www.sagenb.org/home/pub/3699
Of course, there are many other great aspects of Sage I haven't mentioned.
But the best thing to do is to try it out or download it! Thank you, and have a great day.
http://www.sagemath.org - the Sage website
http://demo.sagenb.org - try out Sage online!
|
|