FDS Week3 Assignments - Doubts in Solution

FDS Week3 Assignments - Doubts in Solution
0

Hi,

(1) In the solutions for FDS week 3 - Exercise 2 - (5) the function compute_sum_epsilon() calls the function
compute_ratio() internally. But as the question asks for computation of F(x, N’) and F(x, N’-1) isn’t the function which has to be internally called is compute_sum() ?

Pasting the solutions code as given in the FDSW3Asgn1Prob2_Solution-200215-182944.ipynb file as below -

def compute_sum_epsilon(x, epsilon):
sum = 1
var = epsilon
i = 1
while var >= epsilon:
var = compute_ratio(x, i)
sum += var
i += 1
return sum

(2) Solution for Exercise-2 Question 6 has to be modified to print v1-v2 and not v2-v1 as asked in the question

p = -1.5

q = 7.1

v1 = compute_sum(p, 100) * compute_sum(q, 100)

v2 = compute_sum(p + q, 100)

print(v1, v2, v2 - v1)

Please clarify

Thanks,
Priya Rajan

  1. in this function we want to find F(x, N’) - F(x, N’-1) and compare against epsilon.
    F(x, N’) = 1 + sum(pow(x, n)/factorial(n)) where n is 1 to N’
    F(x, N’) - F(x, N’-1) = pow(x, N’)/factorial(N’) which is Compute_ratio function.
    so we are using compute_ratio function to calculate var and compare against epsilon and sum is calculated with in while loop by adding var to sum iteratively. so we dont need to call compute_sum function.

  2. Aim of calculating v1, v2 and identify the difference (v1-v2 or v2-v1), is to understand compute_sum(p,100) ~= e ** p
    compute_sum(q,100) ~= e ** q
    v1 = compute_sum(p,100) * compute_sum(q,100)
    ~= (e ** p) * (e ** q) = e ** (p+q)
    ~= compute_sum(p+q, 100) = v2
    hence difference v1-v2 or v2-v1 is to closure to zero (except difference in sign).

1 Like

Thank you for the clarification, understood.