Mathematics By Experiments in H++: An Interesting Matrix Sequence   Leave a comment

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

Mathematics by Experiments

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:

Problem 67 on Page 333

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:

My ScratchWork on this problem

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:

My Solution to problem 67 on Page 333

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:

The Solution Algorithm in H++

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

The code that renders the matrices

The H++ application

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

The H++ program that uses the algorithm

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 compilation of ExpMath.hpp program

The Resultant Matrix Sequences

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

Results up to 7 matrices

Matrices up to 10 in a matrix sequence of this type

Results up to 10 matrices - matrix 7-10

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

See you in the next post!


Posted May 9, 2011 by hmarzan in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: