title: Implicit Euler for Mass Spring System
body: <p>I am currently working on implementing Implicit Euler on a Simulation software for a School project, and I have a hard time wrapping my head around implicit Euler formulas for a Mass Spring System and more specifically, the Jacobian Matrix computation and the final formula that needs to be solved.</p>
  
  <p>As I am new to stack overflow, I apologize beforehand if I posted this in the wrong section or if there are any errors.</p>
  
  <p>What I implemented so far produces weird results (Unrealistic simulations, explosions etc...).
  So if you guys could point out anything I didn't get right I would be immensely grateful.</p>
  
  <p>Here is what I think I understood :</p>
  
  <ul>
  <li><p>There are two Jacobian Matrices, one for the Spring Stretch Force and one for the Spring Damping, both following this structure <a href="https://imgur.com/a/Aydgd3n" rel="nofollow noreferrer">https://imgur.com/a/Aydgd3n</a> (With N the number of particles in the system)</p></li>
  <li><p>Each particle Jacobian is computed the following formulas :</p>
  
  <ul>
  <li>For the Stretch force Jacobian Matrix :</li>
  </ul></li>
  </ul>
  
  <p><code>δfi/δxj = ks⋅uij⋅uTij</code></p>
  
  <p><code>uTij</code> is the transpose of the vector <code>uij</code> (Sorry if the formulas are not very readable)</p>
  
  <p>(This is actually not the full formula found in the sources, but my teacher told me I could implement this one at first)</p>
  
  <ul>
  <li>For the Damping force Jacobian Matrix :</li>
  </ul>
  
  <p><code>δfi/δxj=kd⋅uij⋅uTij</code></p>
  
  <ul>
  <li><p><code>kd</code> and <code>ks</code> are respectively the damping and the stiffness of the spring.</p></li>
  <li><p>uij the vector between the two particles of the spring.</p></li>
  <li>As for the diagonals of both the matrices, I saw that it was the sum of all the particle jacobians connected to that particle so : 
  <code>δfi/δxi=∑jδfiδxj</code>, but I am really unsure about this one.
  Connected particles have <code>δfi/δxj=−δfj/δxi</code></li>
  </ul>
  
  <p>Here is an exemple of the weird explosions I talked about :
  <a href="https://imgur.com/a/gk1MkGJ" rel="nofollow noreferrer">https://imgur.com/a/gk1MkGJ</a></p>
  
  <p>And here are the sources I read if that could help: <a href="http://blog.mmacklin.com/2012/05/04/implicitsprings/" rel="nofollow noreferrer">http://blog.mmacklin.com/2012/05/04/implicitsprings/</a> <a href="http://hugi.scene.org/online/hugi28/hugi%2028%20-%20coding%20corner%20uttumuttu%20implementing%20the%20implicit%20euler%20method%20for%20mass-spring%20systems.htm" rel="nofollow noreferrer">http://hugi.scene.org/online/hugi28/hugi%2028%20-%20coding%20corner%20uttumuttu%20implementing%20the%20implicit%20euler%20method%20for%20mass-spring%20systems.htm</a></p>
  
  <p>Thank you for your time !</p>