Intermediate Exercise
Create a Function where the user enters $n$ numbers of terms desired for a series and is returned its sum, the series being the following: $$S={1 \over 1^3} - {1 \over 3^3} + {1 \over 5^3} - {1 \over 7^3}+...$$
Remember that in most cases there is more than one way to solve the exercise.
Hint: Create a Loop with a given "$n$" and try to realize the pattern that exists in the series to be replicated.
We start by defining the arguments of the series and the output data type
Function InFSeR(n As Double) As Double
We define the variables
Dim i As Double
Dim Prog As Double
We create a For Next loop from 1 to $n$. The "Prog" variable was created to allow us to progress in the sum until we reach the n^th term
For i = 1 To n
Prog = Prog + (-1) * ((-1) ^ i) * (1 / ((2 * i - 1) ^ 3))
Next i
We define the output of the Function as the variable Prog when the For Next loop is done
InFSeR = Prog
Function InFSeR(n As Double) As Double
Dim i As Double
Dim Prog As Double
For i = 1 To n
Prog = Prog + (-1) * ((-1) ^ i) * (1 / ((2 * i - 1) ^ 3))
Next i
InFSeR = Prog
End Function
SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.
Excel ® is a registered trademark of the Microsoft Corporation.
© 2019 SuperExcelVBA | ABOUT
Thank you for contributing. A message was sent reporting your comment.