The math.js library I have used in a couple of previous posts includes comprehensive functionality for handling matrices, and in this post I will demonstrate how to use it for creating matrices as well as basic matrix arithmetic.

Continue reading

The math.js library I have used in a couple of previous posts includes comprehensive functionality for handling matrices, and in this post I will demonstrate how to use it for creating matrices as well as basic matrix arithmetic.

Continue reading

I have already written a couple of small SVG libraries, one in C and one in Python. However, the most useful and widespread use of the SVG format is within web pages so in this post I will begin to develop a JavaScript SVG library.

This first version has quite modest ambitions: just the ability to draw a few simple shapes as well as text. However, SVG is far more capable than most people realise so I will add further functionality in the future with the aim of creating a far more comprehensive library.

Continue reading

The math.js library which I used in my post on SI Prefixes in JavaScript also includes comprehensive functionality for handling complex numbers. In this post I will demonstrate how to use this, as well as providing an insight into the underlying arithmetic involved.

Continue reading

Most people are familiar with a few of the more common prefixes used before many units to denote a fraction or a multiple of the unit - kilograms, megabytes, centimetres etc.. As well as these there a number of less well known ones, going right up to yotta and right down to yocto.

A while ago I wrote a post on SI Prefixes in Python to list all the prefixes along with their corresponding powers and multipliers. When I started writing an equivalent in JavaScript I soon hit a brick wall when I realised that JavaScript's Number type couldn't provide the precision needed.

Searching around for a solution to the problem I discovered the excellent math.js library which, amongst many other things, provides us with a BigNumber type and I thoroughly recommend reading the documentation here. This post covers my simple little JavaScript project to list the numeric SI prefixes.

Continue reading

Benford's Law describes the distribution of the first digits of many, if not most, sets of numeric data and in this post I will implement a demonstration of the law in JavaScript.

Benford's Law centres on the perhaps surprising fact that in numeric data such as financial transaction, populations, sizes of geographical features etc. the frequencies of first digits follow a roughly reciprocal pattern.

Continue reading

Most cameras and image editing applications will generate histograms of image data, showing the distributions of colours for the three channels, red, green and blue. As part of an Electron application I am working on I developed a JavaScript implementation of image histograms using the NodeJS Jimp package. This is it...

Continue reading

This is a JavaScript project to convert colour values from red, green and blue (RGB) to hue, saturation and lightness (HSL) and back again. It runs on Node.js and uses the Jimp "JavaScript Image Manipulation Program" which is actually an npm library.

Continue reading

A while ago I wrote a post on estimating Pi using a variety of methods. As a sort of follow-up I will now write a post on estimating *e*, or Euler's Number, in JavaScript.

In this post I'll write a JavaScript implementation of the Levenshtein Word Distance algorithm which measures the "cost" of transforming one word into another by totalling the number of letters which need to be inserted, deleted or substituted.

The Levenshtein Word Distance has a fairly obvious use in helping spell checkers decided which words to suggest as alternatives to mis-spelled words: if the distance is low between a mis-spelled word and an actual word then it is likely that word is what the user intended to type. However, it can be used in any situation where strings of characters need to be compared, such as DNA matching.

Continue reading

I recently wrote an article called Should You Learn Data Structures and Algorithms?. It is primarily about the searching and sorting algorithms which many people seem to place so much emphasis on, especially in the educational sphere. My view is that the need to implement these algorithms is rare so you would be better off concentrating on learning topics which you will need on a day to day basis. However, you might need to learn at least the basics just to convince others of your prowess so I have put together a short bit of code to illustrate a couple of the best-known sorting algorithms.

I have started of with bubble sort and selection sort. Neither are very efficient but they are simple to understand and implement. In the future I will expand this project with further algorithms.

Continue reading