Math 433 Sage Introduction
system:sage


<p>Exact versus numerical results:</p>

{{{id=0|
19/7
///
}}}

{{{id=30|
187/423 + 171/347
///
}}}

{{{id=1|
n(19/7, 300)
///
}}}

{{{id=2|
pi
///
}}}

{{{id=5|
n(pi, 300)
///
}}}

<p>Really big numbers are no problem for Sage:</p>

{{{id=6|
factorial(400)
///
}}}

<p>Symbolic work is easy for Sage:</p>

{{{id=23|
f(x)=sin(x^2)
f.diff()
///
}}}

{{{id=25|
integrate(sin(x)^2, x)
///
}}}

<p>Plotting is impressive, too</p>

{{{id=7|
plot(20*sin(40/x), (x, -2, 2))
///
}}}

{{{id=11|
var('x y')
plot3d(sin(x)*cos(y), (x, -3*pi, 3*pi), (y, -3*pi, 3*pi))
///
}}}

{{{id=20|
var('x')
@interact
def plot_example(f=sin(x^2),r=range_slider(-5,5,step_size=1/4,default=(-3,3)),
                thickness=(3,(1..10)),
                adaptive_recursion=(5,(0..10)), adaptive_tolerance=(0.01,(0.001,1)),
                plot_points=(20,(1..100)),
                linestyle=['-','--','-.',':'],
                gridlines=False, fill=False,
                frame=False, axes=True,
                 c=Color('blue')
                ):
   show(plot(f, (x,r[0],r[1]), color=c, thickness=thickness,
                adaptive_recursion=adaptive_recursion,
                adaptive_tolerance=adaptive_tolerance, plot_points=plot_points,
                linestyle=linestyle, fill=fill if fill else None),
                gridlines=gridlines, frame=frame, axes=axes)
///
}}}

<p>Sage does algebra: "regular," linear, abstract</p>

{{{id=13|
var('a b')
expand((a+b)^3)
///
}}}

{{{id=12|
solve(x^3-5*x^2+6, x)
///
}}}

{{{id=14|
a = random_matrix(ZZ, 200, 200, x=10)
///
}}}

{{{id=16|
a[34, 17]
///
}}}

{{{id=17|
a.determinant()
///
}}}

{{{id=18|
g = CyclicPermutationGroup(6)
///
}}}

{{{id=19|
factor(factorial(20))
///
}}}

{{{id=29|

///
}}}