# Author: Bala Krishna Juluri

# Parallelization in Octave using parcellfun/pararrayfun

My computer has many processors and I would like to run some octave scripts so that all the processors are being used. One can use octave function called “pararrayfun” for this purpose. This function is part of “general” package on octave-forge. On my ubuntu 11.10, I used “sudo apt-get install octave-general” to install this package and ran the following script 1; # this is kept to Prevent Octave from thinking that this is a function file: close all; clear all; function y=test(a,b) y=sin(a)+cos(b) endfunction num_process=8 a_test_inputs=[0:3.14/20:3.14]; b_test_inputs=[0:3.14/20:3.14]*2; tic (); tt_par= pararrayfun(num_process,@test,(a_test_inputs),(b_test_inputs)); parallel_elapsed_time = toc () tic (); tt_ser= test((a_test_inputs),(b_test_inputs)); serial_elapsed_time Read More …

# Spaces in strings in matlab/octave

To get spaces in the strings to work in matlab or octave, use t1={‘test test’} Result is t1 = { [1,1] = test test } t2=strcat({‘test test ‘},{‘blah blah’}) Result is t2 = { [1,1] = test test blah blah } you can use this string in your figures by plot([1:4]) title(t2{})

# van der Pauw correction factor

The van der Pauw Method is a technique commonly used to measure the Resistivity and the Hall Coefficient of a sample. A correction factor goes into calculating the resistivity as described in van der Pauw paper. A iterative method is generally used to calculate the correction factor and this correction factor is plotted in Figure 5 of van der Pauw paper I reproduced the same figure below using fsolve function in octave. This figure was produced by the octave code shown below. The raw data is here. %This octave/matlab code calculates the correction factor,f as a function of Rmnop/Rnopm. This Read More …

# Surface plasmon dispersion relation for thin metal films

A thin metal film in dielectric (also known as dielectric-metal-dielectric configuration) can support surface plasmons that are different in nature to the ones observed in thick metal-dielectric interfaces. Unlike, a single mode that is observed in thick metal film, thin metal films exhibit two types of modes for the same wavevector due to excitation and interaction of surface plasmons on both sides of the film. One mode (L+) is at higher energy and other (L-) is at a lower energy. The high energy has anti-symmetric field distribution whereas the low energy one has symmetric field distribution. The dispersion relations of Read More …

# All entries of array except certain indices in octave/matlab

In Octave or Matlab, some times one needs to eliminate certain elements in an array. For example, if a=[10,20,30,40,50,60]; and suppose I want to create a matrix “b” such that it has all the elements of “a” except 20 and 40. This can be achieved by: b=a(1:end~=2&1:end~=4); The result is: b = 10 30 50 60

# Scattering / extinction / absorption cross-sections of silver nanowires (infinite cylinders) using meep

Particles scatter and absorb electromagnetic radiation. One often needs to compare the amount of scattering/absorption/extinction for particles of different shapes, composition, sizes and incident light properties (polarization, frequency and angle). In this regard, the concept of cross-sections comes into picture. There are three types of cross-sections, 1) scattering 2) absorption and 3) extinction. All of them have units of area, $m^2$, and provide a measure to quantify scattering/absorption process. Here using MEEP I calculate the crossections of silver nanowires and compare them with numerical solution (code from Bohren and Hauffman book). To achieve this, I wrote a meep code Read More …

# Gnuplot rgb color schemes in matlab as colormaps

I like the color schemes that are used as palettes in gnuplot’s pm3d plots. I wanted similar color schemes that can be used as colormaps in matlab. After reading this article, I found that one can easily incorporate the traditional rgbpallette schemes in matlab To start, there are several schemes in gnuplot that can be used in pm3d plots and they are: 7,5,15 … traditional pm3d (black-blue-red-yellow) 3,11,6 … green-red-violet 23,28,3 … ocean (green-blue-white); try also all other permutations 21,22,23 … hot (black-red-yellow-white) 30,31,32 … color printable on gray (black-blue-violet-yellow-white) 33,13,10 … rainbow (blue-green-yellow-red) 34,35,36 … AFM hot (black-red-yellow-white) The Read More …

# Arbitrary 2d shapes in MEEP

In MEEP (1.1.1), dielectric structures are often created by constructive geometry (adding and subtracting primitive shapes). The primitive shapes that are allowed are blocks, cylinders, ellipsoids and cones. To create a complex shape, one has to decompose the geometry into these primitive shapes. Over the weekend, I was wondering if it was possible to somehow create any complex shape in 2d without figuring out the exact positions and operations with the available primitive shapes. Here I report how I solve this problem. The first thing I figured out was to create a 2d triangle with known vertices using a certain Read More …

# Plasmonic materials in MEEP

The aim of this post is to share my experience in incorporating dielectric function of metals such as gold and silver into MEEP (a free finite difference time domain package) code. The incorporation is not an easy task and can be daunting for the first time user. Metals such as gold and silver have both Drude and Lorentz components for the dielectric function. There are many forms of Lorentz-Drude expressions in literature with slight notation differences. I prefer the Lorentz-Drude expression mentioned in Rakic et al., Optical properties of metallic films for vertical-cavity optoelectronic devices, Applied Optics (1998) and Read More …

# Electric Field in Metal Nanoparticle Dimers

Metal nanoparticles exhibit localized surface plasmon resonance (LSPR). One can think of LSPR as resonance of electron sea oscillations driven by incident electric field. This is similar to the way a spring-mass system attains resonance under external periodic driving force. The result of this plasmon resonance is enhanced dipole moment or charge separation, which leads to 1) large extinction (extinction is defined as sum of scattering and absorption) and 2) large electric field near the particle. Both of which are shape, size and surrounding dependent. Researchers have taken advantage of this large electric field localization to enhance Raman signals from molecules Read More …