{"id":188,"date":"2017-02-19T03:12:05","date_gmt":"2017-02-19T03:12:05","guid":{"rendered":"http:\/\/www.maxwellmckinnon.com\/blog\/?p=188"},"modified":"2022-03-05T20:34:33","modified_gmt":"2022-03-05T20:34:33","slug":"fun-with-waves-in-matlab-wave-equation-modeling","status":"publish","type":"post","link":"http:\/\/maxwellmckinnon.com\/blog\/2017\/02\/19\/fun-with-waves-in-matlab-wave-equation-modeling\/","title":{"rendered":"Fun with Waves in Matlab &#8211; Wave Equation Modeling"},"content":{"rendered":"<div class=\"\" data-block=\"true\" data-editor=\"26fo8\" data-offset-key=\"fqgj-0-0\">\n<h1 class=\"_1mf _1mj\" data-offset-key=\"fqgj-0-0\">Setup<\/h1>\n<div class=\"_1mf _1mj\" data-offset-key=\"fqgj-0-0\"><span data-offset-key=\"fqgj-0-0\">Matlab is cool. Math is cool. Enough said.<br \/>\n<\/span><\/div>\n<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">Amazing how all this beauty is held inside such a seemingly simple formula, the wave equation.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><img decoding=\"async\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/75a9ffe02fba001388931079b7bab7c9e4dea451\" alt=\"{ \\partial^2 u \\over \\partial t^2 } = c^2 \\nabla^2 u \"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">This is the basics of the setup.&nbsp;It is a rectangular pool that can simulate perturbations based on the above wave equation. The model implements finite differences for its solution on the 2D mesh. e.g. (f_x = (f_i &#8211; f_[i-1]) \/ da)<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><a href=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-191\" src=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM.jpg\" width=\"600\" height=\"303\" srcset=\"http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM.jpg 875w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM-300x152.jpg 300w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM-768x388.jpg 768w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM-800x404.jpg 800w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065105_PM-356x180.jpg 356w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<h1 class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">Details of Model<\/h1>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">The inner oscillations are a result of model error. I wasn&#8217;t sure if this error was from the size of the impulse or the size of the mesh.&nbsp;The variables needed to be isolated. I doubled the size of the mesh points in each direction. To keep the impulse size the same, the input was now a 2&#215;2 impulse instead of a 1&#215;1. As seen, the&nbsp;inner oscillations have a higher frequency compared to before. This means the model error of inner oscillation frequency is dependent on the mesh size.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><a href=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-190\" src=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM.jpg\" width=\"600\" height=\"297\" srcset=\"http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM.jpg 875w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM-300x148.jpg 300w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM-768x380.jpg 768w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM-800x396.jpg 800w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065009_PM-364x180.jpg 364w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">I wondered what happens in real life when something gets dropped into a big bowl of water. It turns out that there is one big oscillation followed by medium sized ripples. Running the simulation with a bigger impulse and a very fine mesh, I obtain similar results. As shown, you can see one big oscillation followed by medium-sized ripples.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">In addition to the medium-sized ripples, you can still see little oscillations of high frequency. As shown previously, these depend on the step size.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">In real life, there are a discrete number of water molecules to move up and down. There aren&#8217;t infinitely many points in the mesh.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><em>Maybe these frequencies that depend on the step size show up in real life too. Or maybe not.<\/em><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><a href=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-192\" src=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM.jpg\" width=\"600\" height=\"297\" srcset=\"http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM.jpg 875w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM-300x148.jpg 300w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM-768x380.jpg 768w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM-800x396.jpg 800w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_065928_PM-364x180.jpg 364w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<h1 class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">Boundary Value Manipulation<\/h1>\n<p>Any Dirichlet boundary conditions* can be imposed by reassigning the boundary to its fixed value after every iteration. I wanted to see what happened on the shape of a guitar. It is interesting how there is sort of a mirror of the source in the front of the guitar. There was only one impulse applied to this shape, even though it looks like there is a smaller impulse on the top of the guitar.<\/p>\n<p><a href=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-195\" src=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM.jpg\" width=\"600\" height=\"262\" srcset=\"http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM.jpg 975w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM-300x131.jpg 300w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM-768x335.jpg 768w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM-800x349.jpg 800w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_Clipping_021817_071311_PM-400x174.jpg 400w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">*A Dirichlet boundary condition is a fancy word for a boundary that doesn&#8217;t move, like a wall that has a jump rope tied to it &#8211; or a guitar bridge with guitar strings tied to it.<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<h1 class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">Fun Experiment DOUBLE SLIT!! xD<\/h1>\n<p>Applying more Dirichlet boundary values to form two slits for waves to come out. Look at that beautiful diffraction pattern!! (:<\/p>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">&nbsp;<a href=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-196\" src=\"http:\/\/www.maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-1024x503.jpg\" width=\"600\" height=\"295\" srcset=\"http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-1024x503.jpg 1024w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-300x147.jpg 300w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-768x378.jpg 768w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-800x393.jpg 800w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM-366x180.jpg 366w, http:\/\/maxwellmckinnon.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled_021817_071537_PM.jpg 1674w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\"><\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">Until next time<\/div>\n<div class=\"_1mf _1mj\" data-offset-key=\"1c1np-0-0\">\u2208<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Setup Matlab is cool. Math is cool. Enough said. Amazing how all this beauty is held inside such a seemingly simple formula, the wave equation. This is the basics of the setup.&nbsp;It is a rectangular pool that can simulate perturbations based on the above wave equation. The model implements finite differences for its solution on&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-dev"],"_links":{"self":[{"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":5,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":203,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions\/203"}],"wp:attachment":[{"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/maxwellmckinnon.com\/blog\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}