Skip navigation

Tag Archives: maths

matrixencryption

A few years ago I wasted a lot of time writing a Javascript implementation of matrix encryption.  Now one of my maths assignments has a section about decrypting an encoded string… Russian spies… dead letter drops… yada yada.  I’ll be using my trusty Javascript implementation to blow the question over in a minute as opposed to 30.  I’m posting it here in case whoever marks my assignment wants to see it.

Unfortunately, WordPress.com doesn’t allow .zip uploads, so I’ve been a bit sneaky.  One quick and dirty hack exploits the fact that zip files are read from the end first, and JPEG files from the beginning.  So if you were to append a zip file to the end of a JPEG image, you could use the resultant file as either – depending on which file extension you give it, or which program you open it with.  Under Linux/Mac/*BSD, you can do such an appending operation with cat LoveLetter.zip >> Image.jpg .  Read up about Steganography on Wikipedia if you find this intriguing.

I’ve taken advantage of this highly unsophisticated technique to make available to you, dear reader, a copy of the encryption program.  Unfortunately what I’m writing also makes me sound like a big-headded twit.  So without further ado, here are the instructions:

  1. Save the picture of boy painting flowers
  2. Rename it so it ends with .zip
  3. Use your favourite unzip program to extract the contents.

Matrix encryption of the type I’ve used is very weak, but evidently popular in maths education.  I’m sure anybody with a computer could crack your love letter open with brute-force in a matter of minutes.  The only real-world application that comes to mind for this algorithm is to allow grade 10 girls to swap notes in their English class.

The painting is by Banksy, who has many other cool works to his name.  You can search for photos of his work on Flickr, where I nicked this one from.

Just a pair of top quality links I found this morning on Slashdot.

First, an article about the formula which pretty much single-handedly brought about today’s financial despair.  Allow me to summarise:  Evidence suggests that the quant who developed it knew the limitations of his model, but financial managers everywhere were drawn in by the simple treatment of complicated behaviour (correlation between two probabilities).  This formula ended up becoming so popular that by the time things happened which it didn’t predict, everyone was screwed.  Remember, it’s the managers who are responsible for the quagmire here because they went ahead and used this particular model against the advice of people in the know.  Moral of the story?  Study more maths.  Article here.

Second, a video posted in the ensuing discussion: The Crisis of Credit, Visualised.  Short and simple.  Watch it.

Energy of a system

A system, for the purpose of energy analysis, is defined by an arbitrary, imaginary boundary that isolates one or more components from the rest of the world.  Having established a border, it is possible to keep track of how much energy comes in and out of the system.

    Here the system is defined as "the ball", to which the footballer is an external influence.

Here the system is defined as "the ball", to which the footballer is an external influence.

You may recall that there are many different types of energy, which are categorised as either Kinetic or Potential.  By the way, the list given in part one was by no means exhaustive!  It’s possible for a system to have every single type of energy, although at the end of the day its total Energy (E) is equal to the sum of the Kinetic and Potential components, ie.

E = K + U

Total Energy = Kinetic energy + Potential energy

"Garden bed": Total Energy = Kinetic energy + Potential energy

There are a few more rules with regard to energy in a system:

  1. It is possible to convert energy between forms inside the system, for example, from Gravitational Potential to Kinetic.  The system’s energy can be rearranged into any combination of forms, including forms that weren’t present to begin with.  If I were to hold a marble above my head, the system of “the marble” would contain nothing but gravitational potential.  When I let it go, the marble’s potential energy is converted to kinetic energy.
  2. The conversion process itself does not add or remove energy from the system, however
  3. In the process of conversion, some of the total energy may be lost to mechanical inefficiencies such as friction and drag (more on them soon).

I imagined such partitioning of a system’s energy to be similar in concept to partitioning of space in a computer’s hard drive.  Or perhaps altering the selection of plants grown in a vegetable patch.  Point is, the total amount of energy/storage/dirt remains available and you can arrange things however you like.

Remember how energy was described as ‘the ability to push’, where ‘push’ is defined as ‘exerting force through a distance’?  Energy is measured in units of joules.  One joule of energy enables a system to exert one newton of force over a distance of one metre.  The joule is a measure of push capability, or energy.

It is worth pointing out the relativity of energy.  Suppose that I’m holding a tennis ball.  It’s still; the way I see it there’s no kinetic energy.  Now I tell you that I’m riding the Shinkansen, and you’re standing on the platform as I fly past at 300km/h.  You’re telling me that clearly the ball has twice the kinetic energy of a grand-slam tennis serve, even though I fail to see the ball moving at all.  Another example: you’re lying down in a hammock, barely above the ground.  Let’s say you have no gravitational potential.  Then I come along with my excavator and dig a trench underneath you, and before you know it, you’ve got potential.  Gravitational potential.  But you haven’t moved a muscle.  The reason you’ve gained energy is that your situation has changed.

Energy can be confusing because most of the time the ‘point of zero-reference’ is arbitrarily defined.  To one person, a tennis ball may have kinetic energy, but to somebody else in a different frame of reference it’s still.  More often than not, it’s best to think about change in energy, a concept that does not need a point of ‘zero energy’ to be defined.

Friction and Drag

Molecular bonds being broken as the blue object is lifted off the yellow surface

Molecular bonds between the molecules (blue and yellow circles) of two objects being broken as the blue object is lifted off the yellow surface

Whenever two surfaces are in contact, molecular bonds between the two materials are formed.  The two materials are attached, in a way.  To separate them requires the breaking of these bonds, which in turn demands a small amount of energy.  Thus, when something rubs or moves over a surface (like a book being pushed across a table, a car driving on the road, or balls inside a bearing), molecular bonds are continuously made and broken.  The amount of force required to break such bonds is called frictional force.  ‘Energy loss to friction’ usually means that an object is spending some of its energy breaking molecular bonds with the surface it moves on, in order to continue moving.

Ball farm

Ball farm (CC licensed)

Imagine you’re surrounded with brightly coloured plastic balls.  Plastic balls make it hard to move, right?  I mean, you try to walk to the other side of the enclosure and you’ve got to keep pushing them out of your way.  This situation is similar to the one we face every day.  The air that surrounds us is composed of many little molecules, or ‘small plastic balls of air’ if you will.  While air molecules are smaller and lighter than plastic balls, they still need to be pushed out of the way if you want to move.  The effort required to do this is minimal at low speed, but is well known to the road cyclist at the front  of the pack, and to anybody who has ever stuck their hand out the window of a moving car.  The force felt on your hand as you hold it out in the wind is called the drag force, and will slow you down unless you use some additional energy to negate the effect of drag.

Energy Transfer: Work

In the last Energy post, I explained that there were two types of energy: kinetic and potential.  Then there’s Work, which here appears as a technical term with a slightly different meaning to the everyday word of the same name.  Work is the expenditure of energy.  Work is energy as it is transferred between systems.  Work is what happens when things are pushed.  “The footballer transferred some energy to the ball” could be rephrased into a the more technical, “The footballer did work on the ball”.

You see, Work has the same unit as energy – Joules.  In the case of energy, one joule is the ability to push one newton through one metre.  For Work, one joule is the push of one newton through one metre.  It’s as if there were two words for money, one word when it’s in the bank (energy) and one for when you spend it (work).

Got that? When you transfer energy between systems, the process is called Work.  We can also express the situation as

W=ΔE

That is, Work is the change in the amount of energy.  In order to do work, which is to say in order to give something energy, there needs to be a push or pull.  Work may be done either through direct contact (kicking a ball), or ‘action at a distance’ – where force is exerted without contact.  If you’ve ever been amused by a magnet and a paper clip, you would be acutely aware of how the two can interact with each other and exert force without coming into contact.  Energy can be transferred by exploiting such mechanisms, not just by physical contact.

Vectors, the Dot Product and Work

We’re going to describe Work using maths, but first let me briefly introduce a mathematical tool we’ll need: the vector.  Vectors allow you to keep track of amount and direction.  A commonly used vector quantity is velocity, which encapsulates an object’s speed along with the direction it’s travelling.  For example, ’20km/h, at 23 degrees east of north’ has exactly the information a vector needs to have: amount (20) and direction (N 23 E).  Simple.  Vectors can be represented graphically as arrows, but we’ll see more of that soon.

Two vector quantities that pertain to the study of energy are force and displacement (how far something moves).  Remember that you apply force when you push things, regardless of whether they move or not.  You can apply an amount of force in any direction you like, and you can travel a certain distance in any direction you like as well.  Recognise that they both contain a magnitude (amount of force, distance) and a direction.

Suppose I’m dragging a dead moose along the ground.  I’m applying force of, say, 15 newtons through the rope, which is at 30 degrees to the ground.  The moose moves horizontally to the right, for 10 metres.  Let’s put all of that information in a diagram:

Moose

The force vector is shown as a blue arrow, and the displacement vector is in brown. The length of the vector represents the amount, and the arrow points in the direction in which the vector acts.

Note that the diagram is not to scale, and that the two vectors have a different unit of measurement (which is why the brown one, although it has a smaller number, is longer).  What the diagram shows is that the moose is being pulled 10 metres to the right, as in brown.  The 15N of force (blue) acts at all times as the moose is dragged, and doesn’t change in either size nor direction.

Clearly, the force vector is not in the same direction as the displacement vector.  Not all of the force exerted is being used to move the moose .  How much force, then, is in the direction of displacement?’  Let’s investigate ‘how much’ of the blue vector is in the direction of the brown one, by changing the angle between them:

Dot product

Dot product

Let’s call the force vector F, and the displacement vector d.  The lengths (‘size’, or magnitude) of these vectors are notated by |F| and |d|, which equal 15 and 10 respectively.  At any one time, the amount of force being applied to move the object – the numeric answer to the ‘how much’ question above – will be |F| cos θ, where θ (theta) is the angle between F and d.  In the case of the moose, only 13N of the original 15N is being used to pull the moose.  The other 2N goes towards trying to pull the moose up off the ground, but that’s not happening.

OK, so now we know that it’s 13N of force instead of 15 that’s moving the moose.  The moose is pulled 10 metres horizontally with a force of 13N.  Multiplying the force applied by the distance moved gives a value for the Work done on the moose, in other words – how much pulling was done.  We can summarise the relationship between Work done (ie, energy given to the moose), force applied and distance moved with a constant angle by

W = |F||d| cos θ

This equation can be expressed in shorthand using something called the Vector Dot Product, which here looks like

W = Fd

The Line Integral and Work

The dot product definition of work is only valid when (i) the angle at which force is applied remains constant, (ii) the amount of force remains constant, and (iii) movement is in a straight line.  For cases where one or more of these conditions is not met, a more general definition of work is needed.  Enter the line intergral.

lineint

The blue arrows, while no longer technically vectors, still represent the amount of force applied (after angles have been considered) at intervals along the path of movement

Consider the familiar: where our moose hunter applies constant force in a straight line.  We’ll assume that any angles have already been taken into consideration, ie F is a constant 13N.  Let’s draw this as a graph of Force vs Displacement, on the left.  Note that the graph does not indicate the angle at which force is applied, only the amount.  The work done is represented as the area between the force arrows and the displacement arrow, which here is W=Fd.  The shaded area is a rectangle, simple.  Expressed as an integral, it’s W=∫ F ds.  All this means is, ‘Find the area between the force arrows F and the displacement s, and call it the Work done”.

Now imagine that the moose hunter varies the amount of force being applied to the moose (either by changing the amount or angle at which he pulls).  This would look more like the middle graph, although the concept remains the same: Work is the the area between the force arrows and the displacement arrow.

Imagine now that our moose hunter took a curvy path instead of a direct one, perhaps to avoid some trees.  This is pictured on the right.  Although the ‘displacement vector’ is now curved, that doesn’t stop us finding the area.  In terms of the mathematics required to work things out, it’s exactly the same as before – as long as we’ve got force able to be expressed as a function of displacement.  It doesn’t matter how curvy a path Ms Moose Hunter takes, it’s still essentially W=∫ F ds.  Instead, it’s awarded a Line Integral notation for its efforts, and is now written as W=∮ F ds.

To reconsider the angle between force applied and distance moved, all we need now is to reintroduce the dot product (1), which expands to (2)

1.  W =∮ F‧ ds

2.  W =∮ F cos θ ds

The expressions above signify a process of finding the the ‘area’ between the force arrows and displacement.  It says, ‘Start with the displacement curve s.  Let’s chop it up into infinitely small pieces, ds.  For each piece ds, multiply it by the force F and cos θ, as experienced at that point along the curve.  Add the individual results together and you’ve got the Work done.

Follow

Get every new post delivered to your Inbox.