Skip to content

Instantly share code, notes, and snippets.

@Per48edjes
Last active May 25, 2024 00:53
Show Gist options
  • Save Per48edjes/b83ab3d1c6f05431b8cf73007efb0ab3 to your computer and use it in GitHub Desktop.
Save Per48edjes/b83ab3d1c6f05431b8cf73007efb0ab3 to your computer and use it in GitHub Desktop.
Fiddler on the Proof: Fiddler (05/17/2024)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "6479454d-d434-4808-a73d-01255eed4844",
"metadata": {},
"source": [
"# Fiddler on the Proof\n",
"\n",
"Ravi Dayabhai ⭕️ 2024-05-17"
]
},
{
"cell_type": "markdown",
"id": "52b23e3c-c3d9-4a10-87b0-8f3910e19419",
"metadata": {},
"source": [
"## Problem\n",
"\n",
"One of my favorite facts about circles is the relationship between their area and their circumference. For a circle with radius r, its area is 𝜋r2 and its circumference is 2𝜋r. What’s neat here (or rather, one thing that’s neat here) is that if you take the derivative of the area formula with respect to r, you get the circumference formula! In other words, d(𝜋r2)/dr = 2𝜋r. Amazing, right?\n",
"\n",
"(For those of you who are accustomed to using tau rather than pi, this still works. The area of a circle is 𝜏r2/2 and its circumference is 𝜏r. Once again, d(𝜏r2/2)/dr = 𝜏r.)\n",
"\n",
"Inspired by this fact, let’s define the term “differential radius.” The differential radius r of a shape with area A and perimeter P (both functions of r) has the property that dA/dr = P. (Note that A always scales with r2 and P always scales with r.)\n",
"\n",
"For example, consider a square with side length s. Its differential radius is r = s/2. The square’s area is s2, or 4r2, and its perimeter is 4s, or 8r. Sure enough, dA/dr = d(4r2)/dr = 8r = P.\n",
"\n",
"What is the differential radius of an equilateral triangle with side length s?"
]
},
{
"cell_type": "markdown",
"id": "eaa13279-6073-4c6d-8fa7-e57145e55b49",
"metadata": {},
"source": [
"## Solution\n",
"\n",
"The differential radius $r$ can be expressed in terms of the side length $s$:\n",
"\n",
"$$\n",
"r = \\frac{s}{2\\sqrt{3}} = \\frac{s\\sqrt{3}}{6}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "75277d57-d547-41e9-9813-88d90e03dc12",
"metadata": {},
"source": [
"### Rationale"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "46ada9f7-484c-4438-b910-e07754fb8b32",
"metadata": {},
"outputs": [],
"source": [
"import sympy as sp"
]
},
{
"cell_type": "markdown",
"id": "439fc2a9-c650-4221-8daa-76971ee8b927",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"We can express the perimeter $P$ and the area $A$ of an equilateral triangle in terms of its side length, which itself is a function of the differential radius $r$, thus $s(r)$:\n",
"\n",
"$$\n",
"\\begin{align}\n",
"P &= 3s(r), \\\\\n",
"A &= \\frac{1}{2} \\cdot s(r) \\cdot s(r) \\sin{\\frac{\\pi}{3}}\\\\\n",
" &= \\frac{s(r)^{2}\\sqrt{3}}{4}\n",
"\\end{align}\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9ea32f24-e0a3-4a86-a8ce-c5086b417d06",
"metadata": {},
"outputs": [],
"source": [
"r = sp.Symbol('r', positive=True, real=True)\n",
"s = sp.Function('s')(r)"
]
},
{
"cell_type": "markdown",
"id": "d2a18c6f-649f-475e-a74e-18f53126cd1b",
"metadata": {},
"source": [
"Then we can solve the ordinary differential equation:\n",
"\n",
"$$\n",
"\\begin{align}\n",
"P &= \\frac{dA}{dr}\\\\\n",
"3s(r) &= \\frac{\\sqrt{3}}{4} \\cdot \\frac{d}{dr} s(r)^{2}\\\\\n",
"0 &= \\frac{\\sqrt{3}}{4} \\cdot \\frac{d}{dr}s(r)^{2} - 3s(r) \\\\\n",
"\\end{align}\n",
"$$\n",
"\n",
"with initial condition $s(0) = 0$ since if the differential radius is $0$, so too must the side length be $0$."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c20d9807-aeb7-436d-99a7-2a9d801f27e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"s(r) = 2⋅√3⋅r\n"
]
}
],
"source": [
"eq = sp.Eq(3 * s, sp.Derivative((s ** 2) * sp.sqrt(3) / 4, r))\n",
"initial_condition = {s.subs(r, 0): 0}\n",
"\n",
"solution = sp.dsolve(eq, ics=initial_condition)\n",
"\n",
"sp.pprint(solution)"
]
},
{
"cell_type": "markdown",
"id": "1d0ebc98-1ec5-47e9-97d8-6c3ba1747bf2",
"metadata": {},
"source": [
"Rearranging gives the answer:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "931cda9d-71c1-4476-8902-71512c22586e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⎡√3⋅s⎤\n",
"⎢────⎥\n",
"⎣ 6 ⎦\n"
]
}
],
"source": [
"s, r = sp.symbols('s r', positive=True, real=True)\n",
"solution_eq = sp.Eq(s, 2*sp.sqrt(3)*r)\n",
"r_in_terms_of_s = sp.solve(solution_eq, r)\n",
"\n",
"sp.pprint(r_in_terms_of_s)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment