Martin's Blog

Matlab rant: Elementwise operations on arrays

Posted by Martin Orr on Saturday, 17 March 2012 at 17:27

I have to teach some simple use of Matlab to my engineering students. I don't much like the Matlab language, but then I am unhappy with pretty much every programming language I have ever used except C (which is great for some purposes but they do not include numerical work). Today I am going to rant about the first bit of code in our Matlab course (and probably the first non-trivial bit of code in many Matlab courses and tutorials).

My complaint concerns elementwise operations on arrays (i.e. applying the same operation to every element of an array). These are very important in Matlab, and sometimes you can write code that looks like it is acting on scalars and it just works elementwise on arrays. If scalar code would always just work elementwise on arrays then I might be happy with this (but I worry that if you had such a language, how would you distinguish operations that act on an array as a unit, not just elementwise?).

But sometimes you need to alter things slightly to work elementwise on arrays. I worry that for beginning programmers, the fact that elementwise array operations look so similar to scalar operations makes it difficult to understand when these alterations are required - it would be better to consistently require a syntax meaning "perform this operation elementwise."

no comments Tags matlab, programming, teaching Read more...

CATAM Projects

Posted by Martin Orr on Saturday, 03 May 2008 at 17:17

A substantial part of the past couple of weeks was occupied by CATAM, the computational projects for the Maths Tripos. For each project you write some computer programs for mathematical purposes, then write a report on the results you obtained and the mathematics involved. (This is the only part of the Maths Tripos assessment not done by exams.) This year's projects were more interesting than last year's - at least the ones I did contained a greater mathematical content, and got me interested in elliptic curves. I also did my programming this year in Scala, the language I learned last summer, to try out something different - I have never been entirely satisfied with any programming language for doing mathematics. (And now that I have got into functional programming I have moved the goalposts. I did my CATAM projects in an almost pure functional style, but there were a few places where I couldn't see any efficient way to do that.)

The deadline for that was on Wednesday, and I have finished my supervisions from last term yesterday, so now all that is left until the exams at the start of June is revision. That seems like a long time but there is a lot to revise (and longer than before since in previous years I did some lectures in Easter term).

2 comments Tags catam, programming, scala, tripos

Lessons from Sygneca

Posted by Martin Orr on Wednesday, 26 September 2007 at 10:11

I spent the summer working at Sygneca in Basingstoke. This was an interesting experience as, while I have developed some web-based projects for school and contributed the odd bit to open source projects, I have never worked on software development in conjunction with other people. Nevertheless each person mostly worked independently on separate projects. So long as the projects are small enough for this to be feasible, it definitely seems to be the most efficient way to develop: it is important when programming to be able to hold the entire project in your head at once (the details of bits you have already done can be dropped once you are satisfied they work), and this is hard if someone else is doing bits of it. When multiple people work on a project, each person's piece should be as separate as possible from the rest, with a strictly defined (and simple) interface. This worked well on a couple of occasions where a project required a component not only separate from, but different in nature to, the main project.

Sygneca does its development in a language called Scala which is a language developed at a Swiss university. It is an active research project, or set of research projects, so contains a lot of cutting-edge features; however it is actually very easy to use, and you can gradually pick up the more advanced features. It incorporates functional programming and a rich type system, both pieces of computer science with a strong mathematical content which I had never explored before.

no comments Tags basingstoke, programming, scala, sygneca, tech

Programming contest

Posted by Martin Orr on Tuesday, 15 November 2005 at 14:04

This weekend I went to Stockholm for the ACM North-west Europe Regional programming Contest. This was a very short trip - we were in Stockholm for about 48 hours from Friday evening to Sunday evening. The organisers had scheduled talks on a variety of computing topics on the Saturday morning; we didn't go to these in order to get some time for sightseeing. I'm glad I did this because the part of Stockholm where the competition was and where we were staying was pretty dull, but the centre of Stockholm was worth seeing. It contains a lot of water - being built on a series of islands - and contains many impressive buildings.

On Sunday there was the competition itself. We solved five problems out of nine, which put us in fourth place. The other Trinity team solved three problems and came around the middle. I was pretty pleased with this position, although I know we could have done better if Mark and I had done a lot of practice at coding quickly as Paul has (however this does not seem to me a useful skill for anything other than programming competitions).

On the journey home, I observed that check-in in Stockholm Skavsta airport was done entirely manually: they had a printed list of passengers on which they ticked your name off and then wrote the details onto a boarding pass.

-- Martin

no comments Tags ioi, programming, sweden

Archives