# Tag Archives: Mathematica

## Arc...

Following on from my last post where I was investigating how to determine the parabolic equation when only provided with three co-ordinates, I wanted to extend that knowledge and create a Mathematica sheet to allow me to do this without having to rely on Wolfram Alpha.  This is for two reasons, firstly if I don't have an internet connection, then I'm screwed as Wolfram Alpha isn't going to work for me... secondly I need to encourage a deeper understanding of the procedure and process if I'm going to get the most from Mathematica.

The first part is trying to determine the parabolic equation when I know three points on the curve, typically these are going to be the start, midpoint, and the end support point.  To give an appreciation of the geometry, it's important to firstly understand that parabolic curves are defined by the common equation:

Determining the length of a parabola with cartesian co-ordinates is done through applying the equation below over the limits being considered.

As three co-ordinates are known along the curve, the equations can be expressed as follows, with (x1,y1) (x2,y2) (x3,y3) being taken as the co-ordinate points... this gives a nest of simultaneous equations that can be solved using traditional matrix methods or in this case elimination could be used given that one of the input variables is 0.

Taking the co-ordinates above as (0,500) (2050,0) (4100,500) for the input variables, this gives the simultaneous equations below to solve:-

However, Mathematica is well equipped for solving simultaneous equations and simply requires that the expressions are stacked up neatly and logically.... there can be a few problems with mixing bracket types, but this is just down to practice.  To solve the simultaneous equations above, the following code will solve them, the double equals signs are used just to push up the accuracy of the expressions and Reals is used as an additional parameter just incase any of the solutions are imaginary numbers.

Solve[{a x1^2 + b x1 + c == y1, a x2^2 + b x2 + c == y2, a x3^2 + b x3 + c == y3}, {a, b, c}, Reals]

Which will return the following solution:-

Substituting this back into the general expression determines the parabolic equation for this particular curve to be...

The last thing to do is to work out the length of the curve between the two support points, this is a simple process determined by:-

For those of us with too little time on our hands, this calculation can easily be automated and defined within Mathematica using the following code, where f'[x] is used to differentiate the term within the brackets.

f[x_]:=500 - (20 x)/41 + x^2/8405;

NIntegrate[Sqrt[1 + (f'[x])^2], {x, 0, 4100}]

Which gives the length of the cable to be  4,257.24m  which matches Wolfram Alpha's answer perfectly... the next step is defining equal length links to segment this curve to start creating the geometry for parabolic cable-chain structures... that's definitely a post for another day.

The intention with this post is to help anyone who is trying to define parabolas and arc lengths using Mathematica... or traditional methods, if they've got time on their hands...

General

## Geometry...

I've posted a few times that I feel my mathematics skills have slowly atrophied having been out in industry and that this I feel will be my achilles heel when it comes through to my research.  One of the areas that I've been investigating is the relationship between cable-chain structures and their behaviour.

Depending on how many segments you divide the arc into will determine the geometry and efficiency of the cable-chain arch, now if it's a semi-circle that's not too hard to calculate the geometry using simple triangles.  In degrees the internal angle of each triangle will be given by the following formula, where nseg is the number of segments you're dividing the arc by:-

This then can allow you to calculate the length of the segment along the arc as set out below using the Cosine rule which I haven't used for probably about 20 years, this though is only half the problem as you still have to determine the length of the cables.

Next to determine the length of the cable, you will need to combine two of the triangles previously calculated and which gives double the internal angle and repeat the process for the cable that is shown highlighted in red below.

This all seems fine and well for simple circles, but how would you know that a semi-circle gives the most efficient arrangement for a cable-chain?  What about if it's a parabola?  Well fortunately for the mathematically out of practice determining the equation for a parabolic curve is pretty easy for us Mathematica users...  Let's say I know I have a draped cable that spans 4100m horizontally between supports and has a 500m drape at the middle.  We can define three points on this cable easy enough as can be seen below:

This is where Mathematica starts to flex its muscles for me and why I feel I get good value from the student version that I've purchased.  I don't know what the Mathematica code for determining a line through the points is, but if I press the = key twice I get access to the Wolfram Alpha Servers and try and describe using every day English what it is that I'm trying to do...  Following a blog post from Mathematica on determining arc lengths using calculus I tried the following term which doesn't use any mathematical code at all, simply describes what it is that I'm trying to do:-

Parabola through the points (0,500), (2050,0), (4100,500)

Which gives the me the following output, which is pretty helpful to the maths novice who is trying to explore and understand the relationship between the data, the expression, and the graph...

Which makes my life a lot easier as I can start to tinker with geometry very quickly now using this approach.  One of the cool things about working this way is that you can then start to dissect the code and determine what the correct format should be when creating Mathematica sheets and it makes learning Mathematica much much easier than say MatLab or Maple.

Whilst creating code like this would not be difficult for someone with a little rudimentary programming experience, it isn't that intuitive for a newb like myself, but now I can start to adapt this syntax to suit what I need...  The next step is to try and work out how to subdivide this into nseg number of equal length links... but that's a job for another day.  Maybe I'll need to start using polar geometry to make my life easier? Who knows... but at least I'm not being held to ransom by my elderly fuzzled brain anymore and I can explore and play with the maths rather than being pummelled by them.

I'd love to hear from other Mathematica users, especially to hear what their experiences are and particularly to hear if I'm missing a trick as I'm going through and learning the syntax...

## Mathematica...

One of the reasons that I started this blog was so that I could mess about with embedding some Mathematica files to help with testing out some ideas.  For this to make sense it's easiest if I embed a few simple examples in this blog post.  Now if you want to interact with these examples, I'm afraid you're going to have to download the Wolfram CDF player, which is completely free and works on PC's and Mac's alike.  Imagine it as a sort of PDF viewer but it lets you interact with the files as opposed to a PDF which is typically just a static and lifeless document.

Consider the following equation:

Most text books would draw the graph for this over whichever range they deemed to be suitable and then students would try and learn from these dull and boring diagrams.

Now this is how I was taught maths and in fairness, it's pretty dull and it's difficult to gain any form of intuition as to how it might behave if the 2 became a 3 for example, this is where Mathematica's CDF files come in handy because it has some nice tricks for letting you explore maths in an interactive fashion... let's consider the following equation, from the previous graph most people wouldn't really know how it would affect the graph.

But if we crank this through Mathematica we can create a really nice interactive widget that can be shared with anyone for free!  As you change the slider, the graph updates in real time, and if you want to know what number you're changing 'a' to be then simply click the little + sign next to the slider itself to expand the input values beneath it.  In fact if you think that messsing with sliders is far too much like hard work, then simply click the little play button in the top right and the widget will work the sliders for you... sit back and watch the pattern.

If you're not familiar with Mathematica, you may be concerned that this sort of widget is really difficult to create, but actually I'm still on Chapter 3 on the text that I'm working through and the code is incredibly simple to create this kind of interactive learning tool and I've replicated it below to show how few lines of text can create this level of interaction.

Manipulate[ Plot[ Sin[a x], {x, -10, 10}], {a, 1, 5}]

Essentially this code starts with "I want a slider widget", "Plot me a graph of Sin(a.x) over a range of values for x from -10 to 10", then "make the slider vary a from 1 to 5".

Now this seems ok, but the Manipulate command is actually incredibly powerful and with a little more twiddling, high quality interactive 3D plots can be created, so let's consider the following expression.

This expression has four variables: f,g,x, and y.  Of course, I bet you're dying to know what the graph looks like for this function so you can boost your maths skills...

This is where the CDF player starts to flex its muscles a little, not only can you mess around with the sliders to change the values of f and g... but you can click and rotate the 3D graph itself to get a better view of how you think it's working.  For me this level of interaction is a real opportunity for playing with the maths to help build up a level of intuition and feeling of how the maths will behave.  And once again the code to get it to work is fairly straight forward even for a novice such as myself.

Manipulate[Plot3D[(f ) Sin[ x] + (g)  Sin [y], {x, 1, 10}, {y, 1, 10}], {f, -10, 10}, {g, -10, 10}]

Now here's the rub, a full Mathematica licence is the best part of £1,000 for a lecturer to use, in these hard times that's a lot of money.  But because I carry 'dual' status as I'm studying 2 degrees as well as working full time as a lecturer I was able to pick up a student licence for roughly £80.  Normally the cost for a student licence is a shade over £100 but it is possible to reduce the normal student price by 15% by using the discount code PD1637 at the Wolfram store checkout and I still retain the full functionality of sharing my CDF files via export.

I hope this helps someone, if you've any feedback on this post or would like to ask any questions, please get in touch or leave a comment below.