{"id":777,"date":"2019-11-26T23:55:07","date_gmt":"2019-11-26T21:55:07","guid":{"rendered":"http:\/\/www.joanillo.org\/?p=777"},"modified":"2020-10-05T23:56:03","modified_gmt":"2020-10-05T21:56:03","slug":"libro-elementary-mechanics-using-python","status":"publish","type":"post","link":"https:\/\/www.joanillo.org\/?p=777&lang=es","title":{"rendered":"Libro: Elementary Mechanics Using Python"},"content":{"rendered":"<p><a href=\"http:\/\/www.joanillo.org\/wp-content\/uploads\/2019\/11\/objecte_penjat_molla.png\"><img loading=\"lazy\" src=\"http:\/\/www.joanillo.org\/wp-content\/uploads\/2019\/11\/objecte_penjat_molla-300x235.png\" alt=\"\" title=\"objecte_penjat_molla\" width=\"300\" height=\"235\" class=\"alignright size-medium wp-image-2092\"><\/a>Tengo un nuevo reto para lo que queda de 2019 y para el primer semestre del 2020. He empezado a leer el libro <em><strong>Elementary Mechanics Using Python: A Modern Course Combining Analytical and Numerical Techniques<\/strong><\/em>, de <em>Anders Malthe-S\u00f8renssen<\/em>. Es todo un curso de f\u00edsica, y combina de manera comprensible los ejemplos cl\u00e1sicos de movimiento, fuerzas, energ\u00eda,&#8230; con sus soluciones num\u00e9ricas, utilizando las libreri\u00edas matem\u00e1ticas y de gr\u00e1ficos de Python.<\/p>\n<p>Se trata de implementar todos los ejemplos del libro a c\u00f3digo Python. No he visto ning\u00fan enlace para descargar todo el c\u00f3digo, en cualquier caso, los ejemplos quiero adaptarlos y hac\u00e9rmelos m\u00edos. He empezado por el ejemplo  del peso suspendido de un muelle, que como todo el mundo sabe la soluci\u00f3n del movimiento es sinusoidal entorno al punto de equilibrio, la velocidad es cero en los puntos m\u00e1ximo y m\u00ednimo, y la velocidad es m\u00e1xima en el punto de equilibrio. Este ejemplo se explica en el apartado 5.7, que habla de fuerzas, y no basta con copiar y pegar el c\u00f3digo, sino que lo he tenido que adaptar. Esta es mi soluci\u00f3n:<\/p>\n<blockquote><p>\n# -*- coding: utf-8 -*-<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport numpy as np<\/p>\n<p># Initialize<br \/>\nm = 1.0<br \/>\n# kg<br \/>\nk = 100.0 # N\/m<br \/>\nv0 = 1.0<br \/>\n# in m\/s<br \/>\ntime = 2.0 # s<br \/>\ng = 9.8 # m\/s^2<\/p>\n<p># Numerical setup<br \/>\ndt = 0.0001 # s<br \/>\nn = int(round(time\/dt))<br \/>\nt = np.zeros(n,float)<br \/>\ny = np.zeros(n,float)<br \/>\nv = np.zeros(n,float)<br \/>\n# Initial values<br \/>\ny[0] = 0.0<br \/>\nv[0] = v0<br \/>\n# Simulation loop<br \/>\nfor i in range(n-1):<br \/>\n\\tF = -k*y[i] &#8211; m*g<br \/>\n\\ta = F\/m<br \/>\n\\tv[i+1] = v[i] + a*dt<br \/>\n\\ty[i+1] = y[i] + v[i+1]*dt<br \/>\n\\tt[i+1] = t[i] + dt<\/p>\n<p>fig = plt.figure()<br \/>\nfig.suptitle(u&#8221;Objecte susp\u00e8s d&#8217;una molla&#8221;)<br \/>\nplot1 = fig.add_subplot(211)<br \/>\n#plot1.set_xlabel(&#8216;t [s]&#8217;)<br \/>\nplot1.set_ylabel(&#8216;y [m]&#8217;)<br \/>\nplot1.xaxis.grid()<br \/>\nplot1.plot(t,y)<br \/>\nplot2 = fig.add_subplot(212)<br \/>\nplot2.set_xlabel(&#8216;t [s]&#8217;)<br \/>\nplot2.set_ylabel(&#8216;v [m\/s]&#8217;)<br \/>\n#plot1.grid(axis=&#8217;y&#8217;)<br \/>\n#plt.grid(b=True, which=&#8217;minor&#8217;, color=&#8217;#666666&#8242;, linestyle=&#8217;-&#8216;)<br \/>\nplot2.xaxis.grid()<br \/>\nplot2.plot(t,v)<\/p>\n<p>for i in range(10, n-1, 400):<br \/>\n\\tplot1.plot(t[i],y[i],&#8217;ob&#8217;)<br \/>\n\\tplot2.plot(t[i],v[i],&#8217;ob&#8217;)<\/p>\n<p>plt.show()<\/p><\/blockquote>\n<p>Estos son los cap\u00edtulos y temas que se tratan en el libro:<\/p>\n<blockquote><p>\n4. Motion in One Dimension .<br \/>\n5. Forces in One Dimension .<br \/>\n6. Motion in Two and Three Dimensions<br \/>\n7. Forces in Two and Three Dimensions<br \/>\n8. Constrained Motion<br \/>\n9. Forces and Constrained Motion<br \/>\n10. Work<br \/>\n11. Energy<br \/>\n12. Momentum, Impulse, and Collisions<br \/>\n13. Multiparticle Systems<br \/>\n14. Rotational Motion<br \/>\n15. Rotation of Rigid Bodies<br \/>\n16. Dynamics of Rigid Bodies<\/p><\/blockquote>\n<ul>\n<li>El libro en <a href=\"https:\/\/www.amazon.es\/Elementary-Mechanics-Using-Python-Undergraduate\/dp\/3319195956\" alt=\"Elementary Mechanics Using Python\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Tengo un nuevo reto para lo que queda de 2019 y para el primer semestre del 2020. He empezado a leer el libro Elementary Mechanics Using Python: A Modern Course Combining Analytical and Numerical Techniques, de Anders Malthe-S\u00f8renssen. Es todo un curso de f\u00edsica, y combina de manera comprensible los ejemplos cl\u00e1sicos de movimiento, fuerzas, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[308,324,192,346],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/777"}],"collection":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=777"}],"version-history":[{"count":1,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions"}],"predecessor-version":[{"id":778,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions\/778"}],"wp:attachment":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}