Tag Archives: math

Video Lectures.

This is a wonderful resource with lots of video lectures in science and mathematics

http://videolectures.net/

http://videolectures.net/Top/Mathematics/

Filed under math, mathematics

Creating a Mathematica demonstration on Fermat’s Theorem on Stationary Points

One of the new features of Mathematica 6.0 and above is that it allows you to create a new type of Mathematica notebook called a Mathematica Demonstration.

A Mathematica Demonstration usually consists of some sort of animation that can be manipulated thru some windows controls on the notebook. This is created using some new Mathematica 6.0 code.

The main part of the code is contained within

Manipulate[]

The Manipulate command resembles the Animate [] command of prior Mathematica versions. The main differences is that with Manipulate you may be able to use all the control types while with the Animate[] you may control one or multiple parameters with slider control.

When I got Mathematica I wanted to try my hands at creating a new Demonstration and I decided to create a demonstration on Fermat’s Theorem on Stationary Points.
This is a very beautiful theorem that states

If c is a local extremum in the interval (a,b) and f is differentiable at c, then f’(c)=0.

There is a very simple geometric interpretation of this theorem. As we know the first derivative of a function f could be interpreted as the slope of the tangent line thru the point (c,f(c)) if such derivative exist.  When the slope of the tangent line is zero  f’(c)=0.

My basic idea for the demo was to build a line segment tangent to a point c and I could vary the position of the point c and the line segment tangent  will get redraw.

I wanted to build the segment so that the length from (c,f(c)) to each of the ends of the segments was the same or that (c,f(c)) was the mid point of the segment. To accomplish this I figure the derivative of f at a point c and then computed the equation of the tangent line to f at c and then found the intersection of that line with a unit circle center on (c,f(c)). So the resulting Mathematica code looks like this nightmare!

Manipulate[
Plot[2 Sin[x] + x, {x, 0, 2 Pi},
Epilog -> {{Line[{{(
2 c + 4 c Cos[c] + 4 c Cos[c]^2 –
Sqrt[2] Sqrt[1 + 2 Cos[c] + 2 Cos[c]^2])/(
2 (1 + 2 Cos[c] + 2 Cos[c]^2)), (2 Cos[c] + 1) ((
2 c + 4 c Cos[c] + 4 c Cos[c]^2 –
Sqrt[2] Sqrt[1 + 2 Cos[c] + 2 Cos[c]^2])/(
2 (1 + 2 Cos[c] + 2 Cos[c]^2))) + 2 Sin[c] +
c – (2 Cos[c] + 1) c}, {(
2 c + 4 c Cos[c] + 4 c Cos[c]^2 +
Sqrt[2] Sqrt[1 + 2 Cos[c] + 2 Cos[c]^2])/(
2 (1 + 2 Cos[c] + 2 Cos[c]^2)), (2 Cos[c] + 1) ((
2 c + 4 c Cos[c] + 4 c Cos[c]^2 +
Sqrt[2] Sqrt[1 + 2 Cos[c] + 2 Cos[c]^2])/(
2 (1 + 2 Cos[c] + 2 Cos[c]^2))) + 2 Sin[c] +
c – (2 Cos[c] + 1) c}}]}, {Darker@Red, PointSize[0.015],
Point[{c, 2 Sin[c] + c}]}},
PlotLabel ->
Style[StringJoin[“slope: ” , ToString[N[2 Cos[c] + 1]]], 12],
AspectRatio -> Automatic, ImageSize -> {500, 400},
AxesLabel -> {Row[{Style[“x”, Italic], ” value”}],
TraditionalForm[2 Sin[x] + x]}], {{c, 2.08979, “value c”}, 0,
2 Pi}]

I have decided to simplify the code a bit to make the code more readable.

f[x_] = 2 (Sin[x]) + x;
d[x_] = D[f[x], x];
r = 1.5;
p1 := x /. Solve[(x –
c)^2 + ((d[c]) x + (f[c] – (d[c]) c) – (f[c]) )^2 == r^2,
x][[1]];
f1[c_] = p1;
p2 := x /. Solve[(x –
c)^2 + ((d[c]) x + (f[c] – (d[c]) c) – (f[c]) )^2 == r^2,
x][[2]];
f2[c_] = p2;
SetOptions[Plot,
Ticks -> {{-1, 0, 1, 2, 3, 4, 5, 6, 7}, {-1, 1, 2, 3, 4, 5, 6, 7}},
PlotRangePadding -> 1.5, AspectRatio -> Automatic,
Background -> Black, ImageSize -> {640, 480}, AxesLabel -> {x, y},
AxesStyle -> Directive[20, Thick, Orange]];
Manipulate[
Show[Plot[f[x], {x, -1, 2 Pi},
Epilog -> {
Inset[
Style[StringJoin[“value:”, ToString[N[c]]], Yellow, 20], {2, 7},
Alignment -> Center],
Inset[
Style[StringJoin[“Slope:” , ToString[N[d[c], 5]]], Yellow,
20], {2.5, 6.5}],
If[lin, {Thick, Dashed, Green, Line[{{c, 0}, {c, f[c]}}]}, {}],
If[lin && der, {Thick, Dashed, Green,
Line[{{c, 0}, {c, d[c]}}]}, {}],
If[circle, {White, Circle[{c, f[c]}, r]}, {}], {Thick, Yellow,
Line[{{f1[c], (d[c]) (f1[c]) + f[c] – (d[c]) c}, {f2[
c], (d[c]) (f2[c]) + f[c] – (d[c]) c}}]},
If[der, {Red, PointSize[0.02], Point[{c, d[c]}]}, {}],
{Red, PointSize[0.02], Point[{c, f[c]}]}}
,
(*PlotLabel->Style[StringJoin[“value:”,ToString[N[c]],” “,
“Slope:” ,ToString[N[d[c],5]]],Yellow,20],*)
PlotStyle -> Directive[Red, Thick]
], If[der,
Plot[d[x], {x, -1.001, c}, PlotStyle -> Directive[Blue, Thick]
], {}
]
], {{c, (2 \[Pi])/3, “Value c”}, -1, 2 Pi,
0.001}, {{circle, False, “Show Circle”}, {False, True}}, {{der,
True, “Show Derivative”}, {False, True}},
{{lin, True, “Show line”}, {False, True}}]

And I also added three check boxes to be able to see the graph of the derivative of the function f(x) and also to be able to see the circle.

The original mathematica demonstration I created is at Wolfram demonstration.

1 Comment

Filed under math, Mathematica

One easy problem and One not so easy problem.

A few post ago we used Mathematica to draw the altitudes of an arbitrary triangle of given coordinates. Now we are solving these other two problems The first figure the red lines represent the medians and on the second figure the yellow lines represent the angle bisectors. So our problem consist in finding the Mathematica code to produce these figures.

Let us do the easy one first. To draw a triangle and the medians we will use the Lineal Bezier equation we have use before and since we are interested in finding the mid points on each side the resulting Mathematica code is very simple.

a = {0, 0};
b = {3, 0};
c = {1, 2};
BAB[t_, a_, b_] := (1 – t) a + t b;
Graphics[{Background -> Black,
{{Thick, Blue, Line[{a, b, c, a}]},
{Thick, Red, Line[{c, BAB[1/2, a, b]}]},
{Thick, Red, Line[{a, BAB[1/2, c, b]}]},
{Thick, Red, Line[{b, BAB[1/2, c, a]}]}
},
Inset[Text[Style[“A”, White, Italic, Large]], {-.1, 0}],
Inset[Text[Style[“B”, White, Italic, Large]], {3.1, 0}],
Inset[Text[Style[“C”, White, Italic, Large]], {1.1, 2.1}]}]

Now for the angle bisectors it is a bit harder. We are going to need some property the bisectors satisfy that will allow us to get the coordinates of the intersection of each bisector with each of the sides. One property that could help us is this one.

Theorem: For a triangle ABC If CQ is the bisector thru the angle ACB then AC/CB=AQ/QB.

Notice we will need to find some distances between sides that are given by coordinates so the function EuclideanDistance will be of help. Since we can easily compute AC/CB we need to find Q in AB such that AQ/QB is equal to AC/CB but this is not difficult to achieve if we use the function Nearest. We can guess the best value of Q by building a table where Q is going from A to B and then we pick the best value that approaches to the ratio AC/CB. We can accomplished that with the following Mathematica Code.

a = {0, 0};
b = {3, 0};
c = {1, 2};
ac = EuclideanDistance[a, c];
bc = EuclideanDistance[b, c];
ab = EuclideanDistance[a, b];
cc = ac/bc;
BAB[t_, a_, b_] := (1 – t) a + t b;
N[cc];
tabl = Table[
EuclideanDistance[a, BAB[t, a, b]]/
EuclideanDistance[b, BAB[t, a, b]], {t, 0.000001, 1, 0.001}];
nearest = Nearest[tabl, N[cc]];
Flatten[Position[tabl, First[nearest]]]

that will give us the value 443 that we will use in conjunction with the 0.001 doing similarly for the other sides of the triangle we get the very compact solution

a = {0, 0};
b = {3, 0};
c = {1, 2};
BAB[t_, a_, b_] := (1 – t) a + t b;
Graphics[{Background -> Black,
{{Thick, Blue, Line[{a, b, c, a}]},
{Thick, Yellow, Line[{c, BAB[443*0.001, a, b]}]},
{Thick, Yellow, Line[{a, BAB[428*0.001, c, b]}]},
{Thick, Yellow, Line[{b, BAB[486*0.001, c, a]}]}
},
Inset[Text[Style[“A”, White, Italic, Large]], {-.1, 0}],
Inset[Text[Style[“B”, White, Italic, Large]], {3.1, 0}],
Inset[Text[Style[“C”, White, Italic, Large]], {1.1, 2.1}]}]

Again this time Nearest comes to the rescue and helps us get the best value from a list of possible values!

Filed under geometry, math, mathematics

These are the links to the Phun scenes on our lecture

Are you having phun Yet?

Binary Computer

Binary Computer with decimal conversion

Pascal’s Triangle

Fibonacci Sequence

Triangular Numbers Sequence

Sieve of Eratosthenes

Livio’s Multiplication Machine

If you like to play or modify the Scene above in the Phun simulator you can download the Phun program from

Posting from

Have Phun!

Filed under math

Are you having Phun Yet?

In my last Post I mentioned the incredible physics sand box or physics reality simulator Phun . Here I will explain in some detail one scene created with Phun.
When you build physical simulations in Phun you are creating a visual representation that is attached virtually near physical behavior. In a way you are actually building graphically a very sophisticated computer program where each element have physical properties. Like being able to move, collide, bounce, gravity, velocity, acceleration etc. Naturally the simulation is no perfect but is very close to reality and that is what makes it very surprising and I believe useful. It’s almost like using Lego blocks but this time you can build the building blocks by yourself!

I will name the process of building scenes “Phun programming” for the above reason and by extension a Phun programmer is he who creates a scene.

While many of the Phun programmers restrict them self to creating rockets and tanks some others have dedicated their time to create ingeniously intricate mechanism. I am still in complete awe by some of the mechanical things that people have created with Phun. Between those prolific creators I have found Livio Zucca from Turin Italy the home of world fame mathematician Giuseppe Peano. I believe Livio’s creations deserve more attention for his ingenuity.

In my prior post about the Pascal triangle with Phun I extended a prior idea from Livio. The machine in question is a binary mechanical counter.

The main component to perform computations in this particular device is what is know as a latch and it should not be confused with a flip-flop. The main difference between latch and flip-flop is that latches are transparent storage elements while flip-flops are not. Wikipedia point out this new distinction.

In the above picture you can see a magnified section of the machine. This we called the ball feeding mechanism and it’s function is to collect balls and feed them up the two dimensional vertical tube on the left.

Let us explained in a bit of detail how this is achieve with Phun.

In Phun you can simulate gravity and can also simulate movement. You can define two types of hinges. The normal kind that is just a hinge that hinges and there is the one that can act as an engine or motor. This is just a programmatic simplification on Phun’s designer part. It will be nice if there was some visual differentiation between them but at the moment there is none.

The crosses are used to attached things so they will not fall off the scene when gravity acts upon them.
Notice the green bar at the bottom of the picture. That bar acts as the collector of balls and it does have a very slight inclination this is useful in this design as it makes the balls roll slowly towards the left where the feeding mechanism is located.

You can also see a spring and I guess you must probably already know what a spring does!

and at last the actual latch

The latch acts like a balance and there is a hinge that can be visible if you magnify the picture a little bit more. The numbers have a double function in this particular case. They act as stoppers for the balancer and also as indicators of the state of the latch. As portrait above this latch is in 0 state.

As you probably know latches have two states. One can be use to represent 0 state as in this case and the other can be use to represent 1.

The latch alternates between this two states as you can see in the animation below.
You may also appreciate the mechanism for translating circular motion into linear upward motion on the left side. This mechanism brings back memories of the mechanism that provided steam locomotive with motive power in time past.

As you may have already guess by the picture of the machine and the name the function of this particular mechanism is to count balls dropping down from the device and this is done using the binary numerical system. The binary system is a numerical positional system that uses only two digits instead of the 10 digits we use in our decimal numerical system.

For educators Phun will be a source of inspiration. I believe it is very useful for the instruction and motivation of Mathematics,Physics, Computer Science, Mechanical Engineering,Electronics. Phun is opening a new universe of interactive learning and should I dare also say FUN!

If you like to play,run or modify the Scene above in the Phun simulator you can download the Phun program and the scene from

Livio’s binary counter

If you like to see a short video of my modification then go

I am planning to make more Posts with the Best of Livio’s Phun Machines.

Filed under math

Triangular Numbers (Part III)

Going back once more to the original problem of finding a formula to compute the $n$ triangular number.

$T_n=1+2+3+ \cdots +n$

Triangular numbers suggest by their name the idea of geometry and it should be interesting to try apply some geometric reasoning to solve the problem. As we explained in the first lecture triangular numbers are obtained when we arrange a number of stones in an equilateral triangular shape. It just happens that it is very convenient for us to re arrange those stones in another triangular shape. That is right angle triangle. In that way we are able to produce triangular numbers and it become very simple to arrange the stones in a two dimensional array of stones that could be easily counted. Now we will see how the geometric demonstration works for $T_4.$

First, we duplicate the number of stones so we have $2 T_4$ and conveniently rotating the second $T_4$ we can joint the first $T_4$ and we have as a result a rectangular shape.

The number of stones in that rectangular shape is very easy to compute. It will be the product of the number of stones in two sides. In this case $2 T_4=4(4+1)$ and since we have duplicated the original number $T_4$ now we need to divide by 2 and that will us the value $T_4=4(4+1)/2.$ The same procedure could be carry out for 100 stones or any other number. We do not suggest you do this literally for 100 stones, but you should be able to play this same argument in your mind.

In the previous example we were extremely close to form a square number. We actually missed this by just one row. That is why we have the $(4+1)$ factor. A natural question to ask is.

What should we add to any triangular number $T_k$ to get a square number?

We can see it in the diagram. What we need is to add the prior triangular number! We can express this algebraically with the following relation

$T_k+T_{k-1}=k^2$

What this formula is saying is that the sum of two consecutive triangular numbers is an square number. We can verify that this is true since $T_1+T_{2}=1+3=4$ and also $T_2+T_{3}=3+6=9.$ It is easy to see from the geometric configuration why the sum of two consecutive triangular numbers is an square. Since $T_k$ is something we are interested in finding then the relation seems to be also a kind of equation where the unknown to be found is $T_k$. Notice also that $T_{k-1}$ appears on the equation. Naturally if we know how to compute $T_k$ we then also know to compute $T_{k-1}.$ Equations of this type are known as recursive equations. The last row of $T_k$ will be the diagonal since subtracting the diagonal the resulting triangular number is equal to $T_{k-1}.$ We can also write another relation

$T_k=T_{k-1}+k.$

Now these two equations are defining $T_k$ in terms of the prior triangular number $T_{k-1}.$ These type of relations are called recurrence equations and we will discussed them in more detail in some other lecture. For now let us try and see if we can solve the first equation.

$T_k+T_{k-1}=k^2$

(This is a partial transcription of the Video Lecture Triangular Numbers (III) the video continues displaying a Solution)

The complete video lecture can be seen at Triangular Numbers (III)

There is a prior post similar to this at Triangular Numbers (I)

There is a prior post similar to this at Triangular Numbers (II)

This is a blog posting from www.isallaboutmath.com

Filed under math, mathematics, number, triangular number

Triangular Numbers (Part II)

In the prior lecture we have shown how Gauss solved the problem of

finding the sum $1+2+3+ \cdots +100.$

In Gauss solution we reduce the problem of finding the sum of different natural numbers to the problem of finding the sum of 50 equal numbers. It is very natural in mathematics to generalized concepts and results. A natural small generalization of the prior result will be to

find the sum $1+2+3+ \cdots +n.$

of the first $n$ natural numbers. It is also a natural impulse to try and solve similar problems with analogous solutions. In this case we will try to solve the problem using the same idea as Gauss with a very small modification. As in the prior lecture let us call $T_n=1+2+3+ \cdots +n$ the $n$ triangular number. We can easily re arrange the order of the elements in the addition in reverse order. Therefore we can write $T_n=n+(n-1)+(n-2)+ \cdots +1.$ If we add this two equalities we get

$2 T_n=(n+1)+(n+1)+(n+1) \cdots +(n+1)$

as in Gauss solution to the problem we have found again that adding a number from the beginning of the sequence to one number from the end of the sequence the sum stays constant. The right hand side of the equality is also very easy to compute. Since we have $n$ of those terms therefore

$T_n=n(n+1)/2$

This solution was easy to find because the solution is base on the same idea as Gauss’s solution. For the special case $T_n=1+2+3+ \cdots +100$ we have already point out why Gauss’s solution works and the same is true here. The solution works by translating the problem of finding the sum of different numbers to the problem of finding the sum of equal numbers and we are able to produce the equal numbers by conveniently re arranging the numbers in the sequence. In both cases we are dealing with sequences of consecutive natural numbers.

Could we generalize this a little bit more?

Yes, we can. What if instead of a sequence that starts on one we get a sequence that starts on $a_1$ and we obtain the next element by adding a constant natural number $d.$ So the elements of this progression will be

$a_1, a_{2}=a_1+d, a_{3}=a_1+2d, ..., a_{n}=a_1+(n-1)d$

this progression is a bit more general than the sequence of natural numbers. First, it does start on an arbitrary number and the difference of two consecutive terms is $d$ instead of 1. Progressions that satisfy this conditions are called arithmetic progressions. Example of arithmetic progressions are

$1, 2, 3, ...,100$

In this case the first element is 1 and the value for $d$ is also 1.

Another example is

$2,4,6, ...,200$

In this other example the first element is 2 and the increment is by $d=2$. So we obtained each term by adding 2.

Can we find a formula for the sum of the first $n$ terms of the arithmetic progression?

That is to find $a_1+a_2+a_3 \cdots +a_n$

where $a_k=a_1+(k-1)d$ for $k$ from 1 to $n$ to find this formula we suspect that we may be able to find some invariant as before …

(This is a partial transcription of the Video Lecture Triangular Numbers (II) the video continues displaying a Solution)

The complete video lecture can be seen at Triangular Numbers (II)

There is a prior post similar to this at Triangular Numbers (I)
This is a blog posting from www.isallaboutmath.com