{"id":49,"date":"2010-01-18T13:15:35","date_gmt":"2010-01-18T18:15:35","guid":{"rendered":"http:\/\/blogs.vassar.edu\/magnes\/?page_id=49"},"modified":"2012-01-16T11:48:16","modified_gmt":"2012-01-16T16:48:16","slug":"david-bridgman-packer","status":"publish","type":"page","link":"https:\/\/pages.vassar.edu\/magnes\/advanced-electromagnetism-phys-341\/david-bridgman-packer\/","title":{"rendered":"Modeling Dipoles"},"content":{"rendered":"<h2>Modeling Dipoles<\/h2>\n<p>By modeling dipoles on a large scale, we can observe the calculated bulk effects. The fluidity of a GUI program allows us to easily edit and rearrange the structure and positions of these dipoles. For my project I used Matlab to create a program that can input and graph dipoles in a variety of orientations and combinations.<\/p>\n<p>I used this project mainly as a way to learn some basic and intermediate GUI programming in Matlab. Given its heavy computational focus, Matlab has a lot of built-in features that help with coding projects such as this. For example, Matlab&#8217;s matrix manipulation goes beyond the typical array support of most programming languages. Additionally, the graphing tools already label the axes, calculate color maps, and have built-in tools for various types of plots.<\/p>\n<p>However, the high-end nature of the program (generally referred to as a four-generation programming language) does have several drawbacks. For example, its plotting mechanism does not have an straight-forward function for just plotting pixels to a canvas. This leaves the designer with a little less flexibility and a few more hoops to jump through. Matlab is very good at what it does, but its built-in functions a very rigid and lack flexibility.<\/p>\n<p>In this blog, I&#8217;m going to walk through my process of writing a Matlab GUI.<\/p>\n<h3>Assumptions<\/h3>\n<p>For modeling basic dipoles, I eschewed the inverse square relationship of the Coulomb and Biot-Savart laws in favor of the Gaussian function 1\/e^2. This function has the advantage of going to zero in the infinite limit while not growing arbitrarily large as it approaches zero. It therefore approximates the inverse square function while remaining bounded in the area of interest. Positive and negative charges are represented with positive and negative Gaussians. I also tried modeling charges using <a href=\"http:\/\/en.wikipedia.org\/wiki\/Lorentzian_function\">Lorentzian<\/a> functions, but found that their added complexity did not improve the model. Graphed in three dimensions, the field of the dipole appears as follows:<br \/>\n<img decoding=\"async\" src=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Picture%203.png\" alt=\"graph\" \/><br \/>\nUsing my program, which adds field lines, the basic dipole appears as follows:<\/p>\n<p style=\"text-align: left\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Picture%201.png\" alt=\"Dipole\" \/><br \/>\nWith blue representing positive charge, red representing negative charge, and the white lines showing the field lines of the dipole.<\/p>\n<h3>Modeling Bulk Effects<\/h3>\n<p style=\"text-align: left\">Once the basic dipole is modeled, more complicated structures can be formed by superimposing dipoles on the same plane. The most common magnet is the bar magnet, in which magnetic dipoles are aligned such that the overall field acts as if the magnet were itself a giant dipole:<br \/>\n<img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Picture%202.png\" alt=\"Bar Magnet\" \/><br \/>\nBy bending the bar magnet, we can make a horseshoe magnet. This type of magnet has the advantage of having the positive and negative poles both oriented in the same direction. Further bending the magnet will cause the two ends to face each other, creating a very strong field:<br \/>\n<img decoding=\"async\" src=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Picture%204.png\" alt=\"horseshoe magnet\" \/><\/p>\n<h3>The Program<\/h3>\n<p>It&#8217;s much more fun to play with programs than to hear about them, so here it is: <a href=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/MagnetModels.fig\">Part1<\/a>, <a href=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/MagnetModels.m\">Part 2<\/a>.<br \/>\nIn order to open the program, first open Matlab from Vapps. In the command line type &#8220;guide&#8221; and press enter. A window will pop up called &#8220;GUI quick start.&#8221; Go to the &#8220;Open Existing GUI&#8221; tab and browse to the MagnetModels.fig file. Open this. A form will pop up. Press the green play button in the toolbar and you&#8217;re good to go. Here&#8217;s a quick overview of all the possible inputs. More thorough descriptions of all the functions involved are commented into the code of the program.<\/p>\n<ul>\n<li>X coordinate and Y coordinate: These inputs set the position of the dipole. For bar and horseshoe magnets, this sets the center of the chain of dipoles.<\/li>\n<li>Intensity: This sets how strong the charges for a dipole are. Note that the intensities are normalized during the graphing process, so only relative intensities are shown in the color map.<\/li>\n<li>Distance: This sets the distance between the two ends of a dipole. Closer dipoles will have a stronger internal field and fewer fringe effects.<\/li>\n<li>Angle: This sets the overall angle of the dipole group. Input is in radians.<\/li>\n<li>Dipole Number: Determines the number of dipoles in either a bar or horseshoe magnet.<\/li>\n<li>Curve: Bends a bar magnet into a horseshoe magnet. The value determines the total angle covered by the horseshoe. Input is in radiants.<\/li>\n<\/ul>\n<p>If I had more time to work on this program and increase my skill set with Matlab, there are several more features that I would like to add. Firstly, I would like the user to be able to click on a point on the graph and draw a field line starting at this point. The easiest implementation of this feature would use the &#8220;ButtonDownFcn&#8221; function. However, I haven&#8217;t been able to get his feature to work yet. Additionally, I would like to animate a &#8220;test dipole&#8221; on the graph so that the user can see how the field affects nearby charges. Finally, I know that there are still a couple bugs, mostly in the initialization code, that cause the computer to beep but don&#8217;t disrupt the program. I haven&#8217;t been able to get to the bottom of these yet.<\/p>\n<p>On an unrelated note, this is <a href=\"http:\/\/www.nasa.gov\/mission_pages\/sdo\/news\/first-light.html\">our Sun<\/a>. What&#8217;s with that?<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.nasa.gov\/images\/content\/446667main1_sdo-fulldisk-670.jpg\" alt=\"The Sun\" width=\"304\" height=\"299\" \/><\/p>\n<h2>3\/29<\/h2>\n<p><a href=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/WaveAnimation.nb\">Wave Animation<\/a>.<\/p>\n<p>Also, a friend of mine showed me this today. As the article says, prepare for a nerdgasm.<br \/>\n<img decoding=\"async\" src=\"http:\/\/cache.gawkerassets.com\/assets\/images\/4\/2010\/03\/500x_436202main_pacmanmimas-full.jpg\" alt=\"Mimas\" \/><br \/>\n<a href=\"http:\/\/gizmodo.com\/5504749\/nasa-discovers-pac+man-on-death-star-saturn-moon\">Here&#8217;s the article.<\/a><\/p>\n<h2>3\/22<\/h2>\n<p>I have to admit that, among my homework, my notes, my worksheets, and my blog, my journal did not receive a high priority. Extra questions, doodles, and scandalous recounts of my love affair with charged particles generally found their way into my notebook. For example, here is a Harry Potter Jeopardy game that I wrote:<br \/>\n<img decoding=\"async\" src=\"http:\/\/imgur.com\/9Cd1Y.jpg\" alt=\"HP Jeopardy\" \/><br \/>\nHowever, in order to distract you from the ineptitude of my journalling, I&#8217;m going to teach you how to write programs using Matlab.<br \/>\n1) Open Matlab (available through vapps)<br \/>\n2) In the big input box where you generally enter commands, type &#8220;guide.&#8221; Create a new GUI.<br \/>\n3) This will open the GUI editor. Here you can place elements onto the program like axes (to plot graphs) buttons, labels, etc.<br \/>\n4) Once you have placed all the elements, go to File -&gt; Open M-editor. This will open the area where you can enter code. Each element has its own space. For example, under the header for each button, you can enter code that will be executed when the user presses the button.<br \/>\n5) From here on, the syntax is very similar to Visual Basic and C.<\/p>\n<p>Here are some lovely tutorials: <a href=\"http:\/\/blinkdagger.com\/matlab\/matlab-gui-graphical-user-interface-tutorial-for-beginners\/\">one<\/a> <a href=\"http:\/\/www.youtube.com\/watch?v=D_hmws6dwgg\">two<\/a>.<\/p>\n<p>There&#8217;s also a database of open source code snippets that are very helpful: <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/\"> MATLAB Central<\/a><\/p>\n<p>After you&#8217;ve finished mastering Matlab, try you hand at modeling one of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Universe\">these<\/a>.<\/p>\n<h2>3\/1<\/h2>\n<p>Project Proposal:<br \/>\nFor my project, I would like to model the magnetic field at the dipole level for dipoles of different strengths and separations. Using Visual Basic or another programming language, I would develop a program in which the user can choose the strength and separation of dipoles and then place them in a grid. The program would then calculate the magnetic field at each point in the grid and color it according to strength and direction. A test dipole could then be introduced, and a force and torque would be applied to it based on the field. The user could then watch the effects of the field on the test dipole. This program could be used to show how the alignment of microscopic dipoles creates the macroscopic field of a magnet.<\/p>\n<h2>2\/15<\/h2>\n<p><a href=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Dielectric_Snell.nb\">Snell&#8217;s Law for dialectrics<\/a>. This differs from Snell&#8217;s law for optics because there is no internal reflection. This is due to the fact that the limit as the arctangent function goes to infinity equals pi\/2. Therefore there can be no angle of refraction that exceeds that passes back into the first dialectric.<\/p>\n<p>Also, I spent two hours today playing <a href=\"http:\/\/www.playedonline.com\/game\/597681\/blosics-2.html\">this game<\/a>. You should too.<\/p>\n<h2>2\/8<\/h2>\n<p><a href=\"https:\/\/vspace.vassar.edu\/dabridgmanpacker\/Vector%20Field.nb\">Vector Field<\/a> superimposed on a sphere.<\/p>\n<p>Richard Feynman talks about how science can never fully answer the why question.\u00a0 He also tells you what magnets are.<\/p>\n<a href=\"http:\/\/www.youtube.com\/watch?v=wMFPe-DwULM\">http:\/\/www.youtube.com\/watch?v=wMFPe-DwULM<\/a>\n","protected":false},"excerpt":{"rendered":"<p>Modeling Dipoles By modeling dipoles on a large scale, we can observe the calculated bulk effects. The fluidity of a GUI program allows us to easily edit and rearrange the structure and positions of these dipoles. For my project I used Matlab to create a program that can input and graph dipoles in a variety [&hellip;]<\/p>\n","protected":false},"author":93,"featured_media":0,"parent":9,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-49","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/pages\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/users\/93"}],"replies":[{"embeddable":true,"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":26,"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/pages\/49\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/pages\/49\/revisions\/191"}],"up":[{"embeddable":true,"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/pages.vassar.edu\/magnes\/wp-json\/wp\/v2\/media?parent=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}