Sharedcheat_sheet.sagewsOpen in CoCalc
Author: Matt Thomas
Views : 1
# This line makes the output nicely typeset
%typeset_mode True

# Define a sequence
a(n)=1/n

# Print a sequence
[a(i) for i in [1..10]]

[1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10]
# Define a series (sequence of partial sums)
def s(k):
return sum([a(i) for i in [1..k]])

# Print a sequence of partial sums
[s(i) for i in [1..10]]

[1, 3/2, 11/6, 25/12, 137/60, 49/20, 363/140, 761/280, 7129/2520, 7381/2520]
# Plot a sequence
L = [a(i) for i in [1..10]]
list_plot(L, pointsize=50, color='green')

# Plot sequence of partial sums (i.e. partial sums in a series)
S = [s(i) for i in [1..10]]
list_plot(S, pointsize=50, color='red')

# Indefinite integral
integral(1/x^2, x)

-1/x
# Definite integral from 4 to 5
integral(1/x^2, x, 4, 5)

$\displaystyle \frac{1}{20}$
# Improper integral
integral(1/x^2, x, 1, infinity)

$\displaystyle 1$