{"id":3677,"date":"2011-07-01T00:30:44","date_gmt":"2011-06-30T23:30:44","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=3677"},"modified":"2011-07-01T00:30:44","modified_gmt":"2011-06-30T23:30:44","slug":"pendulum-waves-animation-in-matlab","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=3677","title":{"rendered":"Pendulum Waves Animation in MATLAB"},"content":{"rendered":"<p>The <a href=\"http:\/\/www.youtube.com\/watch?v=yVkdfJ9PkRQ&amp;feature=related\">Pendulum Waves<\/a> video is awesome and the system has been <a href=\"http:\/\/playingwithmathematica.com\/2011\/05\/20\/friday-fun-2\/\">simulated in Mathematica<\/a> (<a href=\"http:\/\/demonstrations.wolfram.com\/PendulumWaves\/\">twice<\/a>), <a href=\"http:\/\/www.mapleprimes.com\/maplesoftblog\/121168-Pendulum-Waves\">Maple<\/a> and probably every other programming language by now.\u00a0 During a bout of insomnia I used the <a href=\"http:\/\/playingwithmathematica.com\/2011\/05\/20\/friday-fun-2\/\">Mathematica code written by Matt Henderson<\/a> as inspiration and made a simple MATLAB version.\u00a0 Here&#8217;s the video<\/p>\n<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"425\" height=\"349\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/HNOEqSWKwzI?version=3&amp;hl=en_GB\" \/><param name=\"allowfullscreen\" value=\"true\" \/><\/object><\/p>\n<p>Here&#8217;s the code.<\/p>\n<pre>freqs  = 5:15;\r\nnum = numel(freqs);\r\nlengths = 1.\/sqrt(freqs);\r\npiover6 = pi\/6;\r\n\r\nfigure\r\naxis([-0.3 0.3 -0.5 0]);\r\naxis off;\r\norg=zeros(size(freqs));\r\nxpos=zeros(size(freqs));\r\nypos=zeros(size(freqs));\r\npendula =  line([org;org],[org;org],'LineWidth',1,'Marker','.','MarkerSize',25 ...\r\n                ,'Color',[0 0 0],'visible','off' );\r\n\r\n% Open the avi file\r\nvidObj = VideoWriter('pendula_wave.avi');\r\nopen(vidObj);\r\n\r\ncount =0;\r\nfor t=0:0.001:1\r\n    count=count+1;\r\nomegas = 2*pi*freqs*t;\r\nxpos = sin(piover6*cos(omegas)).*lengths;\r\nypos = -cos(piover6*cos(omegas)).*lengths;\r\n\r\n for i=1:num\r\n set(pendula(i),'visible','on');\r\n set(pendula(i),'XData',[0 xpos(i)]);\r\n set(pendula(i),'YData',[0 ypos(i)]);\r\n drawnow\r\n end\r\n currFrame = getframe;\r\n writeVideo(vidObj,currFrame)\r\n\r\n F(i) = getframe;\r\nend\r\n\r\n% Close the file.\r\nclose(vidObj);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Pendulum Waves video is awesome and the system has been simulated in Mathematica (twice), Maple and probably every other programming language by now.\u00a0 During a bout of insomnia I used the Mathematica code written by Matt Henderson as inspiration and made a simple MATLAB version.\u00a0 Here&#8217;s the video Here&#8217;s the code. freqs = 5:15; [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[45,4,11,19],"tags":[],"class_list":["post-3677","post","type-post","status-publish","format-standard","hentry","category-just-for-fun","category-math-software","category-matlab","category-physics"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-Xj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/3677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3677"}],"version-history":[{"count":4,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/3677\/revisions"}],"predecessor-version":[{"id":3681,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/3677\/revisions\/3681"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}