Sage Help Sheet
This is a Sage sheet corresponding to the commands for my 3rd year Game Theory course here.
Rearranging expressions
You will often have simple expressions like that need simplifying (sometimes they will be more complex than that obviously). These commands show you how to carry this out:
If your expression was more complicated you could use simplify(exp)
, expand(exp)
and/or factor(exp)
.
Plotting functions
To plot a function type:
Solving equations
Linear equations appear all the time in this course. To solve :
Differentiation
To obtain: where :
If we wanted to find the point at which this equates to zero we would write the following:
Infinite sums
Sage can be used to obtain expressions like :
Sage can also be used to check symbolic expressions of this nature. For example you can quickly check what the expression for is:
Permutations
To quickly obtain all permutations of a set of the set :
Contour plots
I find 3D surface plots messy and unclear. Here is how to obtain a contour plot of the function:
(There are various options that can be passed to the cmap argument: try import matplotlib.cm; matplotlib.cm.datad.keys()
to list them)
Minimizing functions
You might need to minimize the following function with the following constraints: and . Here is how to do that in Sage:
For more details on minimization take a look at this page.
Finding Nash equilibria of Normal Form Games
You can easily obtain the Nash Equilibria for a generic Normal Form game: