Tutorial

## Distance…

Mathematica is perfect for working with lists and matrices.  Essentially making it useful for defining and manipulating geometry through rotations and later on analysing the forces through stiffness methods.

A key task when working with series of co-ordinates is to check that the relative distances between points don’t change so that the structural elements in between remain the same, even though the structure may have changed position and shape.  When you’re working with Mathematica and there’s a task that you need to do repeatedly it’s often worth creating a custom function that can be called whenever needed.

A couple of the functions that I’ve written can determine the distance between each co-ordinate in a list for 2D and 3D co-ordinate lists.

First, create some co-ordinates to work with on the examples.

Now that we’ve got some points to work with we can create a function to determine the distance between the points in 2D.  On 2D points, Mathematica has an inbuilt function called  EuclideanDistance[] which is nice and fast when determining the distance between 2D points.

There are two key parts to the function, the first part maps a list of points across the   EuclideanDistance[] function, with the second section essentially iterating the co-ordinates to restructure the list so that the function can be mapped across the list by rearranging it in a  (First point, Second point)(Second point, Third point) format…. until the last element in the list.

This is nice and zippy for 2D co-ordinates, but won’t work unfortunately for 3D and needs modifying to make use of the inbuilt function  Norm[] .

Running a comparison on speed for how 2D points are handled can be compared by zeroing out the Z ordinate.

As can be seen, EuclideanDistance[] is faster, but Norm[] is more flexible and can be used on 2D and 3D co-ordinates.

Tutorial

## Lists…

One of the things that I spend a lot of time doing in Mathematica is creating lists of co-ordinates so that I can export them into structural analysis software, either before or after I’ve rotated and transformed them through space to mimic a deployable structure.

Most of these methods I’ve picked up along the way through trawling Stack Exchange which I find a great resource for learning Mathematica, I’m not able to link to all of them as I’ve hoovered them up into a notebook over a long period of time and not kept all of the original links…

## Creating lists.

Frequently I’ll create a list of x co-ordinates, then y co-ordinates, then the z co-ordinates.  There are a multitude of ways to do this, a few of the ways to create a list of co-ordinates are linked below:

Other ways of creating lists, could make use of functions.

{0, 2, 4, 6, 8, 10}

{1, 4, 9, 16, 25}

## Creating points

And there are dozens of other methods that are available, but once you have your list of x, y, and z co-0rdinates then the next step is to combine them.  You could certainly type them in long hand as below, but the more nodes you have the longer it takes.

You could automate a simple list of co-ordinates like above in a couple of ways:

or

Both return the same list of co-ordinates:

{{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 0}, {4, 0, 0}, {5, 0, 0}}

## Combining lists.

Or you might have created a list of points, the same as the lists x,y, and z at the top of this post and now want to combine them…

Thread[ ] is available and is one of the quicker methods for knitting together lists.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}

or

both return.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}

### Transpose.

Transpose[ ]   can be used for nice tidy syntax

### Inner.

If there is a simple 2D set of co-ordinates, then these can be combined using  Inner[ ]

### Riffle.

Again for simple 2D lists, the function  Riffle[ ] can be used, but needs to be used in combination with  Partition[ ]

If you’re working with multiple lists, then a function called multiRiffle can be written, taken from here.

Gives

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}

## Custom functions.

If you only have 2D data points then a function could be written to knit them together, these functions can check to see if the lists are of the same length too which can be beneficial.

{{0, 10}, {1, 11}, {2, 12}, {3, 13}, {4, 14}, {5, 15}, {6, 16}}

Which can be adapted for 3D data points easily enough.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}

Hopefully this will help someone who’s learning Mathematica who’s going to be working with data points and co-ordinates a lot.  It seems to be a topic that gets asked a lot on Mathematica Stack Exchange so I thought it would be helpful to try and summarise up in one post.

## Dynamic Arches…

Tinkering about with SystemModeler a little further, I’ve managed to finally build a sprung arch, complete with dampers on the revolute joints.  I’m intending on using this principle in my research to create folded structures, so it’s interesting to see what effect the spring stiffness will have on the behaviour of the arch during the unpacking process – specifically looking at the accelerations on the masses at key points.

The thing that I was struggling with was creating a structure that had a set of equations that could be solved, the key concept I was initially missing was the closing of the structure with the special type of revolute joint to complete the chain.  Without this special revolute chain the equations are essentially unsolvable, so it’s important that one of these joints sits in the system somewhere.

Another concept is that the structure in the video has 3 straight segments, each 1m long; but the supports are only 2m apart…. forcing the arch to pop into a stable shape that balances the weights at each of the joints.  This is essentially what makes the arch wobble when solving the initial set of equations.  Next step is applying external forces and measurement points along the structure for displacement etc…

General

## SystemModeler….

I’ve had SystemModeler for a while, but struggled to get on with it.  I guess the issue that I’ve had with it is that there are very few learning resources and tutorials around to help cut your teeth.  Mathematica has been around for years, so there are endless resources that are suited to the individuals preferred method of learning, from PDF’s, Stack Exchange, and even Lynda.com now has a video based learning method for the basics.  Given that even simple models have dozens of flags that can be plotted and graphed and that certain flanges aren’t enabled by standard, I’ve waited until I’ve had a few minutes spare to start tinkering.

Today I’ve been fiddling about with a mass and two springs with dampers, what I’ve been trying to do (and failed) is to make both supports displace over a given time period to push a displacement through the system to see what effect spring stiffness and damping have on the system, eventually this will be scaled up to a chain of springs of about 40-50 elements and used to model a structural system but this is my validation model.

I’ve not worked out how to give the supports a nudge (something that we do when modelling in ANSYS) so I’ve cheated a bit by essentially shortening the left hand spring to give a similar effect and then watched to see how the system has damped down. Parameter settings below for the spring/damper system.

By specifying the spring length as 1m, then setting the nominal value for it as 0.5m to start with it gives the system a nudge to start it bouncing.  I’m sure there’s another more elegant way of achieving this but I’ll have to figure it out over the next few days.

I’ll keep tinkering over the coming days, to try and refine the process.   Hopefully I can find some more learning materials or a decent community… something comparable to the Mathematica StackExchange community would be ideal.

If anyone’s come across a decent text or resource I’d love to hear about it.

General

## No More Heroes…

I studied for my Civil Engineering degree a long time ago and did a sandwich degree at what was an old school polytechnic.  When I was on my year in industry I was dragged along (slightly reluctantly) to a technical meeting at Warwick University to listen to a chap called Heinz Isler.

Up until this point I’d never heard of Heinz Isler, but after sitting through his lecture for an hour I was utterly spellbound listening to his thought process and the shear creativity and quite frankly maverick nature of how he achieved his engineering structural forms.  This was the first time I’d seen structural engineering really become exciting and not be slavish to design codes or afraid of being bold.  This was my first time being inspired by a structural engineer and feeling that even if I lived for 12 lifetimes I could never be as good as this guy in front of me… and actually not feeling in the least bit bad about it, the guy before me was an utter genius.

Creative Commons Image courtesy of Trevor.Patt on Flickr.

After graduation I went to work for a lightweight structures company and when I eventually (and reluctantly) left so that I could gain some traditional engineering experience I was given a book called ‘An Engineer Imagines‘ all about Peter Rice.  Again to my shame, this was the first time I’d heard about Peter Rice and reading through his autobiography I was in awe at how far ahead of his time he was, refusing to take the tried and tested path and instead developing innovative solutions.

Unfortunately both of these engineering heroes of mine are now dead… with my only engineering hero Frei Otto, remaining alive.  There are lots of good engineers out there and I’m sure that they inspire and lead their respective fields…. and whilst I have a few academics who I’m in awe of in my research field, I can’t say that I have any engineering heroes of the same ilk as Isler, Rice, and Otto left anymore.

Perhaps that golden age of engineering has gone?  Where new techniques could be implemented and tested through modelling?  But I would have hoped that with the power behind geometrical computational models nowadays that perhaps this technology and power could be combined with the artisan skills of the past to create some genuinely beautiful and inspiring structures.

If Isler can create massive spanning thin concrete shells through freezing his wife’s bed linen, then surely we could be doing something even more mindblowing with the computational power that is now at our fingertips…

Who are the engineering heroes of tomorrow I wonder? Will they have the same passion and ability as those from the past or will they be limited as the world becomes a far more commercial place and less experimental?  Are the talented engineers being driven out of the technical aspects of the design process to become managers and is this damaging the market?

Uncategorized

## Undo!..

Mathematica 10, finally has a multiple undo function added…. finally!

Clearly the undo petition here brought it’s functionality screeching into the 20th century… so happy…

Tutorial

## Searching…

I thought I was pretty good at finding information using Google and other search engines, but after the recent Mathematica seminar I went to I realise that actually I could be searching smarter using Google.

For example, all of the Mathematica documentation sits on one site reference.wolfram.com and I could trawl this if I wanted, or even add the domain into the search field to help give it some focus, maybe even break out some simple BOOLEAN algebra to proper show off…. or I could read how to use Google properly and just constrain all of my search results to this site using site:

For example, entering the following into Google searches the reference.wolfram.com site (and only that site) for the word Transpose.

site:reference.wolfram.com Transpose

Now to take it a step further I could limit all of the responses to be PDF files incase they are tutorials that would be helpful.

site:reference.wolfram.com Transpose filetype:pdf

Give it a whirl on whatever sites you frequently search.

General

## Speed…

I’d never really given speed a lot of thought when coding my Mathematica notebooks, but after recently attending a seminar I think it’s something I need to spend some time thinking about.  My sheets are normally fairly trivial in comparison to some of the large banking house notebooks that run, but what I was interested to hear was that some of the sheets being run take over 6 hours from the other delegates.  That’s a long time to wait to see if your numbers are rubbish.

Also what was interesting was that the presenter spends a lot of his time making other people’s code work faster, essentially that’s the core of his consultancy business.  Some speed improvements were up to 912% faster.

So a 6 hour sheets would potentially run in less than 30 seconds.  Which is a hell of a lot faster and lets you run various scenarios in a day rather than one a day.

One simple thing that I took away from all of this is if I’m only interested in numerical results rather than symbolic, then I need to think carefully about the level of precision I require.

For example using the /AbsoluteTiming flag you can do a simple test to see the difference that the level of precision makes.  By simply adding a decimal point to the number 2 it will convert to machine level precision.

Gives a timing of 0.283438 seconds on my machine.  Simply adding a decimal place to the number 2 gives a significant speed jump.

Gives a timing of 0.000293 seconds, which is a massive shift in computation time.

Something to consider.

Tutorial

## Rotations…

In a previous post I showed how complex numbers are useful when rotating co-ordinates and since then I’ve hard coded several geometrical translation and rotation routines that have been crude, but functional in Mathematica.  Nothing too complex, but a nice little achievement, working with matrices and manipulations.

But the scary thing about a big program like Mathematica, is that it has lots of built in functions that whilst incredibly well documented, you have to be aware that they exist before you can start to search for them.

The transformation matrices scripted above, can be automated using some of the inbuilt functions in Mathematica 9.  So for example if I wanted to rotate some co-ordinates about the z-axis the syntax is quite straightforward and can be taken from the documentation.  Rotating 4 co-ordinates (a) around the z axis (b) to give the newly updated co-ordinates (c).

There are quite a few neat and compact examples over on the documentation website if you’re interested.

I personally struggle with Mathematica at times, not because the documentation is poor, but because the scope is so vast.  But with helpful sites such as Stack Exchange or the Wolfram Community Page I’m sure I’ll start to work my way through some of the more hardcore functions given time.

General

## Annual report…

Last year I created an annual report to help me reflect on the year and determine what it is that I need to keep the same, change, eliminate, or get counselling from to recover.  I found it a really helpful process so I’m going to try and make it an annual event even though I’m a little late with it this year.

## 1 What are your biggest accomplishments this year?

Last year I’ve achieved quite a few things that I wanted to, plus a few nice surprises.

• I was nominated for an NUS teaching award by one of my students, this means an awful lot to me as it shows I’m appreciated and genuinely making a difference.  Plus I got a mug and some free food!
• I won the Vice Chancellor’s Teaching Excellence Award.
• I passed my interim assessment on my PhD, although I’m still not sure how.
• We moved into our new family home and got ourselves established after a much harder build than we expected.
• I turned 40… quite a few of my friends I grew up with never made it this far. I feel blessed.

## 2 What are the biggest lessons you’ve learned this year?

I’m a dreadful communicator.  I can sing, dance, argue the point about the most complex of subjects, but I’m rubbish at talking about how I’m feeling, particularly if I’m feeling negative, tired, upset, or worried.  I’ve plenty of friends who’d let me bash their ears if needed, but I choose not to, I bottle it up, burn out, creak along until I fall over.

I’ve been surrounded a lot by serious illness this year, from close family, friends, work colleagues, students… and I’ve got to admit it’s been pretty scary.  There’s been times where I’ve genuinely feared for those I hold dearest and panicked that there’s about to be a big hole in my life, I need to let these people know more often how much they mean to me, I’ve learned that life is fragile and precious.

## 3 With a grade, how satisfied are you with how you spent the year? Why?

I’d struggle to give this a universal grade.  I’m made up with the new house, it’s given us a lot of space and we can have friends round for parties and food which has helped us strengthen relationships with friends and have visitors stay for catch ups, this has really contributed to life quality in a positive way.  The glass is definitely half full…

As always there are parts of work I love, parts I’d prefer to have surgically removed, but I attended graduation for the first time last year and I really enjoyed seeing my students graduate, which bearing in mind I didn’t want to go to my own graduation is quite something.  It was also nice that we went for a few beers with our students afterwards and I think they liked seeing that we’re human too… we think a lot of our students, but sometimes feel we have to maintain a bit of distance.  I’m not sure we’ve got the balance always right.

I think on the whole I’d give the year a B, because I need to gain more balance between home and work and find some collaborators for my research to work with, but on the whole I’m satisfied.

## 4 What do you want to accomplish next year, such that it’s your best year ever?

• I want to learn to relax.
• I want to make progress on my PhD and I want to build a team around my research.
• I want to survive my chairmanship with the IStructE in one piece.
• I want to be more anarchic and chaotic in my thinking and behaviour, I want to challenge convention.
• I want to surround myself with more brilliant people, to collaborate, contribute, relish….
• I want to grow.

## 5 What new habits to cultivate that will help you to achieve your goals in Q4?

I hope to identify better places to work, either through sharing an office space with someone, getting a study buddy to work with or perhaps just working from home more often with a colleague/friend.  I really want to immerse myself in research the coming year, but would work better if I had someone to immerse myself with in the topic.

I intend to chill out a little more, I work far too many hours on too many different roles this sometimes results in me spreading myself too thinly.   More concerts, more beer, more silliness, more doing nothing from time to time…

Once my chairmanship is up with the IStructE I am seriously considering walking away from several positions to free up time.  I’ve learned enough about roles to support/coach/mentor future graduates and I’ve no intention of pushing for a senior position.  I would like to become a Fellow of the Royal Society or the Royal Academy of Engineering, but I can’t see that happening as I’m not linked to either institution and you’re nominated for membership.

I will be more anarchic, I’m intending that this will be my last full calendar year as an academic (I plan to leave in 18 months time) and so before I leave I will challenge the system and try and leave a positive mark.  However, if I build a good research team around me with PhD students I genuinely could see me extending my timescale, or sharing myself between academia and an industrial role.  I will try my hardest to not become a passenger, I will be different, I will make a difference…

## 6 What are your immediate next steps to achieve these goals?

I will make more time to spend time with the family, this year we started playing board games with the kids and going out for walks.  I just need to try and protect more time to head out with my wife.

Last year I said I’d start growing plants and baking with the kids…. the baking part took off and I learned a few basic recipes and even taught my daughter how to use the electric whisk.  I need to do more of this.

I will grow, with purpose, focus, and a mohawk…