Calculation for geometric series

Using SimpleMath to Compute Recursively Converging Series

The coding script SimpleMath, supported by Function Calculator, is highly useful for computing recurrence relations that converge systematically by 1.

Let’s consider the following infinite series:


1 + 1/2 + 1/4 + 1/8 + ... + 1/2^n + ...

This series sums an infinite sequence where each term is half of the previous one.

Deriving the Recurrence Relation

To compute this series, let’s first define its sum as :


S = 1 + 1/2 + 1/4 + 1/8 + ... + 1/2^n + ...

Now, let's multiply by :


(1/2)*S = 1/2 + 1/4 + 1/8 + ... + 1/2^n + ...

Since this new series is essentially with the first term 1 removed, we can express it as:


(1/2)*S = S - 1

Solving for  S, we get:


S = 1 + (1/2) * S

Implementing in SimpleMath

Using SimpleMath, we can code this recurrence relation as follows:

def S(n) = 1 + (1/2) * S(n-1);
S(0) = 0;

Here, S(n) and S(n-1) represent the sum S in our recurrence logic. Since S(n) and S(n-1) are nearly identical when n  is sufficiently large, the function approximates the correct sum.

However, recursive functions must have a base case to prevent infinite loops. That’s why we define:

S(0) = 0;

Without this, the function would attempt to evaluate , leading to an infinite recursion error. This ensures that when n  is reached to 0, the function returns 0 instead of continuing with the recursive formula.

Running the Function in Function Calculator

  1. Go to the Factory Page and enter the above code.
  2. Click the run button to execute it.
  3. Click save to store the function.
  4. Return to the Calculator Page and press the F2 button to check the saved functions.
  5. Select the function and compute , which will return 2.

This demonstrates how SimpleMath can efficiently compute recursive functions and infinite series!

Comments

Post a Comment

Popular posts from this blog

Prompt for AI

How Deep Is the Well?

Function Examples