Sharedseq.sagewsOpen in CoCalc
Author: Matt Thomas
Views : 2
%typeset_mode True

a(n)=1/n

for i in [1..10]:
a(i)

$\displaystyle 1$
$\displaystyle \frac{1}{2}$
$\displaystyle \frac{1}{3}$
$\displaystyle \frac{1}{4}$
$\displaystyle \frac{1}{5}$
$\displaystyle \frac{1}{6}$
$\displaystyle \frac{1}{7}$
$\displaystyle \frac{1}{8}$
$\displaystyle \frac{1}{9}$
$\displaystyle \frac{1}{10}$
[a(i) for i in [1..10]]

[$\displaystyle 1$, $\displaystyle \frac{1}{2}$, $\displaystyle \frac{1}{3}$, $\displaystyle \frac{1}{4}$, $\displaystyle \frac{1}{5}$, $\displaystyle \frac{1}{6}$, $\displaystyle \frac{1}{7}$, $\displaystyle \frac{1}{8}$, $\displaystyle \frac{1}{9}$, $\displaystyle \frac{1}{10}$]
L = [a(i) for i in [1..10]]

L

[$\displaystyle 1$, $\displaystyle \frac{1}{2}$, $\displaystyle \frac{1}{3}$, $\displaystyle \frac{1}{4}$, $\displaystyle \frac{1}{5}$, $\displaystyle \frac{1}{6}$, $\displaystyle \frac{1}{7}$, $\displaystyle \frac{1}{8}$, $\displaystyle \frac{1}{9}$, $\displaystyle \frac{1}{10}$]
L[1]

$\displaystyle \frac{1}{2}$
points([(a(i),0) for i in [1..10]], pointsize=50)

def a(n):
if n==1:
return 1
else:
return (n*a(n-1))

a(5)

$\displaystyle 120$
for i in [1..5]:
a(i)

$\displaystyle 1$
$\displaystyle 2$
$\displaystyle 6$
$\displaystyle 24$
$\displaystyle 120$
list_plot([a(i) for i in [1..5]], color='green', pointsize=50)

a(n)=1/n
list_plot([a(i) for i in [1..10]])



list_plot([s(n) for n in [1..10]])



N(s(100))

$\displaystyle 5.18737751763962$
L = [s(n) for n in [1..10]]

L

[$\displaystyle 1$, $\displaystyle \frac{3}{2}$, $\displaystyle \frac{11}{6}$, $\displaystyle \frac{25}{12}$, $\displaystyle \frac{137}{60}$, $\displaystyle \frac{49}{20}$, $\displaystyle \frac{363}{140}$, $\displaystyle \frac{761}{280}$, $\displaystyle \frac{7129}{2520}$, $\displaystyle \frac{7381}{2520}$]
L[1]

$\displaystyle \frac{3}{2}$
L[0]

$\displaystyle 1$