Archive for the ‘math software’ Category

May 3rd, 2013

I recently picked up a few control theory books from the University library to support a project I am involved with right now and was interested in the seemingly total dominance of MATLAB in this subject area.  Since I’m not an expert in control systems, I’m not sure if this is because MATLAB is genuinely the best tool for the job or if it’s simply because it’s been around for a very long time and so has become entrenched.  Comments from anyone who works in relevant fields would be most welcome.

On its own, MATLAB is insufficient to teach introductory control systems courses — you also need the control systems toolbox as a bare minimum but most books and courses also seem to require Simulink and the symbolic math toolbox.  All of these are included in the student edition of MATLAB which is very reasonably priced.

If you are not a registered student, however, and don’t work for someone who can provide you with MATLAB it’s going to be very expensive!  As far as I can tell, your only option would be to purchase commercial licenses which are very expensive (as in thousands of dollars/pounds for MATLAB and a few toolboxes).

What else is out there?

I have a strong interest in mathematical software and so I know that there are several products that have support for control theory. Here are some that I know of and have access to myself

  • Mathematica – Its symbolic math support far exceeds that of MATLAB and it is on an equal footing numerically but its control systems support is much more recent and I don’t know of a textbook that utilizes it.  One benefit of Mathematica is that it doesn’t separate functionality out into toolboxes – everything is just built in.  Another benefit to tinkerers is the home edition which gives you the full product at a much lower price than commercial licenses.
  • Maple – This also has very strong symbolic and numeric math support.  It also comes with some Control Systems support built in.  Like Mathematica, it has a home edition for non-commercial tinkering and learning.
  • Labview - A graphical programming language that I’m only just starting to get used to.  It has lots of users and advocates in my employers electrical and mechanical engineering departments.  There is no support for symbolic computing as far as I know.
  • Python – Python is a superb general purpose scripting language that’s also completely free.  Numerics are taken care of by Numpy, symbolics by Sympy and there is a control theory module, the development of which is coordinated by Richard Murray of Caltech (The same Richard Murray that co-wrote the book Feedback Systems: An Introduction for Scientists and Engineers).
  • Octave – Octave is a free implementation of the MATLAB .m language.  It also has a free control package.
  • Scilab – Scilab is a free numerical environment that also has a free control package.

I haven’t mentioned Simulink alternatives in this post since I’ve discussed them before.

Questions

Some questions that arise are

  • Are there any other alternatives to those listed above?
  • Do these alternatives have sufficient functionality to support undergraduate courses in control systems and control theory?
  • What would be the best language to use if you were teaching control systems as a Massively Open Online Course (MOOC)?
  • Does it matter to employers which computational language you learned your control systems in as an undergraduate?

I find that the final point is very divisive among people I discuss it with.  On the one hand you have those who say ‘It’s the concepts that matter, the language you choose to implement them in is much less important’ and on the other hand you have those who say ‘It’s gotta be MATLAB, my father used MATLAB and his grandfather before him. Industry uses MATLAB, I only know MATLAB, we must teach MATLAB.’

May 1st, 2013

As I type this, the sun is shining (finally!) and the skies are blue.  You’d think that it would be difficult to concentrate on writing this Month’s mathematical software round-up but it has been such an interesting month that it turned out to be a breeze.  Thanks to everyone who submitted news items for this month’s review, your feedback and generosity is greatly appreciated–I would have given up long ago without it.

If you have any news items for next month’s issue, please let me know via the usual channels.  Click here for the Month of Math Software Archives.

Things that are a bit like MATLAB

Things written for MATLAB

  • GAGA: GPU Accelerated Greedy Algorithms for Compressed Sensing is “a software package for solving large compressed sensing problems with millions of unknowns in fractions of a second by exploiting the power of graphics processing units”. It saw its first ever release in April.
  • Version 3.4.3.3481 of the Multiprecision Computing Toolbox for MATLAB was released in April bringing several enhancements including the addition of the incomplete gamma function, improvement to the accuracy of eigensolvers and speed up of determinant computations.

Spreadsheets

  • One of the most famous spreadsheet errors of all time was unearthed this month.  I’ll leave the explaining to the BBC and New Scientist.
  • Gnumeric is the free spreadsheet program from the GNOME Office project and April saw it updated to version 1.12.2  Updates include a set of new computational functions, fixes to various file import tools and a new font selector.

Graphs and Plotting

  • GNUPlot is a free, open source plotting package that’s been around for over 25 years.  It has been ported to almost every computer system known to man including Ye Olde Windows MobileAndroid and Raspberry Pi along with all of the platforms you’d usually expect.  April 2013 saw version 4.6.3 and the list of changes is at http://www.gnuplot.info/announce_4.6.3.txt
  • DISLIN is a plotting library for C, Fortran 77 and Fortran 90/95 and is also callable from several other languages including Perl,Python and Java.  Developed by the Max Plank Institute for Solar System Research, DISLIN has just hit version number 10.3.2.  Take a look at the new goodness here.

Numerical libraries

Python

It’s been a big month for mathematical and scientific software in Python with several releases of note.

  • After 7 months of work, The SciPy team have unveiled version 0.12.0.  The full list of updates is at http://sourceforge.net/projects/scipy/files/scipy/0.12.0/ but standout features for me are a Basin Hopping Global Optimisation routine (never heard of that algorithm but sounds interesting),  the ability to inspect the contents of MATLAB .mat files without actually reading them to memory and documented BLAS and LAPACK low-level interfaces.
  • According to its website, numexpr “evaluates multiple-operator array expressions many times faster than NumPy can.”  In other words, numexpr is one way to get Python code going faster.  Something that I didn’t realise until I wrote this entry is that it supports the high performance Intel Vector Math Library (VML).  April saw a release to version 1.4.2 with the new stuff listed at https://code.google.com/p/numexpr/wiki/ReleaseNotes
  • Pweave is a scientific report generator and a literate programming tool for Python, inspired by Sweave for R.  Version 0.21.2 of Pweave was released earlier this month — take a look at the release notes for details of what’s new.  Thanks to @mpastell for the news.
  • The IPython (Interactive computing in Python) team have released a bugfix update.  The details of version 0.13.2 are in the release notes.
  • Version 1.0 of the PyASTRAToolbox was released on 23rd April.  “The PyASTRAToolbox is a Python interface to the ASTRA Toolbox, a tomography toolbox based on high-performance GPU primitives for 2D and 3D tomography.”

Misc

  • Derek of Coding-guidelines.com has released version 0.5 of his Numbers tool which looks at the numeric literals contained in the source code of any program you pass to it. The numbers program extracts these literals, compares them against a database of ‘interesting’ values and prints out any matches; it can also print out values that don’t match.  The matching is fuzzy, the intent being to find mistakes.  To see why this might be interesting and useful, take a look at this blog post where Derek discovers that both Maxima and R use a wide variety of different literal values for pi.
  • Version 2.19-5 of Magma, the regularly updated, commercial computer algebra system with a focus on algebra, number theory, algebraic geometry and algebraic combinatorics has been released.
  • Version 6.1 of MapleSim has been released.  MapleSim is a physical modeling and simulation tool.

From the blogs

 

April 18th, 2013

A friend of mine recently got hold of a Microsoft Surface Pro tablet and he let me have a play on it for a couple of hours.  So, I installed Mathematica 9 and ran the benchmark.  A screenshot of the result is below with the Surface’s result in blue.  Not bad for a tablet!

Touch controlled Manipulates were a lot of fun too.  If only I could run such things on my iPad as appeared to be promised in http://blog.wolfram.com/2012/02/17/a-preview-of-cdf-on-ipad/

My only other comment is that the Touch Cover is truly awful, reminding me of ye-olde ZX81, but I’ve been told that the Type Cover is much better

Mathematica 9 benchmark on surface pro

March 4th, 2013

Welcome to the latest Month of Math Software here at WalkingRandomly.  If you have any mathematical software news or blogposts that you’d like to share with a larger audience, feel free to contact me.  Thanks to everyone who contributed news items this month, I couldn’t do it without you.

The NAG Library for Java

MATLAB-a-likes

  • Version 3.6.4 of Octave, the free, open-source MATLAB clone has been released.  This version contains some minor bug fixes.  To see everything that’s new since version 3.6, take a look at the NEWS file.  If you like MATLAB syntax but don’t like the price, Octave may well be for you.
  • The frequently updated Euler Math Toolbox is now at version 20.98 with a full list of changes in the log.  Scanning through the recent changes log, I came across the very nice iteratefunction which works as follows
    >iterate("cos(x)",1,100,till="abs(cos(x)-x)<0.001")
    
    [ 1  0.540302305868  0.857553215846  0.654289790498  0.793480358743
    0.701368773623  0.763959682901  0.722102425027  0.750417761764
    0.731404042423  0.744237354901  0.735604740436  0.74142508661
    0.737506890513  0.740147335568  0.738369204122  0.739567202212 ]

Mathematical and Scientific Python

  • The Python based computer algebra system, SAGE, has been updated to version 5.7.  The full list of changes is at http://www.sagemath.org/mirror/src/changelogs/sage-5.7.txt
  • Numpy is the fundamental Python package required for numerical computing with Python.  Numpy is now at version 1.7 and you can see what’s new by taking a look at the release notes

Spreadsheet news

R and stuff

This and that

  • The commercial computer algebra system, Magma, has seen another incremental update in version 2.19-3.
  • The NCAR Command Language was updated to version 6.1.2.
  • IDL was updated to version 8.2.2.  Since I’m currenty obsessed with random number generators, I’ll point out that in this release IDL finally moves away from an old Numerical Recipies generator and now uses the Mersenne Twister like almost everybody else.

From the blogs

January 30th, 2013

In a recent blog post, I demonstrated how to use the MATLAB 2012a Symbolic Toolbox to perform Variable precision QR decomposition in MATLAB.  The result was a function called vpa_qr which did the necessary work.

>> a=vpa([2 1 3;-1 0 7; 0 -1 -1]);
>> [Q R]=vpa_qr(a);

I’ve suppressed the output because it’s so large but it definitely works. When I triumphantly presented this function to the user who requested it he was almost completely happy.  What he really wanted, however, was for this to work:

>> a=vpa([2 1 3;-1 0 7; 0 -1 -1]);
>> [Q R]=qr(a);

In other words he wants to override the qr function such that it accepts variable precision types. MATLAB 2012a does not allow this:

>> a=vpa([2 1 3;-1 0 7; 0 -1 -1]);
>> [Q R]=qr(a)
Undefined function 'qr' for input arguments of type 'sym'.

I put something together that did the job for him but felt that it was unsatisfactory.  So, I sent my code to The MathWorks and asked them if what I had done was sensible and if there were any better options.  A MathWorks engineer called Hugo Carr sent me such a great, detailed reply that I asked if I could write it up as a blog post.  Here is the result:

Approach 1:  Define a new qr function, with a different name (such as vpa_qr).  This is probably the safest and simplest option and was the method I used in the original blog post.

  • Pros: The new function will not interfere with your MATLAB namespace
  • Cons: MATLAB will only use this function if you explicitly define that you wish to use it in a given function.  You would have to find all prior references to the qr algorithm and make a decision about which to use.

Approach 2: Define a new qr function and use the ‘isa’ function to catch instances of ‘sym’. This is the approach I took in the code I sent to The MathWorks.

function varargout = qr( varargin )

if nargin == 1 && isa( varargin{1}, 'sym' )
    [varargout{1:nargout}] = vpa_qr( varargin{:} );
else
    [varargout{1:nargout}] = builtin( 'qr', varargin{:} );
end
  • Pros: qr will always select the correct code when executed on sym objects
  • Cons: This code only works for shadowing built-ins and will produce a warning reminding you of this fact. If you wish to extend this pattern for other class types, you’ll require a switch statement (or nested if-then-else block), which could lead to a complex comparison each time qr is invoked (and subsequent performance hit). Note that switch statements in conjunction with calls to ‘isa’ are usually indicators that an object oriented approach is a better way forward.

Approach 3: The MathWorks do not recommend that you modify your MATLAB install. However for completeness, it is possible to add a new ‘method’ to the sym class by dropping your function into the sym class folder.  For MATLAB 2012a on Windows, this folder is at

C:\Program Files\MATLAB\R2012a\toolbox\symbolic\symbolic\@sym

For the sake of illustration, here is a simplified implementation. Call it qr.m

function result = qr( this )
  result = feval(symengine,'linalg::factorQR', this);
end

Pros: Functions saved to a class folder take precedence over built in functionality, which means that MATLAB will always use your qr method for sym objects.

Cons: If you share code which uses this functionality, it won’t run on someone’s computer unless they update their sym class folder with your qr code. Additionally, if a new method is added to a class it may shadow the behaviour of other MATLAB functionality and lead to unexpected behaviour in Symbolic Toolbox.

Approach 4: For more of an object-oriented approach it is possible to sub-class the sym class, and add a new qr method.

classdef mySym < sym

    methods
        function this = mySym(arg)
            this = this@sym(arg);
        end

        function result = qr( this )
            result = feval(symengine,'linalg::factorQR', this);
        end
    end

end

Pros: Your change can be shipped with your code and it will work on a client’s computer without having to change the sym class.

Cons: When calling superclass methods on your mySym objects (such as sin(mySym1)), the result will be returned as the superclass unless you explicitly redefine the method to return the subclass.

N.B. There is a lot of literature which discusses why inheritance (subclassing) to augment a class’s behaviour is a bad idea. For example, if Symbolic Toolbox developers decide to add their own qr method to the sym API, overriding that function with your own code could break the system. You would need to update your subclass every time the superclass is updated. This violates encapsulation, as the subclass implementation depends on the superclass. You can avoid problems like these by using composition instead of inheritance.

Approach 5: You can create a new sym class by using composition, but it takes a little longer than the other approaches. Essentially, this involves creating a wrapper which provides the functionality of the original class, as well as any new functions you are interested in.

classdef mySymComp

    properties
        SymProp
    end

    methods
        function this = mySymComp(symInput)
            this.SymProp = symInput;
        end

        function result = qr( this )
            result = feval(symengine,'linalg::factorQR', this.SymProp);
        end
    end

end


Note that in this example we did not add any of the original sym functions to the mySymComp class, however this can be done for as many as you like. For example, I might like to use the sin method from the original sym class, so I can just delegate to the methods of the sym object that I passed in during construction:

classdef mySymComp

    properties
        SymProp
    end

    methods
        function this = mySymComp(symInput)
            this.SymProp = symInput;
        end

        function result = qr( this )
            result = feval(symengine,'linalg::factorQR', this.SymProp);
        end

        function G = sin(this)
            G = mySymComp(sin(this.SymProp));
        end
    end

end

Pros: The change is totally encapsulated, and cannot be broken save for a significant change to the sym api (for example, the MathWorks adding a qr method to sym would not break your code).

Cons: The wrapper can be time consuming to write, and the resulting object is not a ‘sym’, meaning that if you pass a mySymComp object ‘a’ into the following code:

isa(a, 'sym')

MATLAB will return ‘false’ by default.

January 10th, 2013

R has a citation() command that recommends how to cite the use of R in your publications, information that is also included in R’s Frequently Asked Questions document.

To cite R in publications use:

  R Core Team (2012). R: A language and environment for
  statistical computing. R Foundation for Statistical
  Computing, Vienna, Austria. ISBN 3-900051-07-0, URL

http://www.R-project.org/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2012},
    note = {{ISBN} 3-900051-07-0},
    url = {http://www.R-project.org/},
  }

We have invested a lot of time and effort in creating R, please
cite it when using it for data analysis. See also
‘citation("pkgname")’ for citing R packages

This led me to wonder how often people cite the software they use.  For example, if you publish the results of a simulation written in MATLAB do you cite MATLAB in any way?  How about if you used Origin or Excel to produce a curve fit, would you cite that?  Would you cite your plotting software, numerical libraries or even compiler?

The software sustainability institute (SSI), of which I recently became a fellow, has guidelines on how to cite software.

December 29th, 2012

xkcd is a popular webcomic that sometimes includes hand drawn graphs in a distinctive style.  Here’s a typical example
xkcd graph

In a recent Mathematica StackExchange question, someone asked how such graphs could be automatically produced in Mathematica and code was quickly whipped up by the community.  Since then, various individuals and communities have developed code to do the same thing in a range of languages.  Here’s the list of examples I’ve found so far

Any I’ve missed?

December 14th, 2012

One of the best ways to learn how to use a piece of software such as Mathematica is simply to dive in and start using it.  If you get lost, consult the documentation and if you get really lost, ask for help…..but who to ask?

Ideally, you’d need a group of people who are friendly, knowledgeable and always around–no matter what time of day or night it is.  Wouldn’t that be great? It would be even better if they were to offer you all of this help and expertise for free.  Oh, and let’s have the moon on a stick while we’re at it.

The Mathematica StackExchange community offers Mathematica users all of the above requirements apart from the mounted satellite.  Based upon the same technology as the immensely popular Stack Overflow question and answer site for software developers, Mathematica StackExchange has over 3000 active Mathematica users.  Between them, these users have asked, and answered, over 4000 questions on almost every aspect of Mathematica you can imagine and then some.

A matter of reputation

Every user on Mathematica StackExchange has a reputation level which is essentially a measure of how much the rest of the community trusts that user.  Users are awarded reputation points (by other users) both for asking good questions and writing good answers which means that you don’t have to be a Mathematica master in order to succeed…inquisitive neophytes can also build up a solid level of reputation.  More details on the reputation system can be found at the site’s Frequenty Asked Questions section.

Starters for 10

To get a flavour of the site, I recommend taking a look at a few highly rated Q+As such as Where can I find examples of good Mathematica programming practice?, xkcd-stye graphs and How can I use Mathematica’s graph functions to cheat at Boggle?  Alternatively, take a browse through the list of questions sorted according to the number of votes they’ve recieved.

Before you ask a question of your own, it is recommended that you search the site to ensure that you’re not asking something that has been asked, and answered in the past.  Once that’s done feel free to ask away– you don’t even need to create an account and log-in (although it is highly recommended that you do)!

Make friends and influence people

I signed up for Mathematica StackExchange a couple of months ago (My profile’s here) but have only started using it in earnest for the last few weeks and I only wish I had started earlier.  Although I like to think that I know Mathematica pretty well, I’ve learned a lot more about it in a very short time from some very smart people.  I’ve also had a lot of fun, met some great people and maybe helped a few people out along the way.

So, if you have a Mathematica problem, and no one else can help, maybe you should try Mathematica StackExchange.

December 5th, 2012

Since I am writing this article while on a train it seems only fitting that I say ‘Welcome to the slightly delayed November edition of a Month of Math software, the latest in a series of posts that have been going for almost two years‘  If you have any news for the final edition of 2012 feel free to contact me to tell me all about it.

General Mathematics

Libraries

  • The Fast Library for Number Theory, FLINT, was updated to version 2.3 on November 9th.  See what’s new in this C library by taking a look at the NEWS file.
  • MAGMA is a GPU accelerated linear algebra library from the Innovative Computing Laboratory (ICL) at the University of Tennessee.  According to the release announcement, version 1.3 of the library includes some performance improvements and support for the new NVIDIA-Kepler GPUs.
  • PLASMA is another linear algebra library from the people at ICL and it too has seen a new release.  Version 2.5.0 Beta 1 contains a couple of new algorithms, bug fixes and performance enhancements–check out the release announcement for the details.  A nice paper that explains the differences between PLASMA and Magma is available at http://icl.cs.utk.edu/news_pub/submissions/plasma-scidac09.pdf
  • The HSL library is ‘a collection of state-of-the-art packages for large-scale scientific computation written and developed by the Numerical Analysis Group at the STFC Rutherford Appleton Laboratory’  It saw a few updates throughout November – see the project’s change log for details.

Mobile

  • SoftMaker have released their office suite for Android devices and my first impressions are that it blows the competition out of the water.  Although the Word and Powerpoint alternatives are fine, the app that might be of most interest to readers of this article is, of course, the spreadsheet app, PlanMaker.  This initial release includes over 330 calculation functions and has support for complex numbers, arrays and 3d charts.
  • MathStudio, one of the best mathematical apps for mobile devices has been updated to version 5.4.Other than adding suport for iOS 6 and iPhone 5 I have no idea what’s new since the release annoucement is rather sparse.

Bits and pieces

  • The numeric javascript library has been updated to 1.2.4.  This is mainly a big-fix release with full details at http://numericjs.com/wordpress/?p=66
  • The commercial computer algebra system, Magma, is now at version 2.18-11.  See what’s new at http://magma.maths.usyd.edu.au/magma/releasenotes/2/18/12/
  • The free open-source linear algebra library ViennaCL  is now available in version 1.4.0. In addition to the OpenCL-based computing backend, the new release now also provides a CUDA- and an OpenMP-backend. Most noteworthy among the many new features and updates are the improved performance of ILU preconditioners including optional GPU-acceleration using level-scheduling, the incomplete Cholesky factorization preconditioner, a mixed-precision conjugate gradient solver, and further increased API compatibility with Boost.uBLAS.
November 28th, 2012

Back when Mathematica 8 was released I tried to work out how many MATLAB toolboxes you’d need to buy to have the same functionality and came up with 9 toolboxes.  Readers of WalkingRandomly suggested several more in the comments.  Now that Mathematica 9 has been released, I thought I’d work through the exercise again.

So I think that Mathematica 9 contains at least some of the functionality of the following 18 MATLAB toolboxes. Click on the relevant toolbox for more information or an example.

I use both Mathematica and MATLAB extensively and sincerely wish that MATLAB had this level of integration.  Does anyone have evidence of any I might have missed (or shouldn’t have included)?