{"id":240,"date":"2012-09-01T11:24:39","date_gmt":"2012-09-01T17:24:39","guid":{"rendered":"http:\/\/www.ghyzmo.com\/?p=240"},"modified":"2012-09-22T21:15:28","modified_gmt":"2012-09-23T03:15:28","slug":"grokking-glileos-physics-iii-python-code","status":"publish","type":"post","link":"http:\/\/www.ghyzmo.com\/grokking-glileos-physics-iii-python-code\/","title":{"rendered":"Grokking Glileo's Physics III --Python Code"},"content":{"rendered":"<p><em>\u00a9Fernando Caracena 31 August 2012<\/em><\/p>\n<h2><em>Python genrated figures<\/em><\/h2>\n<p>The figures used in the previous session were generated using an interactive version of python (<a title=\"Ipython documentation\" href=\"http:\/\/ipython.org\/documentation.html\">ipython<\/a>). For those familiar with, or learning the language, the following snippets of code are provided for generating each figure.<\/p>\n<p><a href=\"http:\/\/www.ghyzmo.com\/grokking-galileos-physics-part-ii\/acclvstime\/\" rel=\"attachment wp-att-222\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft  wp-image-222\" title=\"AcclVsTime\" src=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/AcclVsTime.png\" alt=\"Acceleration versus Time\" width=\"279\" height=\"211\" srcset=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/AcclVsTime.png 812w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/AcclVsTime-150x113.png 150w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/AcclVsTime-300x226.png 300w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/a><\/p>\n<p>ipython --pylab<br \/>\nfrom pylab import *<br \/>\nfrom matplotlib.font_manager import FontProperties<br \/>\nfrom matplotlib.backends.backend_agg import RendererAgg<\/p>\n<p>figure()<br \/>\n#--------------------------------------------<br \/>\na=0.5<br \/>\nx=arange(0,0.5, 0.01)<br \/>\ny=0.*x+a<br \/>\nx=concatenate((x,x[::-1]))<br \/>\ny=concatenate((0*y,y[::-1]))<br \/>\np=fill(x, y, facecolor='g')<br \/>\nx1=[0,1]<br \/>\ny1=[1,1]<br \/>\ny2=[0.0,0.0]<br \/>\nplot(x1,y1, x1, y2, color='k')<br \/>\ntext(0.501,0.5,r'a')<br \/>\nxlabel('Time', color='k')<br \/>\nylabel('Acceleration', color='k')<br \/>\ntitle(\"Acceleration vs. time\", color='k')<\/p>\n<p>#---------------------------------------------------------------------------<\/p>\n<p># N.B. that the lead character comments out the whole line.<\/p>\n<p><a href=\"http:\/\/www.ghyzmo.com\/grokking-galileos-physics-part-ii\/velvstime\/\" rel=\"attachment wp-att-225\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft  wp-image-225\" title=\"VelVsTime\" src=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/VelVsTime.png\" alt=\"Velocity versus time\" width=\"240\" height=\"180\" srcset=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/VelVsTime.png 812w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/VelVsTime-150x113.png 150w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/VelVsTime-300x226.png 300w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a>figure()<\/p>\n<p>t=arange(0,0.51, 0.01)<br \/>\nv=a*t<br \/>\nt=concatenate((t,t[::-1]))<br \/>\nv=concatenate((0*v,v[::-1]))<br \/>\np=fill(t, v, facecolor='g')<br \/>\nxlabel('Time', color='k')<br \/>\nylabel('Velocity', color='k')<br \/>\ntitle(\"Velocity vs. time\", color='k')<\/p>\n<p>#-----------------------------------------------------------------------------------------------<\/p>\n<p>figure() #Generates a new active window, in which is plotted a new figure.<\/p>\n<div id=\"attachment_226\" style=\"width: 329px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.ghyzmo.com\/grokking-galileos-physics-part-ii\/distvstime\/\" rel=\"attachment wp-att-226\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-226\" class=\" wp-image-226\" title=\"DistVsTime\" src=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/DistVsTime.png\" alt=\"\" width=\"319\" height=\"240\" srcset=\"http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/DistVsTime.png 812w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/DistVsTime-150x113.png 150w, http:\/\/www.ghyzmo.com\/wp-content\/uploads\/2012\/08\/DistVsTime-300x226.png 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/a><p id=\"caption-attachment-226\" class=\"wp-caption-text\">Distance versus time<\/p><\/div>\n<p>t=arange(0,0.51, 0.01)<br \/>\ny=0.5*a*t*t<br \/>\nt=concatenate((t,t[::-1]))<br \/>\ny=concatenate((0*y,y[::-1]))<br \/>\np=fill(t, y, facecolor='g')<br \/>\nt1=[0,1]<br \/>\ny1=[0.06,0.06]<br \/>\ny2=[0.0,0.0]<br \/>\n# plot(x1,y1, x1, y2, color='w')<br \/>\nxlabel('Time', color='k')<br \/>\nylabel('Distance', color='k')<br \/>\ntitle(\"Distance vs. time\", color='k')<\/p>\n<p>#--------------END--------------------------------------------------------------------------------------<\/p>\n<h2><em>About python<\/em><\/h2>\n<p>Python is a good scripting language, sometimes used by web developers, which through its various add-on graphics libraries becomes a powerful graphics tool. Although it is interpreted, rather than compiled, it runs fast on the modern desktop and laptop.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a9Fernando Caracena 31 August 2012 Python genrated figures The figures used in the previous session were generated using an interactive version of python (ipython). For those familiar with, or learning the language, the following snippets of code are provided for &hellip; <a href=\"http:\/\/www.ghyzmo.com\/grokking-glileos-physics-iii-python-code\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,10,12,43,42],"tags":[80,44],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry","category-frame-of-reference","category-mathematics","category-physics","category-programming","category-python","tag-physics","tag-python-programming"],"_links":{"self":[{"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":7,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":400,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/posts\/240\/revisions\/400"}],"wp:attachment":[{"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ghyzmo.com\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}