Question

In: Computer Science

Using python coding, test for convergence of an infinite sequence or series. keep the coding at...

Using python coding, test for convergence of an infinite sequence or series.

keep the coding at beginner level please!

Solutions

Expert Solution

I wrote up an example function that should work:

Σ (from n=1 to inf) (an )/(bn-1) can be rewritten as Σ (from n=1 to inf) b*(a/b)n . Now that it's in this form, it's clear that this is a geometric series with r=(a/b). Thus, it will converge only when abs(a/b) < 1, and it will diverge otherwise. When it is in the divergent case, we will want to exit the function.

This is the function for it:

def compute_sum(a, b, tolerance=1e-5):
    if abs(a/b) >= 1:
        return None
    n = 1
    total_sum = 0
    prev_partial = 0
    while True:
        current_partial = b * (a / b)**n
        total_sum += current_partial
        if abs(prev_partial - current_partial) < tolerance:
            return total_sum
        prev_partial = current_partial
        n += 1        

As you can see, the first thing we do is check for divergence. I opted to return None in this case, but you can choose to throw an error if you'd like.

NOTE:Let me know if this answers your question or if I can explain anything better.


Related Solutions

1. Test the series below for convergence using the Root Test. ∞∑n=1 (2n/7n+5)^n The limit of...
1. Test the series below for convergence using the Root Test. ∞∑n=1 (2n/7n+5)^n The limit of the root test simplifies to lim n→∞ |f(n)| where f(n)=    The limit is:     Based on this, the series Diverges Converges 2. Multiple choice question.  We want to use the Alternating Series Test to determine if the series: ∞∑k=4 (−1)^k+2 k^2/√k5+3 converges or diverges. We can conclude that: The Alternating Series Test does not apply because the terms of the series do not alternate. The...
Prove the Weierstrass M-test for uniform convergence of Series of Functions.
Prove the Weierstrass M-test for uniform convergence of Series of Functions.
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program should begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive. Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are...
Tests for divergence of convergence 4) a) Use the ratio test to deteremine whether the series...
Tests for divergence of convergence 4) a) Use the ratio test to deteremine whether the series converges or diverges infinite sum (4^n)/(n!) n = 1 b) Use the root test to determine whether the series converges or diverges infinite sum ((2n + 1)/7n + 4) ^ 2n n = 1 stuck on this hw question !
Test the series for convergence or divergence. ∞∑n=1(−1)nn4n Identify bn.
Test the series for convergence or divergence. ∞∑n=1(−1)nn4n Identify bn.
Determine the radius of convergence and the interval of convergence of the following power series. ∞...
Determine the radius of convergence and the interval of convergence of the following power series. ∞ ∑ n=1 (2^(1+2n))/ (((−3)^(1+2n)) n^2) (4x+2)^n .
find the radius of convergence and interval of convergence of the series ∑ n=1 ~ ∞...
find the radius of convergence and interval of convergence of the series ∑ n=1 ~ ∞ (3^n)((x+4)^n) / √n Please solve this problem with detailed process of solving. I can't understand why the answer is [-13/3, -11/3) I thought that the answer was (-13/3, -11/3]. Can you explain why that is the answer?
Question 1 - Infinite Sequences. (a). Determine an infinite sequence that satisfies the following . ....
Question 1 - Infinite Sequences. (a). Determine an infinite sequence that satisfies the following . . . (i) An infinite sequence that is bounded below, decreasing, and convergent (ii) An infinite sequence that is bounded above and divergent (iii) An infinite sequence that is monotonic and converges to 1 as n → ∞ (iv) An infinite sequence that is neither increasing nor decreasing and converges to 0 as n → ∞ (b). Given the recurrence relation an = an−1 +...
Find the radius of convergence, R, of the series. Find the interval, I, of convergence of...
Find the radius of convergence, R, of the series. Find the interval, I, of convergence of the series. (Enter your answer using interval notation ∞ (−1)n  (x − 4)n 3n + 1 n = 0 ∞ (x − 4)n n7 + 1 n = 0 ∞ 7n (x + 5)n n n = 1 ∞ (x − 13)n nn n = 1 ∞ 4nxn n2 n = 1
The following DNA coding sequence is at the beginning of a coding region of the wildtype...
The following DNA coding sequence is at the beginning of a coding region of the wildtype MCB gene (wildtype allele) DNA   5’ C A T G A A A T G G* G A G C C T G A A G G A 3’ (mutant allele) DNA     5’ C A T G A A A T G A* G A G C C T G A A G G A 3’ There has been a base change mutation at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT