Ramanujan Second Problem
About a year ago, I wrote about one of my heroes, Ramanujan, and his first really cool problem: https://anothercasualcoder.blogspot.com/2018/02/ramanujan-first-problem.html. It turns out that he also had a less famous problem which went also unsolved for many, many years:
Sorry for the handwriting paint... In any case, this is an infinite series for which I have no idea how to solve, but with the help of some simple recursive code, you can pretty much find the solution in 5min. The code will be very similar to the first post, with the exception that I'm now passing two values (the "6" as v1, and the "2" as v2) as parameters, and the number of terms I want to process. In way than less than 70 terms, the function converges fast. The answer? 4 (four). Code and output are down below, cheers, ACC.
Code:
Output:
Sorry for the handwriting paint... In any case, this is an infinite series for which I have no idea how to solve, but with the help of some simple recursive code, you can pretty much find the solution in 5min. The code will be very similar to the first post, with the exception that I'm now passing two values (the "6" as v1, and the "2" as v2) as parameters, and the number of terms I want to process. In way than less than 70 terms, the function converges fast. The answer? 4 (four). Code and output are down below, cheers, ACC.
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ramanujan2 { class Program { static void Main(string[] args) { int max = 70; for (int i = 0; i <= max; i++) { Console.WriteLine("For terms = {0}, RSP = {1}", i, RamanujanSecondProblem(6, 2, 0, i)); } } static double RamanujanSecondProblem(int v1, int v2, int terms, int maxTerms) { if (terms >= maxTerms) return 0.0; return Math.Sqrt(v1 + v2 * RamanujanSecondProblem(v1 + 1, v2 + 1, terms + 1, maxTerms)); } } }
Output:
For terms = 0, RSP = 0 For terms = 1, RSP = 2.44948974278318 For terms = 2, RSP = 3.36028311636522 For terms = 3, RSP = 3.72428093078256 For terms = 4, RSP = 3.87774468792224 For terms = 5, RSP = 3.94474031740102 For terms = 6, RSP = 3.97467867768177 For terms = 7, RSP = 3.98827831877827 For terms = 8, RSP = 3.99453082330687 For terms = 9, RSP = 3.99743199901717 For terms = 10, RSP = 3.9987879611993 For terms = 11, RSP = 3.99942546059194 For terms = 12, RSP = 3.99972664621995 For terms = 13, RSP = 3.99986952935495 For terms = 14, RSP = 3.99993755361378 For terms = 15, RSP = 3.99997003836743 For terms = 16, RSP = 3.99998559315209 For terms = 17, RSP = 3.9999930590532 For terms = 18, RSP = 3.99999665010797 For terms = 19, RSP = 3.99999838067683 For terms = 20, RSP = 3.9999992160921 For terms = 21, RSP = 3.99999962001047 For terms = 22, RSP = 3.99999981558073 For terms = 23, RSP = 3.99999991039593 For terms = 24, RSP = 3.99999995641879 For terms = 25, RSP = 3.99999997878278 For terms = 26, RSP = 3.99999998966129 For terms = 27, RSP = 3.99999999495796 For terms = 28, RSP = 3.99999999753915 For terms = 29, RSP = 3.99999999879806 For terms = 30, RSP = 3.99999999941254 For terms = 31, RSP = 3.99999999971269 For terms = 32, RSP = 3.9999999998594 For terms = 33, RSP = 3.99999999993115 For terms = 34, RSP = 3.99999999996627 For terms = 35, RSP = 3.99999999998347 For terms = 36, RSP = 3.99999999999189 For terms = 37, RSP = 3.99999999999602 For terms = 38, RSP = 3.99999999999805 For terms = 39, RSP = 3.99999999999904 For terms = 40, RSP = 3.99999999999953 For terms = 41, RSP = 3.99999999999977 For terms = 42, RSP = 3.99999999999989 For terms = 43, RSP = 3.99999999999994 For terms = 44, RSP = 3.99999999999997 For terms = 45, RSP = 3.99999999999999 For terms = 46, RSP = 3.99999999999999 For terms = 47, RSP = 4 For terms = 48, RSP = 4 For terms = 49, RSP = 4 For terms = 50, RSP = 4 For terms = 51, RSP = 4 For terms = 52, RSP = 4 For terms = 53, RSP = 4 For terms = 54, RSP = 4 For terms = 55, RSP = 4 For terms = 56, RSP = 4 For terms = 57, RSP = 4 For terms = 58, RSP = 4 For terms = 59, RSP = 4 For terms = 60, RSP = 4 For terms = 61, RSP = 4 For terms = 62, RSP = 4 For terms = 63, RSP = 4 For terms = 64, RSP = 4 For terms = 65, RSP = 4 For terms = 66, RSP = 4 For terms = 67, RSP = 4 For terms = 68, RSP = 4 For terms = 69, RSP = 4 For terms = 70, RSP = 4
Comments
Post a Comment