Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Homework 4
Views: 164
Kernel: SageMath (default)

Homework 4

Experimental Math

Garrett Van Beek

April 4, 2020

Problem 1

Show that ParseError: KaTeX parse error: Got function '\underline' with no arguments as superscript at position 10: \Delta[x^\̲u̲n̲d̲e̲r̲l̲i̲n̲e̲{n}] = n * x ^\…

hwp1

Problem 2

Create a sage function that given a function(symbolic expression) f, a non negative integer n∈Z≥ 0 and a number x, computes ∆^nf.Here ∆n means taking the operation n times. For example ∆^2(falling_factorial(x,3))(x) = ∆(3*falling_factorial(x,2))(x) = 6x^1= 6x.

def delta_f(f, n): delta = f(x+1) - f(x) if n == 1: return delta else: return delta_f(delta, n-1) t(x) = falling_factorial(x,6) # print the first 6 forward derivatives of t(x) as a demonstration for i in range(1,7): print(str(i)+"th delta:", delta_f(t,i).simplify_full())

Problem 3

Show that Δ[Fx]=Fx1\Delta[F_x]= F_{x-1}

hw3-1

Problem 4 (Bonus)

Give a convincing arguement for not going outside.
At this time, individuals should avoid group gatherings and going outside because they could not only contract the coronavirus, but they could also carry the virus (with or without symptoms). This means that they could introduce the virus to their friends and family that could be at risk.

Problem 5

Part 1
Letf(x)=cx,wherec1Let f(x) = c^x, where c\neq 1Showk=0nck=cn+11c1Show \sum_{k=0}^n {c^k} = \frac {c^{n+1} - 1}{c-1}

hw5-1

Part 2

Give a formula for k=0nk2k\sum_{k=0}^n {k*2^k}

var('n') for i in range(0, 15): print(sum(x*2**x, x, 0, i), 2+(2**(i+1))*(i-1))
(0, 0) (2, 2) (10, 10) (34, 34) (98, 98) (258, 258) (642, 642) (1538, 1538) (3586, 3586) (8194, 8194) (18434, 18434) (40962, 40962) (90114, 90114) (196610, 196610) (425986, 425986)

The summation can be represented by the formula: 2+2^(n+1)*(n-1) This is sequence A036799 on OEIS.

Part 3

What about k=0nk22k \sum_{k=0}^{n} {k^2*2^k}

for i in range(0, 15): print(sum((x**2)*2**x, x, 0, i), -6+2**(i+1)*(3 - 2*i + i**2))
(0, 0) (2, 2) (18, 18) (90, 90) (346, 346) (1146, 1146) (3450, 3450) (9722, 9722) (26106, 26106) (67578, 67578) (169978, 169978) (417786, 417786) (1007610, 1007610) (2392058, 2392058) (5603322, 5603322)

The summation is sequence A036800 on OEIS. It can be represented with the formula: -6+2**(n+1)(3 - 2n + n**2)

Problem 6

Give an equivalent to integration by parts for finite calculus. Use it to show k=1n(kn)Hk=(n+1m+1)Hn+11m+1 \sum_{k=1}^{n} {{k \choose n} * H_{k}} = {n+1 \choose m+1} * {H_{n+1} - \frac{1}{m+1}}

hw6-1 hw6-2

Problem 7

Check that Hn=011tn1tdt H_{n} = \int_{0}^{1} {\frac {1-t^n}{1-t} dt}

## Check the equality for the first 100 values of n for n in range(1,101): if ( harmonic_number(n, 1) != integral((1-x**n)/(1-x) , x, 0, 1) ): print("The two values are NOT equivalent") print("If this is the only line printed, the equality holds for at least the first 100 terms of n")
var('t') var('epsilon') assume(epsilon > 0) def H(n): return limit( integral( (1-t^n)\(1-t), t, 0+epsilon, 1-epsilon ) , epsilon=0) #H(1) #limit((1-t^2)/(1-t), t=0) integral( (1-t**2)\(1-t), t, 0+epsilon, 1-epsilon )
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-531f58828497> in <module>() 7 #H(1) 8 #limit((1-t^2)/(1-t), t=0) ----> 9 integral( (Integer(1)-t**Integer(2)) * BackslashOperator() * (Integer(1)-t), t, Integer(0)+epsilon, Integer(1)-epsilon ) /ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/misc/misc.pyc in __mul__(self, right) 1171 (0.0, 0.5, 1.0, 1.5, 2.0) 1172 """ -> 1173 return self.left._backslash_(right) 1174 1175 /ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4606)() 487 AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah' 488 """ --> 489 return self.getattr_from_category(name) 490 491 cdef getattr_from_category(self, name): /ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4715)() 500 else: 501 cls = P._abstract_element_class --> 502 return getattr_from_other_class(self, cls, name) 503 504 def __dir__(self): /ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2614)() 392 dummy_error_message.cls = type(self) 393 dummy_error_message.name = name --> 394 raise AttributeError(dummy_error_message) 395 attribute = <object>attr 396 # Check for a descriptor (__get__ in Python) AttributeError: 'sage.symbolic.expression.Expression' object has no attribute '_backslash_'

Problem 8:

Part 1

Give a recursive definition for the hamonic series to the power of k in sage.

var("k") @CachedFunction def h(n,k): if n <= 1: #base case return 1 else: #recursive step return 1/(n**k) + h(n-1,k) for k in range(1,4): print("k is ", k) for i in range(1,6): print(harmonic_number(i, k), h(i,k).n())
Part 2

Represent the sequence as an integral.
We represent h(n,k) as summation from t=1 to t=n of 1/t**k

t=1n1tk\sum_{t=1}^{n} {\frac {1}{t^k} }
# integral of h(n,k) var('t') def h_as_integral(n,k): return sum(1/t**k, t, 1, n) for i in range(1,11): print(h_as_integral(i,1))
Part 3

Use sage to compute limit of H(n,2) as n goes to infinity.

sum(1/x**2, x, 1, oo)

h(n,2) converges to (1/6)*pi^2

Part 4

Show that the i=1nHik=(n+1)HnkHnk1 \sum_{i=1}^{n} {H_{i}^{k} } = (n+1)*H_{n}^{k} - H_{n}^{k-1}

hw8-1 hw8-2

Problem 9

In class we defined s(n,k) to be numbers such that:
ParseError: KaTeX parse error: Got function '\underline' with no arguments as superscript at position 4: x^\̲u̲n̲d̲e̲r̲l̲i̲n̲e̲{n} = \sum_{k=0… Give a formula for s(n,1) and s(n,2).
Note that s(n,k) represents the coefficient of x^k in the rising_factorial(x,n)

for i in range(1, 11): print(i, rising_factorial(x,i).simplify_full())

Give a formula for s(n,1)
This is the coefficient of x^1. Notice
s(n,1) = (n-1)!

Give a formula for s(n,2)
This is the coefficient of x^2. The formula is given by the sequence A000254 on OEIS.
s(n,2) = ( harmonic_number(i, 1) * factorial(i) ).numerator()

This was found by Eric Desbiaux, Jan 07 2009

def sn2(n): return (harmonic_number(i, 1) * factorial(i)).numerator() for i in range(1,11): print(i, sn2(i) )

Problem 10 (with bonus)

Create a sage code to plot the sequence s(n,k) after taking the residue when dividing by r. Use r different colors to plot the sequence.
My function supports r values from 1 to 10

color_list = ['white', 'blue', 'red', 'yellow', 'black', 'pink', 'orange', 'brown', 'black', 'grey'] def plot_stirling_residues(up_to_n, up_to_k, r): # make a list containing r empty lists L = [] G = points([]) for i in range(0,r): L.append([]) for k in range(1, up_to_k + 1): for n in range(1, up_to_n + 1): #calculate the residue residue = stirling_number1(n,k) % r #append to sublist of L based on residue L[residue].append((n,k)) # add points to the graphics object with colors that reflect residues for i in range(0,r): G = G + points(L[i], color=color_list[i]) return G # Plot the first 100 values of n for every value of k up to 100, taking the residue of r=4 plot_stirling_residues(100,100,2)
Now I show the plot for different values of r.
plot_stirling_residues(100,100,3)
plot_stirling_residues(100,100,4)
plot_stirling_residues(100,100,5)
plot_stirling_residues(100,100,6)
plot_stirling_residues(100,100,7)
plot_stirling_residues(100,100,8)
plot_stirling_residues(100,100,9)
plot_stirling_residues(100,100,10)