In [1]:
# Part A
function A(M)
r = 0
for n = 1:M
r = r + sqrt(n)
end
return r
end
Out[1]:
In [2]:
# Part B
function B(M)
r = 0
for n = 1:M
r = r + log(n)
end
return r
end
Out[2]:
In [3]:
# Part C
function C(M)
r = 1
for n = 1:M
r = r * (cos(n*pi/10)^2+0.1)
end
return r
end
Out[3]:
In [4]:
# Part D
## The product is independent to i, though it can be written as
function D1(M, x)
return (1+exp(x))^(M/2)
end
## If the x is wrong and is supposed to be an i, the function is
function D2(M)
r = 1
for n = 1:M
r = r * sqrt(1+exp(i))
end
return r
end
Out[4]:
In [ ]: