), NOT Sage Publications or the SAGE Visualization group.
Note that in Sage, there is usually more than one way to do something.
.
var('x')
f(x) = e^x * cos(x)
f.integrate(x)
f.integrate(x, 0, 5)
f.integrate(x, 0, 5).n()
var('x y')
f(x) = (x^2 - 1) / (x^4 + 1) * y
f.derivative(x)
f.derivative(y)
f.derivative(y, 2)
f.derivative(y, x)
- Simplifying, expanding, factoring
var('x y')
# simplifying
f(x) = sqrt(x^2 + x) / sqrt(x)
f.simplify_radical()
# expanding
expr1 = (x + 3)^3 == (x - 1)^2
expr1.expand()
expr1.lhs().expand()
# factoring
g(x) = x^2 - 1
g.factor()
var('x y')
solns = solve([x^2 + y^2 == 1, y^2 == x^3 + x + 1], x, y, solution_dict= True)
for soln in solns:
print("x= {0}, y = {1}".format(soln[x], soln[y]))
g(x) = expand((x^2 - 1)^3 * (x^2 + 1) * (x - 2))
print(g)
root_list = g.roots(x)
for root in root_list:
print("Root: {0} (multiplicity: {1})".format(root[0], root[1]))
p1 = plot(g, (-2, 2))
p1.ymin(-10)
p1.show()
var('x')
f(x) = 1/x
limit(f(x), x = 0, dir= '+')
limit(f(x), x = 0, dir= '-')
limit(f(x), x= 0) # Does this seem right? Note absence of sign
limit(f(x), x= oo)
p1 = plot(f, (x, -1, 1), detect_poles= 'show')
p1.axes_range(-1, 1, -10, 10)
p1.show()
var('x, k')
colors= ['red', 'black', 'blue', 'magenta']
x1 = pi/2
xmin = x1 - pi
xmax = x1 + pi
f(x) = sin(x)
p1 = plot(f, (xmin, xmax), color= colors[0], legend_label= 'sin(x)')
Taylor_ser_1(x) = f.taylor(x, x1, 1)
p1 += plot(Taylor_ser_1, (xmin, xmax), legend_label= '1', color= colors[1])
Taylor_ser_3(x) = f.taylor(x, x1, 3)
p1 += plot(Taylor_ser_3, (xmin, xmax), legend_label= '3', color= colors[2])
Taylor_ser_5(x) = f.taylor(x, x1, 5)
p1 += plot(Taylor_ser_5, (xmin, xmax), legend_label= '5', color= colors[3])
Taylor_ser_5
show(p1)
rationalVector1 = vector(QQ, [1, 2/7, 10/3])
rationalVector1
realVector1 = vector(RR, [1, 2/7, 10/3])
realVector1
var('a, b, c')
symbolicVector1 = vector(SR, [a, b, c])
symbolicVector1
rationalVector1.dot_product(symbolicVector1)
rationalVector1.pairwise_product(symbolicVector1)
var('d e f')
ratMatrix = matrix(QQ, [[4, 2, 1], [5, 3, 7]])
symbMatrix = matrix(SR, [[a, b], [c, d], [e, f]])
ratMatrix * symbMatrix
symbolicVector1 * symbMatrix
ratMatrix * symbolicVector1
restore('e')
A = matrix(QQ, [[2, 5, 4], [3, 1, 2], [5, 4, 6]]) # examples look nicer with QQ; for real numbers, use RR instead
A.det()
A.rank()
A.transpose()
A.inverse()
b= vector(QQ, [1,2,3])
A.solve_right(b) # get the solution to A.x = b