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

Friday, October 02, 2026

Interesting math solution

A well known math problem: You've got 40m of fencing and want to enclose a rectangular field beside a straight river:
The river forms one side of the rectangle, so you only need fencing along the other three. What is the maximum area of the field?

It is an optimization problem with a constraint and is normally solved using Lagrange Multipliers, a technique taught in graduate programs. Since my 14 year old son is preparing for the Turkish high school entrance exam (LGS), I wondered whether it could be solved using only middle-school mathematics.

Let's designate the short side of the rectangle as x and the long side as y. The length of the fencing gives us the equation

40 = 2x + y → y = 40 − 2x.

The area is A = xy. Substituting the equation for y,

A = x(40 − 2x) = 40x − 2x².

We are stuck because, in middle school, we don't know about derivatives. Or are we?

Rearrange the area equation:

A = −2(x² − 20x).

The expression x² − 20x = x² − 2*10x can be completed into a square by adding and subtracting 10²=100:

x² − 20x = x² − 20x + 100 − 100 = (x − 10)² − 100.

Plug this into the area equation:

A = −2((x − 10)² − 100) = −2(x − 10)² + 200.

Rearrange the terms:

A = 200 − 2(x − 10)².

Since we don't know x, we cannot find A... But let's think about this equation for a second...

We are subtracting a value from 200. If the whole −2(x − 10)² term could be positive, i.e. (x − 10)² could be negative, 200−2(x − 10)² would be larger than 200. But wait, (x − 10)² cannot be negative because the square of a real number is always positive. This means that −2(x − 10)² ≤ 0, making the area ≤ 200:

A = 200 −2(x − 10)² ≤ 200 

For area to be maximum, (x − 10)² must be minimum. The smallest possible value of (x − 10)² is zero, which happens when x = 10. Since the question asks for the maximum area, the answer is 200. We don't even need to find x = 10 and y = 20.

This is a very nice question because it requires you to see a missing piece, in this case, the missing terms needed to turn the expression into a perfect square. It also requires you to think more deeply about the equation and draw inferences from it. This is characteristic of the harder problems in the LGS exam.

Let's change the question slightly and say that we also need to use fencing material along the river side. The equations would then be:

40 = 2x + 2y → y = 20 − x

A = xy = x(20 − x) = 20x − x² = −(x² − 20x).

Complete the square:

A = −(x² − 20x + 100 − 100) = 100 − (x − 10)².

Using similar logic, the maximum area is 100 when x = 10 → y = 10. The fenced area is a square in this case. For this case, adding fencing along the river side halved the maximum area.

Can you prove that adding fencing along the river side always halves the maximum possible area, assuming the total amount of fencing remains the same, for any length of fencing?

Thursday, May 15, 2025

Intersection of circle and sine wave

I recently encountered the following question [University of Tor Vergata, Engineering Sciences, PreCalculus self assessment test, Geometry D]: A circle has center at the point A = (1, 1) and has radius r = 2. At how many points does it intersect the function y = sin(x)?

The equation of the circle with center (1, 1) and radius 2 is: (x - 1)² + (y - 1)² = 4

At any intersection point, the coordinates (x, y) must satisfy both equations:

1. (x - 1)² + (y - 1)² = 4

2. y = sin(x)

Let's substitute the second equation into the first: (x - 1)² + (sin(x) - 1)² = 4

This is a transcendental equation and cannot be solved analytically. Luckily, the equations are easy to plot by hand. The circle is trivial and plotting sin(x) only requires you to know that sin(0)=0, sin(pi/2)=1, sin(2*pi)=0. The sine wave amplitude is between -1 and 1. Since the circle has radius 2 and is centered at (1, 1), both the x and y interval for the circle will be [-1, 3]. This results in two intersections. Using Desmos for a cleaner plot:

Note that if we increase the amplitude of the sine wave, we will can have more than 2 intersections. For an amplitude of 3.5, we have 4 intersections:

After amplitude, if we also increase the frequency by 4, we get even more intersections:
It is only reasonable to find the number of intersections by hand drawing if the sine wave is of the simple form sin(x).

If you want to find the numerical values of the intersections (which is not asked for in the question), you have to use numerical root finding methods like Newton-Raphson.

Saturday, February 15, 2025

Hexagon proofs

Yesterday, I was solving a math problem with my 13 year old son involving a hexagon. The sum of internal angles of an n-sided polygon is calculated by the formula (n-2)*180°. For a hexagon, the number of sides n=6, the sum is (6-2)*180°=720°. I didn't like to use this formula and thought about a proof: Let's draw four triangles inside the hexagon and label the angles:
The 6 interior angles of the hexagon would be:
  1. a1+a2+a3+a4
  2. b1
  3. c1+b2
  4. c2+b3
  5. c3+b4
  6. c4
We know that the internal angles of a triangle, e.g. a1+b1+c1 is 180°. If we sum all the 6 internal angles of the hexagon, we see that they are equal to the sum of the internal angles of our 4 triangles. Therefore, the sum of the internal angles of a hexagon is 4*180°=720°.

Then I wanted to prove that the 6 triangles created by the diagonals of a regular hexagon are equilateral:

We can label the triangle internal angles x, y, z as follows:
 Using parallel lines, we can fill the internal angles of all 6 triangles:

Note that the sum of internal angles of the hexagon are (z+x)+(y+z)+(x+y)+(z+x)+(y+z)+(x+y) = 4*(x+y+z). Since x+y+z=180°, this is another way to prove that the sum of internal angles are 4*180° = 720°. Also note that this proof is only valid for a regular hexagon. For a non regular hexagon, the sides would not be parallel and we would not be able to assert the equality of angles of triangles. The first proof at the top is valid even for a non-regular hexagon.

Since all triangles have the same 3 internal angles (x, y, z), they are similar. Since they also have a side of length "a", they must be congruent. Since the side "a" is opposite to angle x in one triangle and opposite to y and z angles in the others, the angles must be the same, x = y = z, which can only happen if they are all 60°. Therefore, the triangles must be equilateral:

Friday, March 29, 2024

Matematik'te ezber yerine mantık yürütme

Dün oğlum 8. Sınıf Master Matematik Soru Bankası'ndaki Ünite Değerlendirme-5, soru 7'nin çözümünü tam anlamadığı için bana sordu:

Sorunun cevap videosunda üçüncü kart olarak BC=16cm çıkması durumunda birden fazla üçgen oluşturulabileceğini, bu nedenle olasılığın 3/4 olduğunu söylüyordu. Birden fazla üçgen oluşması için öne sürülen argüman tek üçgen için bir açı ve iki komşu kenarının bilinmesi gerektiği, eğer açının (soruda C açısı) karşısındaki kenar (16cm) verilirse tek üçgen belirtmeyeceği idi.

Oğluma soruları mümkün olduğunca kural ezberleyerek değil, mantık yürüterek çözmemiz gerektiğini hatırlattım ve şu yolu izledim:

  1. A merkezli ve 16cm yarıçaplı bir çember çizersek bu çember C'den geçen ışını iki noktada (B ve D) keser.
  2. 16cm AC'den (14cm) fazla olduğundan ikinci kesişim C köşesinin üst kısmında kalır (D noktası).
  3. Sorudaki üçgenin oluşabilmesi için çember kesişimi C'nin altında olmalıdır (B). O da ancak bir nokta olabileceğinden üçüncü kartın BC=16cm çıkması durumunda dahi tek üçgen oluşur.
  4. Cevap çözüm videosundaki 3/4 seçeneği değil, 4/4 = 1 seçeneği olmalıdır.

AB verildiğinde C noktasının altında iki kesişim, yani iki üçgen olasılığı ancak AB'nin AC'den az ve BC kenarına ait yükseklikten (h) fazla olması durumunda mümkün, bkz. aşağıdaki B1 ve B2 noktaları. AB uzunluğu yükseklikten de az olursa kesişim olmayacağından üçgen oluşmaz. AB yüksekliğe eşit olursa yine tek üçgen oluşur.

Friday, July 03, 2020

Probability of at least one failure

Say you have a system with 3 components (a, b, c), each having a failure probability of 0.1. What is the probability of at least 1 component failing? The standard way is P(at least 1 fail) = 1-P(all pass) = 1-(1-p)^n, where p = 0.1, n = 3 and result being 0.271 in our case.

The longer way is to find all unique failure combinations and their probabilities and sum them up because any of those combinations will satisfy "at least one failure" criteria. Pass probability = 1-0.1 = 0.9. Since fail order is not important, we can use combinations:
  • Failure combinations: abc, a (b and c pass), b (a and c pass), c (a and b pass), ab (c pass), ac (b pass), bc (a pass)
  • Probabilities: 0.1^3, 0.1*0.9^2, 0.1*0.9^2, 0.1*0.9^2, 0.1^2*0.9, 0.1^2*0.9, 0.1^2*0.9
  • At least one failing: abc OR a OR b OR c OR ab OR ac OR bc. In probability, OR is summation, AND is multiplication.
  • Sum: 0.1^3 + 3*0.1*0.9^2 + 3*0.1^2*0.9 = 0.271
  • Check with short solution: 1-(1-p)^n = 1-(1-0.1)^3 = 0.271
We can generalize it as follows. C(n,k) means number of k combinations in a set of n elements:
  • P(At least 1 fail) = C(3,1)*p*(1-p)^2 + C(3,2)*p^2*(1-p) + C(3,3)*p^3
  • k=1..n, sum(C(n,k)*p^k*(1-p)^(n-k))
  • Binomial Theorem: k=0..n, sum(C(n,k) * x^k * y^(n-k)) = (x+y)^n
  • If we use x = p and y = 1-p, we get k=0..n, sum(C(n,k) * p^k * (1-p)^(n-k)) = (p+1-p)^n = 1. The reason that this summation is one is that it represents all possible combinations and sum of probability of all combinations (including no failure case) is 1. 
  • In our case k starts from 1, because. we don’t consider the empty set, i.e. no failure case. Probability of k=0 (no failure) case: C(n,0) * p^0 * (1-p)^(n-0) = (1-p)^n.
  • Subtract k=0 case: k=1..n, sum(C(n,k) * p^k * (1-p)^(n-k)) - (1-p)^n = 1-(1-p)^n, which is equal to the short solution at the beginning of this post.

Tuesday, March 17, 2020

Applied Mathematics

Recently I helped my cousin with her integral questions. They were about areas between curves. This made me think if there were any applications of this that I personally know of and came to the conclusion that I don't know any. I decided to make a list of mathematical subjects that I apply in my work so that I can motivate students who are exposed to them for the first time:
  1. Trigonometry (sine, cosine)
  2. Quadratic equations
  3. Vectors in 3D, derivative of vectors in rotating reference frames
  4. Linear algebra. Cross product, dot product. Matrix multiplication: Used in rotating objects in 3D
  5. Basic integral
  6. Basic derivative
  7. Differential equations (2nd order ODE)
  8. Taylor Series (for linearization and as a starting point of numerical integration)
  9. Interpolation
  10. Gaussian distribution. Regression. Bayes' Theorem. Markov Chain. Kalman Filter
  11. Fourier Transform

Wednesday, December 25, 2019

Lessons from teaching my kid math for 10 months with Khan Academy

I have been teaching my 7 year old child mathematics with Khan Academy since February 2019. Everyday at about 19:00, we have a 15 minute session. Right now we are at 85% of 4th grade. During this time, I discovered that the difficulty of math does not lie in concepts, but in the high degree of attention it requires. Contrast a reading assignment with a math problem; In reading, you might omit a few letters, even words and still get the essence of the text and be able to answer questions correctly. With a math problem, if you misread even one symbol, you will be completely wrong. In this respect, math resembles software development.

During our problem solving sessions, I saw again and again that my son had no problem with the subject matter but was usually missing a bit and getting the answer wrong. When I helped him just a little by telling him to be more careful, he was able to solve most of the problems.

I suspect many students who are bad at math struggle due to a lack of attention. Unfortunately, improving attention requires one on one care, which the education system cannot provide. Parents have to help their kids.

Other lessons learnt:
  1. It is frustrating to witness that your child forgets the math rule you explained a minute ago. Be patient and repeat as much as necessary.
  2. Only advance to the next subject when your child can solve all of the end of chapter questions without any assistance from you. You might be dismayed by how many times he might have to repeat that test. As an example, my child solved all 18 questions of Understanding Decimals unit test in one sitting on his 13th try. It took him almost two weeks of frustration and tears! This sharpened his attention and cured his false sense of self-confidence(!)
  3. Every couple of months, revisit older subjects by re-solving their unit tests.
  4. My son is impatient and wants to solve problems quickly in his head. This works for simple operations but once you get to problems involving multiple steps like 12*17, you have to force him to use pencil and paper and show each step clearly to you.
  5. Since every child is different (and also rapidly changes with time), progress and tactics will be different. You have to constantly observe and adapt to the learning/teaching challenges you and your child will face.
  6. Persistence is key and the hardest part. It is easy to teach a couple of times, but most parents struggle to do it consistently.
How am I able to keep him marching on through this difficult journey? First, I have earned his respect and trust by being useful to him in subjects he cares about like video games, internet and sports. Second, I do not refrain from punishing him by reducing his video game time if he gets out of line.

Music: Chumbawamba - Tubthumping

Tuesday, March 05, 2019

Teaching English and mathematics to a six year old

My six year old son has learnt reading and writing which opened up a lot of opportunities. While thinking about how I could be more useful to him, I decided to try Duolingo for English teaching and Khan Academy for mathematics. Everyday at 18:30, I sit down with him and he first does Duolingo for 15 minutes, and then Khan Academy for another 15 minutes, for a total of half an hour a day. My role is to make sure that he really does the exercises and not play games or watch YouTube. I only help him when he gets stuck and requests my assistance.

Since both Duolingo and Khan Academy have curriculums that progress according to his level, I don't have to think about what to teach when. Khan Academy videos show me how to explain mathematical concepts to a child. Duolingo, besides training his English, also improves his reading and comprehension skills. Using the English version of Khan Academy also supports the language effort (of course, I have to translate math questions that have too many words in them to Turkish). The exercises show him the importance of paying attention to detail before jumping to conclusions, i.e. conscientiousness. Doing something every day is helpful in forming the most useful habit in life: persistence. And finally, he got rid of fearing failure and started to treat failure as a learning opportunity.

Friday, July 20, 2018

Solving the Monty Hall problem using Bayesian inference

The Monty Hall problem is one of my favorites. I came across How to solve the Monty Hall problem using Bayesian inference, which used my other favorite topic, Bayesian inference. My only criticism of the post is that P(E) is a little confusing. The following formulation with separate P(B*) and P(C*) notation suits me better:

P(B*) = Probability that Monty will open door B (given that the user has chosen door A) = 1/2

P(C*) = Probability that Monty will open door C (given that the user has chosen door A) = 1/2

P(C*/B) = Probability that Monty will open door C (given that the user has chosen door A and car is behind door B) = 1/1

P(C*/A) = Probability that Monty will open door C (given that the user has chosen door A and car is behind door A) = 1/2

P(B*/C) = Probability that Monty will open door B (given that the user has chosen door A and car is behind door C) = 1/1

P(A/B*) = Probability that the car is behind door A, given that Monty has opened door B = P(B*/A) * P(A) / P(B*) = 1/2 * 1/3 * 1/2 = 1/3

P(C/B*) = Probability that the car is behind door C, given that Monty has opened door B = P(B*/C) * P(C) / P(B*) = 1/1 * 1/3 * 1/2 = 2/3

P(A/C*) = Probability that the car is behind door A, given that Monty has opened door C = P(C*/A) * P(A) / P(C*) = 1/2 * 1/3 * 1/2 = 1/3

P(B/C*) = Probability that the car is behind door B, given that Monty has opened door C = P(C*/B) * P(B) / P(C*) = 1/1 * 1/3 * 1/2 = 2/3

As you can see, it is two times better to switch doors, i.e. if Monty has opened door B, switch to door C. If Monty has opened door C, switch to door B. Note that if Monty was truly random, then the probabilities of P(C*/B) and P(B*/C) would not be 1/1 but 1/2 which in turn would cause P(C/B*) and P(B/C*) to be 1/3 and switching doors would make no difference. The probabilities change due to Monty knowing where the car is, i.e. by opening a door, Monty adds non-random information (evidence) into the system and we have to update the initial probabilities which were valid before this information.

Interesting variation of this problem [Think Bayes, p.10]: What if Monty always chooses door B when B does not have a car behind?

Saturday, December 30, 2017

Practical application of the dot product

I recently had to write an algorithm to decide whether two trains (whose movement directions are known) are moving towards each other or not.

When two trains move towards each other the angle between their direction vectors is larger than 90 degrees. If the track was a straight line the angle would be close to 180 degrees, but tracks are not always straight.

I used the dot (scalar) product as follows:


  1. Calculate the dot product of the train direction vectors. This is equal to cos(angle).
  2. If 90 < angle <= 180 (-1 =< cos(angle) < 0), the two trains are moving towards each other
Note 1: If the track is bending more than 90 degrees, this algorithm will not work:
Note 2: If the trains have passed each other just using the dot product won't work, you also have to check whether the trains are in front of each other (let that be another blog post):

Monday, February 27, 2017

Probability: Difference between "exactly..." and "at least..."

In probability, I have to pay close attention to the problem statement because I easily make errors. As an example, let's say I toss a fair coin n times. What is the probability of
  1. Exacly 1 head
  2. At least 1 head
The figure below has n as the x axis and the two different probabilites as y axis. As you can see, the "exactly 1 head" probability decreases with n while the "at least 1 head" probability increases with n.

Matlab script for generating the plot:
n = 1:16;
pExactly1 = n./2.^n;
plot(n, pExactly1); grid on
hold on
pAtLeast1 = 1-(1-0.5).^n;
plot(n, pAtLeast1)
legend('exactly 1 heads', 'at least 1 heads')
xlabel('n'); ylabel('p')
Note that you can also get probability of at least 1 heads with this sum: pExactly1Head + pExactly2Heads + ... + pExactlyNHeads, where
pExactlyKHeads = nchoosek(n,k) * ph^k * (1-ph)^(n-k)
Even simpler: 1 - pExactly0Heads = 1 - nchoosek(n,0) * ph^0 * (1-ph)^(n-0).

For more information, visit Khan Academy.

Thursday, February 11, 2016

Finding the Intersection of Lines

The classical y = m*x+n line equation fails when finding intersections with vertical lines. Normally, the intersection point of two lines is found as follows:

Y = m1*x+n1 = m2*x+n2 --> x = (n2-n1)/(m1-m2)

Consider the following example, which clearly has an intersection at x = 1 and y = 0.5:

The classical equation for line AB results in m1 = infinity and n1 = -infinity, and for CD results in m2 = 0.5, n2 = 0. When you plug these values into x = (n2-n1)/(m1- m2), you get x = (0 - (-infinity)) / (infinity - 0.5) = infinity/infinity = NaN.

You could try to solve this problem using a bunch of if statements to check if a line is vertical, horizontal etc which would be prone to bugs. Or you could use parametric line equations:

Applying the above parametric formula to our example problem, we obtain the following equations:

Line1: P1 = A + (B - A) * t
Line2: P2 = C + (D - C) * u

To find the intersection point we equate P1 to P2:

A + (B - A) * t  = C + (D - C) * u.

Using scalar components:
Ax + (Bx-Ax)*t = Cx + (Dx-Cx)*u --> Ax-Cx = (Ax-Bx)*t + (Dx-Cx)*t
Ay + (By-Ay)*t = Cy + (Dy-Cy)*u --> Ay-Cy = (Ay-By)*t + (Dy-Cy)*t

Rearranging into matrix form:

| Ax-Bx, Dx-Cx | |t|  = |Ax-Cx|
| Ay-By, Dy-Cy | |u| = |Ay-Cy|

We can solve this M*TU = K system and obtain t and u values: TU = M^-1*K. t and u are -0.25 and 0.5 respectively. Finally to get intersection x,y coordinates, we can use

xIntersect = Ax + (Bx-Ax)*t
yIntersect = Ay + (By-Ay)*t

Which gives us the correct result of (1, 0.5)

An additional benefit of the parametric line equation is that it can easily be extended to three dimensional space. It is also used in calculating intersection lines with a planes.

Lesson learnt: Don't use y = m*x+n, instead use P = A + (B - A) * t

Thursday, August 01, 2013

Math tests

Java's java.lang.Math library provides methods for performing numeric operations. It's a good idea to have a basic test list to test the math functions of whichever programming language you are using at the moment. You should know about the behavior of math functions (in cases like overflow) so that you won't waste a lot of time looking for bugs in the wrong places.

Tuesday, April 03, 2012

Casual Mathematics

I like to solve casual math problems. For today's episode, inspiration came from Simulation as a Practical Tool. Below is the Maple 9 script I wrote to find the angle for shortest time. Note that the angle for minimum time is independent of rotational speed, omega.


Saturday, March 13, 2010

0.999... = 1

Rastgele wikipedia gezintim sırasında 0.999... yazısına denk geldim. Yazı 0.999... = 1'in ispatını sunuyor. Alın benden de bir ispat:

0.999... = x
10*0.999... = 9.999... = 10*x = 9 + x --> x = 1

Soru: Bir ampulü takmak için kaç matematikçi gerekir?
Cevap: 0.999...

Wednesday, December 02, 2009

Geometri Maceraları

Günlük işlerimde sık sık temel geometri ve fizik problemleri ile karşılaşırım. Zaman zaman basit sorularda kafam karışır ve tuhaf cevaplar bulurum. Buyrun bugünkü örneğimiz: Şekilde 13 birim yarıçapında 45 derecelik bir yay görülmektedir. Bu yayda 1 birim uzunlukta bir kirişin yataydan y uzaklığı nedir?


Sunday, September 27, 2009

Angular Motion and Inertia Tensor

Angular motion is a confusing subject for me. In todays white paper, I investigate Euler's equation of motion, correct a common mistake that I am prone to make (i.e. forgetting that the derivative of inertia tensor depends on the frame) and derive some additional conclusions related to the stability of angular velocity.


For the rest of the document see pdf (5 pages).

Saturday, September 19, 2009

How to Calculate Euler Angles

There are two ways to calculate Euler angles. You have to know their limitations to use them wisely in your programs. I forget that fact and rediscover it every couple of years, wasting time in the process. Let's write it down for easy reference (click here for pdf version):

Monday, September 07, 2009

Vector vs Scalar Expressions

Consider the well known Euler’s equations expressed in the body fixed frame:


In this vector form, there are a total of five operations (one derivative, two multiplications, one cross product and one addition)

If we choose to use scalar equations:


Here we have 30 multiplications, 21 subtractions and 3 additions, which add up to 54 operations. As you see, expressing equations in vector form yields 10 times less complication. It is easier to review, find errors and code vector equations. You only need code for vector/matrix multiplication, addition and cross products (they can be easily found on the internet).

Saturday, September 05, 2009

Vector derivative and reference frames

At least once a year I get confused when dealing with derivatives of vectors in different reference frames. I decided to do a derivation demonstrating the main points in an unambiguous fashion. Here it is: