Showing posts with label mathematics. Show all posts
Showing posts with label mathematics. Show all posts

Thursday, 18 June 2015

Sum of 1 to 100

Back in school, during Math, one of the arithmetic examples that spoke the most to me about how Powerful Math can be, was the explanation for the adding up of the first one hundred numbers.

The short explanation

When you have a nice distribution of numbers like 1 to 100, it is obvious that the average is right down the middle, which is 50½. And given the fact that we have 100 numbers, the solution becomes obvious.

Okay, so for some people that explanation might have been a bit too short.

The Long Explanation

Determining the average of a series of numbers, \(x_{1}, x_{2}, x_{3}, ... x_{n-1}, x_{n}\) is done by summing them all, and then dividing by the amount of numbers you have.
\[x_{avg} = {\displaystyle\sum_{i=1}^{n} x_i \over n}\]
Therefore, it follows that the sum, i.e. the thing we wish to know, is obviously:
\[{\displaystyle\sum_{i=1}^{n} x_i} = n * x_{avg}\]
For the first 100 numbers, this gives:
\[{\displaystyle\sum_{i=1}^{100} x_i} = 100 * 50{1 \over 2} = 5050\]

The Staircase

Of course, most explanations use a bit more imagination to make things clear2.

Think of the problem as a staircase, with steps reaching from 1 to 100. To make things a bit more simple, and to save my having to draw 100 steps, let's try it with 10 first. With 100 steps the principles are the same.
The interesting part here, is that we can pair different numbers. We will add the numbers at the outside of the figure above, 1 and 10. This gives 11. Next the following outside numbers 2 and 9, also gives 11. In a figure, this would look as follows:
Hence, the answer is the surface of the square, \(5 * 11 = 55\).

Triangles

Obviously the surface area of the square is equal to the surface area of the staircase. If you look at the staircase, you might see a triangle. The surface of the triangle is half the surface of the square containing the triangle (actually containing the two triangles, forming the square).

So you could compute the surface of the staircase also by computing the surface of the square and dividing by two. As it's not a perfect triangle, we need to do some cutting. In geometry, this would look something like the following:

Anecdote

The Anecdote that everybody knows or has heard relates that Carl Friedrich Gauss3, a German mathematician who contributed significantly to many fields, solved this problem in primary school.

References

[1] LaTeX Mathematics
http://en.wikibooks.org/wiki/LaTeX/Mathematics
[2] What is the sum of the first 100 whole numbers?
http://mathcentral.uregina.ca/QQ/database/QQ.02.06/jo1.html
[3] Wikipedia - Carl Friedrich Gauss
http://en.wikipedia.org/wiki/Carl_Friedrich_Gauss

Thursday, 11 June 2015

Creating Math in Blogger

I've decided to add MathJax1 to my blog.

I have tried in the past to use MathML3, but it's support among internet browsers is still too fragmented to be of any use. It looks like this situation is likely to continue. Also, I am a big fan of the Tex notation, instead of the verbose XML I would need to get anything done in MathML.

The difference is obvious when you right-click on the Math Expressions below.

Example

When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c =
0\) and they are \[x = {-b \pm \sqrt{b^2 - 4ac} \over 2a}\]

JavaScript Snippet

I have added the below snippet to my HTML in my Template, as according to source [2].
<!-- Script for installing MathJax -->
<script type='text/x-mathjax-config'>
   //  <![CDATA[
    MathJax.Hub.Config({
      extensions: ["tex2jax.js"],
      showProcessingMessages : true,
      tex2jax: {
          inlineMath: [ ["\\(","\\)"] ],
          displayMath: [ ["\\[","\\]"] ],
          preview : "TeX",
          processEscapes: true
      },
      TeX: {
        Macros: {
            Moon: "{&#9790;}"
   }
   }
    });
   //   ]]>
</script>
<script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>
<!-- End Script for installing MathJax -->

References

[1] MathJax
https://www.mathjax.org/
[2] The Astronomy Learner - MathJax on Blogger
http://astro-learned.blogspot.nl/2015/01/mathjax-on-blogger.html
[3] Wikipedia - MathML
http://en.wikipedia.org/wiki/MathML
W3 - MathJax Overview
http://www.w3.org/Math/MJ/Overview.html
Hanselman - Exploring Crossbrowser Math Equations Using MathML or LaTeX With MathJax
http://www.hanselman.com/blog/ExploringCrossbrowserMathEquationsUsingMathMLOrLaTeXWithMathJax.aspx

Thursday, 14 May 2015

Operator Precedence

I see a number of people get the answer to the following equation wrong:
1 + 5 * 2
Depending who you talk to, it could either be 12 (6 * 2) or the appropriate and correct answer 11 (1 + 10).

Everybody knows the precedence of things, but to make matters clear, here's the list ordered in descending precedence:
  1. parenthesis (also known as brackets)
  2. exponents/roots
  3. multiplication/division
  4. addition/subtraction

Mnemonics

Several mnemonics are in use to remember the correct precedence. Below are three examples.

“Please Excuse My Dear Aunt Sally”
  • Parentheses
  • Exponents
  • Multiplication
  • Division
  • Addition
  • Subtraction

However, this mnemonic doesn't do justice to the fact that some operations actually have the same precedence, for example subtraction and addition.

“Hallo, Meneer van Dalen wacht op antwoord!”
  • Haakjes (Parentheses)
  • Machtsverheffen (Exponents)
  • Vermenigvuldigen (Multiplication)
  • Delen (Division)
  • Worteltrekken (Root)
  • Optellen (Addition)
  • Aftrekken (Subtraction)

This Dutch mnemonic is very very old (and very wrong nowadays). It indicates that roots are very low in priority. Also, if taken literally, it means there's a difference in precedence between, for example, addition and subtraction, similar to the English mnemonic.

“Hé, Mw. v/d Aorta!”

A different Dutch mnemonic (written above), also contains information regarding the equality of certain operations.
  1. Haakjes (Parentheses)
  2. Machtsverheffen (Exponents)/Worteltrekken (Root)
  3. Vermenigvuldigen (Multiplication)/Delen (Division)
  4. Aftrekken (Subtraction)/Optellen (Addition)
Unfortunately, it contains a number of abbreviations:
Mw.
mevrouw (misses)
v/d
van de (of)

References

Wikipedia - Order of operations
http://en.wikipedia.org/wiki/Order_of_operations
Wikipedia - Bewerkingsvolgorde
http://nl.wikipedia.org/wiki/Bewerkingsvolgorde

Monday, 12 March 2012

Math

I was experimenting with the new MathML, Markup Language for Displaying Equations in your browser.

There are a lot of different ways, apparently, of displaying equations. Most of them are JavaScript libraries[3] [4] that have been written.

I'm opting for "a standard", described at [1].

Thank heavens that it is possible to use MathML (3.0) without having to use html+xml and other requirements like in MathML 2.0. [2]

Unfortunately, it's support in browsers is still sorely lacking, for example Long Division is one of the new things in MathML, and it is either not well supported, or I am doing something seriously wrong.

Examples


The Quadratic Formula


x=b±b24ac2a

Long Division


٣ #x0664;٣٥٫٣ ١٣٠٦ ١٢ ١٠ ٩ ١٦ ١٥ ١٫٠ ٩ ١

Well, the long division example shows in my browser as utter junk. I hope someone else has more luck in viewing. Let me know. The examples in [5] also show non-working long division.

Browsers


Math MSIE 9 Chrome 17 FF10FF 8 FF 6Opera 11
EquationsXXOO OX
Long divisionXXXX XX

[1] MathML 3.0
http://www.w3.org/Math/
[2] MathML 3.0 Spec
http://www.w3.org/TR/MathML3/
[3] Math Jax
http://www.mathjax.org/
[4] Html5MathML
http://html5mathml.googlecode.com/svn/trunk/test1.html
"left/\right"
a notation that is commonly used in Netherlands for Long Division[2]
MathML, Firefox, and Firemath
http://lwn.net/Articles/440313/
[5] MathML 3.0 Spec Test Suite
http://www.w3.org/Math/testsuite/build/mathml3/frameset-full.xhtml
An introduction to MathML
http://www.ibm.com/developerworks/xml/library/x-mathml3/
Blogging Mathematics
http://holdenweb.blogspot.com/2011/11/blogging-mathematics.html
Mozilla MathML Project
https://developer.mozilla.org/en/Mozilla_MathML_Project
Firefox Mathml Demo
http://www.mozilla.org/projects/mathml/demo/
Firemath - Editor - Plugin for Firefox
http://www.firemath.info/