Thomas Russell: Programmer & Designer
Have a browse of my thoughts!

Recent Posts - What I've been saying

Adding a Generic p-norm in Modern C++

In this article, I will show how to use modern C++ features such as fold expressions, variadic templates and type-traits to make a safe, stable and generic $p$-norm function. Read more »

Getting stock price in C++

It seems to be a common problem that people wish to be able to get the current price of a particular stock/share, so I figured it would be a good idea to write a brief article on the easiest way to get the current stock price using native C++.

In this article, I will be making extensive use of the C++REST SDK, also known as Casablanca. It is an open-source, cross-platform SDK initially developed by Microsoft. I will also be using the Yahoo! Finance query engine as the data-source for our query.

I will be working with Visual Studio, which makes Casablanca trivial to install and use; simply right-click on your project and select “Manage NuGet Packages…”, then search for cpprestsdk and install it. If you are not using Visual Studio, you can find comprehensive installation instructions here. Read more »

Automatic allocation on the heap or stack

In response to one of the Google+ comments (which can be found here) to my post on how to create a Tensor class, I have decided to write an article on how to modify the CTensor to use a storage class which uses automatic allocation on the heap or the stack depending on whether a stack overflow is likely.

This is quite a long post, so I’ve provided a table of contents here for easier navigation:

  1. Current CTensor concerns
  2. How does automatic allocation help us?
  3. Writing our automatic storage class
  4. Finishing the stack-allocated class
  5. Finishing the heap-allocated class
  6. The Indexing Operator (operator[])
  7. Conclusion Read more »

Writing a Tensor class in Modern C++

As promised in my article about the mathematics of solving the multidimensional Poisson equation, I am beginning writing about the process of writing a parallelized solution to the Poisson Equation by successive over-relaxation. This article will be about writing a tensor class in modern C++, as we will need a multidimensional grid for our Poisson solver.

Mathematically speaking, a Tensor is a multidimensional object over some appropriate field. In this case we will be considering simple fields, real numbers (to floating-point precision), integers (modulo some appropriate power of 2) and complex numbers. Tensors are mathematically-rich objects, with their own notation and algebras embedded in Ricci calculus, but here we will only be writing a basic Tensor class equipped with a few useful operators, however, it is an easily extendable object, so can easily be modified for most general purposes. Read more »

Exporting a Matrix from C++ to Mathematica

In my previous two posts: Solution to the Laplace Equation in C++ using successive over-relaxation and Solution to the Poisson Equation in C++ using Successive Over-relaxation I generated a matrix in C++ and computed the elements of it using a numerical method. I then used Mathematica to visualize the data and compare it to the analytic solution to demonstrate the validity of the methods.

In this blog post I will demonstrate how to export a matrix from C++ (which I will be representing simplistically using a std::vector<std::vector<T>>) to Mathematica using the MatrixMarket (.mtx) format.

The reason I have chosen this particular format for exporting a matrix is because it is space efficient at representing sparse matrices and a NIST standard which is natively handled by many systems, including Mathematica.

N.B: The .cpp file is available in ZIP format at the bottom of this post. Read more »

Designed and Produced by Thomas Russell © 2014-2017

Log-in | Register