{"id":4158,"date":"2024-12-08T16:28:18","date_gmt":"2024-12-08T22:28:18","guid":{"rendered":"https:\/\/laurentlessard.com\/bookproofs\/?p=4158"},"modified":"2024-12-08T17:05:35","modified_gmt":"2024-12-08T23:05:35","slug":"particles-in-a-box","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/particles-in-a-box\/","title":{"rendered":"Particles in a box"},"content":{"rendered":"<p>This week&#8217;s <a href=\"https:\/\/thefiddler.substack.com\/p\/can-you-squeeze-the-particles-into\">Fiddler<\/a> is an optimization problem about fitting particles in a box.<\/p>\n<blockquote><p>\nYou have three particles inside a unit square that all repel one another. The energy between each pair of particles is $1\/r$, where $r$ is the distance between them. To be clear, the particles can be anywhere inside the square or on its perimeter. The total energy of the system is the sum of the pairwise energies among the particles. What is the minimum energy for $9$ particles, and what arrangement of the particles produces it?\n<\/p><\/blockquote>\n<p>My solution:<br \/>\n<a href=\"javascript:Solution('soln_particlesinabox','toggle_particlesinabox')\" id=\"toggle_particlesinabox\">[Show Solution]<\/a><\/p>\n<div id=\"soln_particlesinabox\" style=\"display: none\">\n<p>This is a pure optimization problem. We will center our unit square at the origin, so the particles are located at $(x_i,y_i)$, with $-\\tfrac{1}{2}\\leq x_i\\leq \\tfrac{1}{2}$ and $-\\tfrac{1}{2}\\leq y_i\\leq \\tfrac{1}{2}$. Our optimization problem is rather simple to state:<br \/>\n\\begin{align*}<br \/>\n\\underset{x,y}{\\text{minimize}}\\qquad &#038; \\sum_{1\\leq i \\lt j \\leq n} \\frac{1}{\\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}} \\\\<br \/>\n\\text{subject to:}\\qquad &#038; -\\tfrac{1}{2}\\leq x_i\\leq \\tfrac{1}{2} \\quad i=1,\\dots,n\\\\<br \/>\n&#038;  -\\tfrac{1}{2}\\leq y_i\\leq \\tfrac{1}{2} \\quad i=1,\\dots,n<br \/>\n\\end{align*}Taking a numerical approach, I used a local gradient-based solver in Mathematica with randomized initial conditions, solved 50 times, and took the best solution found. I solved the problem for $n=2,\\dots,17$ and here were the best solutions found:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1.png\" alt=\"\" width=\"790\" height=\"791\" class=\"aligncenter size-full wp-image-4162\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1.png 790w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1-300x300.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1-150x150.png 150w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles1-768x769.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p>Here is a plot of the optimal cost as the number of particles grows:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles3.png\" alt=\"\" width=\"495\" height=\"310\" class=\"aligncenter size-full wp-image-4165\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles3.png 495w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles3-300x188.png 300w\" sizes=\"auto, (max-width: 495px) 85vw, 495px\" \/><\/a><\/p>\n<h3>The case $n=9$<\/h3>\n<p>For the case $n=9$, interestingly, the optimal solution is <em>not<\/em> to place the points in a regular $3\\times 3$ grid. Using an irregular arrangement can produce a slightly lower cost, as shown in the figure below.<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles2.png\" alt=\"\" width=\"804\" height=\"348\" class=\"aligncenter size-full wp-image-4161\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles2.png 804w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles2-300x130.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2024\/12\/particles2-768x332.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p>The optimal arrangement for $9$ particles shown above has the particles at coordinates:<br \/>\n\\[<br \/>\n\\left(<br \/>\n\\begin{array}{cc}<br \/>\n -0.5 &#038; 0.5 \\\\<br \/>\n 0.5 &#038; 0.5 \\\\<br \/>\n 0.5 &#038; -0.5 \\\\<br \/>\n -0.5 &#038; -0.5 \\\\<br \/>\n 0. &#038; 0.5 \\\\<br \/>\n 0.5 &#038; 0.0469081 \\\\<br \/>\n -0.5 &#038; 0.0469081 \\\\<br \/>\n 0.181044 &#038; -0.5 \\\\<br \/>\n -0.181044 &#038; -0.5 \\\\<br \/>\n\\end{array}<br \/>\n\\right)<br \/>\n\\]<\/p>\n<p><strong>Side note:<\/strong> If we change the energy function to $1\/r^2$, then the optimal arrangement does become the regular $3\\times 3$ grid.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week&#8217;s Fiddler is an optimization problem about fitting particles in a box. You have three particles inside a unit square that all repel one another. The energy between each pair of particles is $1\/r$, where $r$ is the distance between them. To be clear, the particles can be anywhere inside the square or on &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/particles-in-a-box\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Particles in a box&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4162,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[42],"tags":[43,10,26],"class_list":["post-4158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-fiddler","tag-fiddler","tag-geometry","tag-optimization"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/4158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/comments?post=4158"}],"version-history":[{"count":6,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/4158\/revisions"}],"predecessor-version":[{"id":4167,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/4158\/revisions\/4167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media\/4162"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=4158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=4158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=4158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}