Samir Khan

1744 Reputation

19 Badges

14 years, 158 days

My role is to help customers better exploit our tools. I’ve worked in selling, supporting and marketing maths and simulation software for all my professional career.

I’m fascinated by the full breadth and range of application of Maple. From financial mathematics and engineering to probability and calculus, I’m always impressed by what our users do with our tools.

However much I strenuously deny it, I’m a geek at heart. My first encounter with Maple was as an undergraduate when I used it to symbolically solve the differential equations that described the heat transfer in a series of stirred tanks. My colleagues brute-forced the problem with a numerical solution in Fortran (but they got the marks because that was the point of the course). I’ve since dramatized the process in a worksheet, and never fail to bore people with the story behind it.

I was born, raised and spent my formative years in England’s second city, Birmingham. I graduated with a degree in Chemical Engineering from The University of Nottingham, and after completing a PhD in Fluid Dynamics at Herriot-Watt University in Edinburgh, I started working for Adept Scientific – Maplesoft’s partner in the UK.

MaplePrimes Activity

These are Posts that have been published by Samir Khan

For no particular reason at all, these are parametric equations that print "Maplesoft" in handwritten cursive script when plotted

X := -2.05*sin(-2.70 + 2.45*t) - 3.36*sin(1.12 + 1.43*t) - 4.82*sin(-2.19 + 2.03*t) - 2.02*sin(1.36 + 2.31*t) - 2.41*sin(1.08 + 2.59*t) - 14.2*sin(1.51 + 0.185*t) - 5.25*sin(-2.04 + 1.85*t) - 2.81*sin(0.984 + 2.36*t) - 3.01*sin(-2.04 + 1.80*t) - 1.80*sin(-2.61 + 2.73*t) - 0.712*sin(-3.94 + 1.89*t) - 6.90*sin(-1.90 + 1.52*t) - 0.600*sin(-3.39 + 2.26*t) - 0.631*sin(-4.65 + 2.68*t) - 3.10*sin(-2.22 + 2.17*t) - 2.95*sin(1.38 + 1.25*t) - 1.43*sin(0.383 + 2.40*t) - 8.25*sin(-1.66 + 0.323*t) - 1.39*sin(-3.08 + 2.63*t) - 0.743*sin(-2.43 + 0.647*t) - 6.25*sin(-1.73 + 0.832*t) - 273.*sin(-1.58 + 0.0462*t) - 4.58*sin(-2.00 + 1.48*t) - 5.70*sin(-1.80 + 1.20*t) - 2.30*sin(1.42 + 0.462*t) - 3.24*sin(1.51 + 0.277*t) - 16.0*sin(-1.64 + 0.231*t) - 1.58*sin(0.779 + 1.71*t) - 0.571*sin(-2.08 + 0.970*t) - 8.85*sin(-1.88 + 1.34*t) - 1.10*sin(-2.24 + 2.08*t) - 1.49*sin(-2.27 + 1.02*t) - 2.19*sin(-1.70 + 1.94*t) - 4.47*sin(-2.06 + 1.57*t) - 2.08*sin(-2.02 + 1.06*t) - 5.70*sin(-1.86 + 1.62*t) - 2.26*sin(-1.66 + 1.16*t) - 3.95*sin(-1.98 + 1.29*t) - 0.928*sin(-2.08 + 1.76*t) - 2.98*sin(1.36 + 1.11*t) - 0.390*sin(-2.33 + 2.22*t) - 3.81*sin(1.01 + 2.54*t) - 0.613*sin(-1.43 + 1.66*t) - 19.7*sin(-1.60 + 0.138*t) - 0.524*sin(-2.87 + 0.414*t) - 2.15*sin(-4.63 + 0.694*t) - 0.782*sin(-1.56 + 2.49*t) - 5.27*sin(-1.81 + 1.38*t) - 5.18*sin(1.51 + 0.0923*t) - 6.83*sin(1.37 + 0.923*t) - 0.814*sin(-1.72 + 0.600*t) - 2.98*sin(-1.82 + 0.738*t) - 5.49*sin(1.44 + 0.509*t) - 3.90*sin(-1.76 + 0.785*t) - 0.546*sin(-2.18 + 0.876*t) - 1.92*sin(0.755 + 1.98*t) - 8.16*sin(1.38 + 0.553*t) - 0.504*sin(-1.56 + 0.371*t) - 3.43*sin(1.14 + 2.12*t):
Y := -1.05*sin(-3.81 + 2.68*t) - 7.72*sin(-4.59 + 0.231*t) - 6.38*sin(1.37 + 1.11*t) - 4.24*sin(-2.36 + 2.31*t) - 7.06*sin(1.18 + 1.80*t) - 4.60*sin(1.28 + 2.03*t) - 0.626*sin(-0.285 + 2.45*t) - 0.738*sin(-1.89 + 2.26*t) - 1.45*sin(-1.73 + 1.57*t) - 2.30*sin(-4.51 + 2.59*t) - 9.58*sin(-2.07 + 1.71*t) - 0.792*sin(-0.578 + 0.647*t) - 4.55*sin(1.49 + 1.25*t) - 14.0*sin(-2.13 + 1.62*t) - 1.02*sin(0.410 + 0.277*t) - 19.2*sin(-1.54 + 0.0462*t) - 17.3*sin(-1.86 + 1.20*t) - 1.96*sin(-0.845 + 2.63*t) - 0.754*sin(-0.0904 + 2.73*t) - 4.74*sin(1.11 + 1.48*t) - 1.79*sin(0.860 + 2.17*t) - 25.2*sin(-1.77 + 0.832*t) - 3.88*sin(1.30 + 0.462*t) - 20.8*sin(-1.66 + 0.323*t) - 17.6*sin(1.20 + 1.29*t) - 4.83*sin(0.169 + 2.36*t) - 10.8*sin(-2.01 + 1.85*t) - 8.69*sin(-2.17 + 2.22*t) - 5.48*sin(-1.69 + 1.34*t) - 18.1*sin(1.18 + 1.43*t) - 4.71*sin(0.728 + 2.08*t) - 1.15*sin(-3.44 + 1.52*t) - 2.53*sin(-2.61 + 2.54*t) - 5.48*sin(-2.02 + 1.94*t) - 4.67*sin(1.30 + 1.66*t) - 9.10*sin(1.37 + 0.970*t) - 6.45*sin(1.31 + 1.02*t) - 5.18*sin(-2.09 + 1.76*t) - 18.3*sin(-1.77 + 1.06*t) - 27.3*sin(1.31 + 1.16*t) - 2.83*sin(-3.01 + 2.40*t) - 2.93*sin(-1.70 + 0.138*t) - 4.17*sin(-2.06 + 2.12*t) - 1.60*sin(-4.25 + 1.38*t) - 2.69*sin(-1.89 + 0.371*t) - 7.92*sin(-1.78 + 0.600*t) - 19.6*sin(-1.79 + 0.738*t) - 22.6*sin(1.48 + 0.509*t) - 13.5*sin(1.21 + 0.923*t) - 5.53*sin(-1.64 + 0.0923*t) - 1.20*sin(0.145 + 2.49*t) - 3.15*sin(-1.57 + 0.414*t) - 1.74*sin(0.655 + 1.98*t) - 3.98*sin(-2.14 + 0.876*t) - 11.3*sin(-1.82 + 0.694*t) - 10.4*sin(0.987 + 1.89*t) - 8.39*sin(-1.53 + 0.185*t) - 27.8*sin(-1.76 + 0.785*t) - 9.39*sin(1.38 + 0.553*t):
plot([X, Y, t = 0 .. 68], scaling = constrained, axes = boxed);

While googling around for Season 8 spoilers, I found data sets that can be used to create a character interaction network for the books in the A Song of Ice and Fire series, and the TV show they inspired, Game of Thrones.

The data sets are the work of Dr Andrew Beveridge, an associate professor at Macalaster College (check out his Network of Thrones blog).

You can create an undirected, weighted graph using this data and Maple's GraphTheory package.

Then, you can ask yourself really pressing questions like

  • Who is the most influential person in Westeros? How has their influence changed over each season (or indeed, book)?
  • How are Eddard Stark and Randyll Tarly connected?
  • What do eigenvectors have to do with the battle for the Iron Throne, anyway?

These two applications (one for the TV show, and another for the novels) have the answers, and more.

The graphs for the books tend to be more interesting than those for the TV show, simply because of the far broader range of characters and the intricacy of the interweaving plot lines.

Let’s look at some of the results.

This a small section of the character interaction network for the first book in the A Song of Ice and Fire series (this is the entire visualization - it's big, simply because of the shear number of characters)

The graph was generated by GraphTheory:-DrawGraph (with method = spring, which models the graph as a system of protons repelling each other, connected by springs).

The highlighted vertices are the most influential characters, as determined by their Eigenvector centrality (more on this later).


The importance of a vertex can be described by its centrality, of which there are several variants.

Eigenvector centrality, for example, is the dominant eigenvector of the adjacency matrix, and uses the number and importance of neighboring vertices to quantify influence.

This plot shows the 15 most influential characters in Season 7 of the TV show Game of Thrones. Jon Snow is the clear leader.

Here’s how the Eigenvector centrality of several characters change over the books in the A Song of Ice and Fire series.

A clique is a group of vertices that are all connected to every other vertex in the group. Here’s the largest clique in Season 7 of the TV show.

Game of Thrones has certainly motivated me to learn more about graph theory (yes, seriously, it has). It's such a wide, open field with many interesting real-world applications.

Enjoy tinkering!

Last year, I read a fascinating paper that presented evidence of an exoplanet, inferred through the “wobble” (or radial velocity) of the star it orbits, HD 3651. A periodogram of the radial velocity revealed the orbital period of the exoplanet – about 62.2 days.

I found the experimental data and attempted to reproduce the periodogram. However, the data was irregularly sampled, as is most astronomical data. This meant I couldn’t use the standard Fourier-based tools from the signal processing package.

I started hunting for the techniques used in the spectral analysis of irregularly sampled data, and found that the Lomb Scargle approach was often used for astronomical data. I threw together some simple prototype code and successfully reproduced the periodogram in the paper.


After some (not so) gentle prodding, Erik Postma’s team wrote their own, far faster and far more robust, implementation.

This new functionality makes its debut in Maple 2019 (and the final worksheet is here.)

From a simple germ of an idea, to a finished, robust, fully documented product that we can put in front of our users – that, for me, is incredibly satisfying.

That’s a minor story about a niche I’m interested in, but these stories are repeated time and time again.  Ideas spring from users and from those that work at Maplesoft. They’re filtered to a manageable set that we can work on. Some projects reach completion in under a year, while other, more ambitious, projects take longer.

The result is software developed by passionate people invested in their work, and used by passionate people in universities, industry and at home.

We always pack a lot into each release. Maple 2019 contains improvements for the most commonly used Maple functions that nearly everyone uses – such as solve, simplify and int – as well features that target specific groups (such as those that share my interest in signal processing!)

I’d like to to highlight a few new of the new features that I find particularly impressive, or have just caught my eye because they’re cool.

Of course, this is only a small selection of the shiny new stuff – everything is described in detail on the Maplesoft website.

Edgardo, research fellow at Maplesoft, recently sent me a recent independent comparison of Maple’s PDE solver versus those in Mathematica (in case you’re not aware, he’s the senior developer for that function). He was excited – this test suite demonstrated that Maple was far ahead of its closest competitor, both in the number of PDEs solved, and the time taken to return those solutions.

He’s spent another release cycle working on pdsolve – it’s now more powerful than before. Here’s a PDE that Maple now successfully solves.

Maplesoft tracks visits to our online help pages - simplify is well-inside the top-ten most visited pages. It’s one of those core functions that nearly everyone uses.

For this release, R&D has made many improvements to simplify. For example, Maple 2019 better simplifies expressions that contain powers, exponentials and trig functions.

Everyone who touches Maple uses the same programming language. You could be an engineer that’s batch processing some data, or a mathematical researcher prototyping a new algorithm – everyone codes in the same language.

Maple now supports C-style increment, decrement, and assignment operators, giving you more concise code.

We’ve made a number of improvements to the interface, including a redesigned start page. My favorite is the display of large data structures (or rtables).

You now see the header (that is, the top-left) of the data structure.

For an audio file, you see useful information about its contents.

I enjoy creating new and different types of visualizations using Maple's sandbox of flexible plots and plotting primitives.

Here’s a new feature that I’ll use regularly: given a name (and optionally a modifier), polygonbyname draws a variety of shapes.

In other breaking news, I now know what a Reuleaux hexagon looks like.

Since I can’t resist talking about another signal processing feature, FindPeakPoints locates the local peaks or valleys of a 1D data set. Several options let you filter out spurious peaks or valleys

I’ve used this new function to find the fundamental frequencies and harmonics of a violin note from its periodogram.

Speaking of passionate developers who are devoted to their work, Edgardo has written a new e-book that teaches you how to use tensor computations using Physics. You get this e-book when you install Maple 2019.

The new LeastTrimmedSquares command fits data to an equation while not being signficantly influenced by outliers.

In this example, we:

  • Artifically generate a noisy data set with a few outliers, but with the underlying trend Y =5 X + 50
  • Fit straight lines using CurveFitting:-LeastSquares and Statistics:-LeastTrimmedSquares

LeastTrimmedSquares function correctly predicts the underlying trend.

We try to make every release faster and more efficient. We sometimes target key changes in the core infrastructure that benefit all users (such as the parallel garbage collector in Maple 17). Other times, we focus on specific functions.

For this release, I’m particularly impressed by this improved benchmark for factor, in which we’re factoring a sparse multivariate polynomial.

On my laptop, Maple 2018 takes 4.2 seconds to compute and consumes 0.92 GiB of memory.

Maple 2019 takes a mere 0.27 seconds, and only needs 45 MiB of memory!

I’m a visualization nut, and I always get a vicarious thrill when I see a shiny new plot, or a well-presented application.

I was immediately drawn to this new Maple 2019 app – it illustrates the transition between day and night on a world map. You can even change the projection used to generate the map. Shiny!


So that’s my pick of the top new features in Maple 2019. Everyone here at Maplesoft would love to hear your comments!

You might recall this image being shared on social media some time ago.


Look closely and you see Albert Einstein. However, if you move further away (or make the image smaller), you see Marilyn Monroe.

To create the image, the high spatial frequency data from an image of Albert Einstein was added to the low spatial frequency data from an image of Marilyn Monroe. This approach was pioneered by Oliva et al. (2006) and is influenced by the multiscale processing of human vision.

  • When we view objects near us, we see fine detail (that is, higher spatial frequencies dominate).

  • However, when we view objects at a distance, the broad outline has greater influence (that is, lower spatial frequencies dominate).

I thought I'd try to create a similar image in Maple (get the complete application here).

Here's an overview of the approach (as outlined in Oliva et al., 2006). I used different source images of Einstein and Monroe.

Let's start by loading some packages and defining a few procedures.


fft_shift := proc(M)
   local nRows, nCols, quad_1, quad_2, quad_3, quad_4, cRows, cCols;
   nRows, nCols := LinearAlgebra:-Dimensions(M):
   cRows, cCols := ceil(nRows/2), ceil(nCols/2):
   quad_1 := M[1..cRows,      1..cCols]:
   quad_2 := M[1..cRows,      cCols + 1..-1]:  
   quad_3 := M[cRows + 1..-1, cCols + 1..-1]:
   quad_4 := M[cRows + 1..-1, 1..cCols]:
   return <<quad_3, quad_2 |quad_4, quad_1>>:
end proc:

PowerSpectrum2D := proc(M)
   return sqrt~(abs~(M))
end proc:

gaussian_filter := (a, b, sigma) -> Matrix(2 * a, 2 * b, (i, j) -> evalf(exp(-((i - a)^2 + (j - b)^2) / (2 * sigma^2))), datatype = float[8]):

fft_shift() swaps quadrants of a 2D Fourier transform around so that the zero frequency components are in the center.

PowerSpectrum2D() returns the spectra of a 2D Fourier transform

gaussian_filter() will be used to apply a high or low-pass filter in the frequency domain (a and b are the number of rows and columns in the 2D Fourier transform, and sigma is the cut-off frequency.

Now let's import and display the original Einstein and Monroe images (both are the same size).

einstein_img := Read("einstein.png")[..,..,1]:

marilyn_img  := Read("monroe.png")[..,..,1]:

Let's convert both images to the spatial frequency domain (not many people know that SignalProcessing:-FFT can calculate the Fourier transform of matrices).

einstein_fourier := fft_shift(FFT(einstein_img)):
monroe_fourier   := fft_shift(FFT(monroe_img)):

Visualizing the power spectra of the unfiltered and filtered images isn't necessary, but helps illustrate what we're doing in the frequency domain.

First the spectra of the Einstein image. Lower frequency data is near the center, while higher frequency data is further away from the center.


Now the spectra of the Monroe image.


Now we need to filter the frequency content of both images.

First, define the cutoff frequencies for the high and low pass Gaussian filters.

sigma_einstein := 25:
sigma_monroe   := 10:

In the frequency domain, apply a high pass filter to the Einstein image, and a low pass filter to the Monroe image.

nRows, nCols := LinearAlgebra:-Dimension(einstein_img):

einstein_fourier_high_pass := einstein_fourier *~ (1 -~ gaussian_filter(nRows/2, nCols/2, sigma_einstein)):
monroe_fourier_low_pass    := monroe_fourier   *~ gaussian_filter(nRows/2, nCols/2, sigma_monroe):

Here's the spectra of the Einstein and Monroe images after the filtering (compare these to the pre-filtered spectra above).



Before combining both images in the Fourier domain, let's look the individual filtered images.

einstein_high_pass_img := Re~(InverseFFT(fft_shift(einstein_fourier_high_pass))):
monroe_low_pass_img    := Re~(InverseFFT(fft_shift(monroe_fourier_low_pass))):

We're left with sharp detail in the Einstein image.


But the Monroe image is blurry, with only lower spatial frequency data.


For the final image, we're simply going to add the Fourier transforms of both filtered images, and invert to the spatial domain.

hybrid_image := Create(Re~(InverseFFT(fft_shift(monroe_fourier_low_pass + einstein_fourier_high_pass)))):

So that's our final image, and has a similar property to the hybrid image at the top of this post.

  • Move close to the computer monitor and you see Albert Einstein.
  • Move to the other side of the room, and Marilyn Monroe swims into vision (if you're myopic, just take off your glasses and don't move back as much).

To simulate this, here, I've successively reduced the size of the hybrid image

And just because I can, here's a hybrid image of a cat and a dog, generated by the same worksheet.

To demonstrate Maple 2018’s new Python connectivity, we wanted to integrate a large Python library. The result is the DeepLearning package - this offers an interface to a subset of the Tensorflow framework for machine learning.

I thought I’d share an application that demonstrates how the DeepLearning package can be used to recognize the numbers in images of handwritten digits.

The application employs a very small subset of the MNIST database of handwritten digits. Here’s a sample image for the digit 0.

This image can be represented as a matrix of pixel intensities.        

The application generates weights for each digit by training a two-layer neural network using multinomial logistic regression. When visualized, the weights for each digit might look like this.

Let’s say that we’re comparing an image of a handwritten digit to the weights for the digit 0. If a pixel with a high intensity lands in

  • an intensely red area, the evidence is high that the number in the image is 0
  • an intensely blue area, the evidence is low that the number in the image is 0

While this explanation is technically simplistic, the application offers more detail.

Get the application here

1 2 3 4 5 6 7 Last Page 3 of 11