This time, I decided to play with some problems I’ve found interesting to solve, from the programming perspective, using H++.

Before I come with the H++ code’s solution, I had to first find it mathematically with just pen and paper. First of all, the problem that I solved, can be found in the book : **Mathematics by Experiment**: Plausible Reasoning in the 21st Century by **Jonathan Borwein and David Bailey**.

This is one of the most easy problems you’ll find in this book. They have co-authored for about 3 to 4 books, and they have discovered a lot formulas for mathematical constants like pi, e, gamma and others.

**The book**

This book requires a good set of tools like Maple, MATLAB and Mathematica, to solve most of the problems, because most of them are hard to solve by pen and paper most of the time.

I highly recommend this book, so go on and buy if your are serious about Mathematics by Experiments using Computers.

**The selected problem**

This time, I selected the problem 67, on page 333. This is it:

**The Scratchwork of the Problem**

In this paper, you can see, that it was not easy for me, because I found a lot of patterns in these matrices, that makes me spin around for a while; the I found the solution, and it was very easy to find, after all this scratch work, because I ran with all the possibilities before I find the real solution:

**The Solution on Paper**

And this is the algorithm that I deduced for this problem. It consists of two parts, the Recurrence Relation, and the Computer Algorithm:

**The Algorithm Implementation in H++**

My implementation in H++, was very easy, once I wrote it on paper. The only difference, is that in H++ as in C/C++ or C#, the arrays are 0-based. That means that in H++, all the arrays start from the subscript zero.

Here is the algorithm in H++ code:

And, this is the code that renders the matrices in the sequence:

**The H++ application**

As in other occasions, the program has just a main function, where everything starts (the H++ entry point):

This program just create an instance of the MatrixSuccesion class, clear the screen, and ask for the number of matrices in the sequence that the user wish to render. Finally, you can repeat the test, for other number of matrices up to 16. This program can only handle correctly, up to 16. Up from 16, the integer data type starts to overflow, and the last matrices will contain some negative elements, which is not correct. So, I kept it to this limit, which I tested.

**The Compilation of ExpMath.hpp program**

This is the output of the compilation process:

**The Resultant Matrix Sequences**

This is first test, which I entered n = 7 (up to 7 matrices):

**Matrices up to 10 in a matrix sequence of this type**

This is all this time folks! Hope that you have enjoyed like me, this simple solution.

See you in the next post!

## Leave a Reply