Showing posts from February, 2015

recursively opening/creating files using c

Most of the day was spent between classes and the afternoon was spent listening to talks at the dept. of physics, as part of the in-house symposium this weekend. Most of them went over my head and I decided to get out of the air conditioned lecture hall before I start drooling or dozing off, to save what little face I have left. Having had a heavy lunch, I finally got some coffee and kicked off my boots, getting back on the numerical methods in programming assignment. A part of it is to plot the legendre functions of degrees (0,5) in the interval (-1,1). For this, I thought I'd have to iteratively open files and write the the function values to different ones. And for this I needed to know how to create files iteratively. Blindly, I tried
in_ptr = fopen("file_%d"+i,"w"); where i was the variable I was iterating over. And it worked, no compilation error, no execution error. The results however were interesting! It created files names file_, ile_, le_, e_, and _…

Another one bites the dust

Even compared to my standards, today was uneventful. After classes, I started work on my numerical methods programming lab work but quickly succumbed to the post-lunch drowsiness, only to be woken up at 4 by weird dreams about ghosts and goblins. I have spent the rest of the day, waiting for the proverbial *moment* to dawn on me and motivate me to work. I should probably take a hint and not wait any further but hey, as Freddie Mercury put it, another one bites the dust...

Travelling waves and magnetic domain walls

It took a while but I finally figured out, after almost 3 days, as to how to visualize a travelling wave using the method I've been using so far  using ipywidgets on an ipython notebook! And here is the result of it. The first plot shows how the envelope of the pulse as a whole changes with change in the total number of modes added in phase and the second plot shows how the pulse moves along the x-direction in time. So far, I'm pretty happy with the incremental progress I've made and my resolve to build something on a solid foundation has strengthened over the last month. I will keep pushing this further, at whatever slow pace I can, adding more and more complexity to it. Let's see where the rise takes me.

Otherwise, the interesting thing today was the bi-monthly departmental colloquium, delivered this time around by Prof. Anil Kumar from IISc, Banglore. His research interests include spintronics, nano-magnetization, and spin polarized electron scattering. He talked a…

Keeping track of multiple git repositories

I have quite a few git repositories, 2-3 of which I actively work in everyday. And for many reasons, I might not push commits everyday. Eventually, when I gain access to the internet, it's taxing to cd into each directory and run git status to check the additions in the repository and the commits that need to be pushed. Being me, I looked for an easy solution which would loop over all git repositories and tell me their status. And this is what I have found in due course -

This article talks about the use of third party tools such as Repo, gitslave, git submodules and git fusion. This describes one of the brilliant bash one-liners that can be used for the same with a much lengthy and less readable version here. Here is a solution in python, in contrast to the earlier ones which are all in bash. Uncommitted is another such solution in python, although it only supports hg and svn. Another simple bash one liner can be found here. Another third party tool, on part with the earlier ones…

Back after the weekend

Count Photon is a very witty nick name. I wish I'd thought of that! Either way, back to hearing me instead of my friends. Today just passed by thinking about general relativity, lasers and cython. I finally figured out why my cython code was giving seemingly errenous results, because I had forgotten to implicitly typecast a specific constant that I was in the earlier buggy version, calling directly from the function. Every numeric operation in cython has to be between values that are typecast is something that I learnt out of this so far.

The morning was spent in awe at what was being taught as part of a general relativity and cosmology course that I am taking this semester. By simply varying/extremizing the action of a free particle in space, we arrived at the equations of it's motion. No field, nothing! It was beautiful to see that a function derivative of the metric that describes the space(time) describes the equations of motion. It was also interesting to note that the e…

What is Photonics?

As promised, I shall introduce to the world of photonics through this post. If you ponder at the word 'Photonics' for some time you will realize that you have heard a similar word somewhere in your life. You are right! The word you are looking for is 'electronics'. Just like electronics is the study of electrons, photonics is the study of photons.
Imagine what would happen if every instrument around you ran on photons instead of electrons. Form the top of my head, data-rates would increase drastically and size of instruments would decrease enormously. Scientist around the world have realized that they have reached the limits of electronics and the future lies in photonics. I also strongly support this claim. In an attempt to convince you, I shall give you an example. Optic fibers have replaced traditional co-axial cables and twisted wire pair as channels to transfer data. You can google what speeds optical cables are giving compared to traditional electrical links. I …

Replacement's here!

Since astronut's home, I shall be your enterntainment for this weekend. You can assume this post was put up on 21st February to keep up astronut's daily streak. I will use this post to introduce myself and maybe the next one to talk about something interesting.

Lo and behold me - Count Photon. Now don't go like - what!? Count!? What are you counting? Photons? No! See that I spelt Count with a capital 'C', which means it's a proper noun. So take it something like Count Dracula; it's my name. The more serious side of me can be found here - . I am an undergraduate student in the department of Electrical Engineering at IIT Madras. I am very passionate about Photonics. For now I will assume you know what photonics is or you can wait for my next blog entry where I explain what it is. Maybe I will also try to explain what 'photon counting' is and ergo the motivation for my name.

Catch you all in the next post. Seeya.

Home for the weekend

I'll be going home this weekend and will only be back late sunday. I have some course work to catch up to and I have one small visualization to make, showing how the output of a mode locked laser looks in time i.e actually see the intensity of the output increase and decrease periodically. In general, this is the phenomenon of beats and how the sum of two frequencies in a given spatial domain varies with time. And I guess I'll add comments and cleanup all of my codes, updating the readme files and rewriting the .help files. Until then...

Random numbers in , adaptive integration and properties of lasers.

I finally got help in solving a problem I was having with generating random generators in C, using the standard function rand(). Apparently, srand48() also does the same job as rand() does and does it better even but I wanted to get my code working with rand() in the first place. Calling rand() returns a random large integer and I needed to convert it to a float between (0,1). RAND_MAX is defined as the largest random number that the system can generate. I knew that I had to divide the output of rand() by RAND_MAX and after a bit of juggling things around, I finally got it working. The relevant code is an implementation of the one I've written earlier in python ad fortran to estimate the value of pi using monte carlo integration. The numerical methods lab in the afternoon had us implementing an adaptive integration method that would choose step size depending on the error and increase or decrease it accordingly if our new estimate was correspondingly better or worse than the prio…

Still on cython

After classes in the morning, my afternoon was spent trying to understand why my codes were running so slow. I knew that i was doing twice the number of function evaluations while estimating the integral of a function numerically but even after i used the correct weights in the trapezoid rule, my code was running slow. I tried cython and it was bit better, but not so much that it made any difference to me. Doubtful that working on an ipython notebook might be a hinderence, I learnt how to build cython codes and use them a libraries in python code, instead of running them on the ipython notebook using the %load_ext cython and %%cython magic functions that I was using until this point. It was a bit better than when I was running the code on the ipython notebook but it still hung up on me after a point. But one thing is for sure, the numerical estimates of error seem way more rational and similar to that I get from C when I ran the cython code than when I ran the python version of the s…

Cython and nbconvert output

As I mentioned in an earlier post, I wanted to learn cython but never had the right motivation. This time I said screw motivation and I just started. Apart from a couple of extra lines to load the cython magic and a small change in the way one imports libraries, the significant difference was the static typecasting of variables. I didnt get much speed out of writing a small code to estimate the integrand of a function but yes, there was a speed up.Moving in, I also wanted to look up a way to toggle the output of various cells in an ipython notebook converted to html. Ipynb files themselves grant the ability to toggle or minimize the output but the nbconvert doesn't do any such thing by default. And after a bit of googling, I found someone's solution to the problem - a problem that enough people have asked about and tried solving! Now to include this to my repertoire! Onwards my good men...And I finally got off my lazy ass and modified my github site links to have easy access t…

monte carlo integration and estimating the value of pi

I have talked about estimating the value of pi earlier and have even mentioned the code that I wrote to estimate the value of pi. I did not realize that I was applying the monte carlo integration method to estimate the area of the circle. I have wanted to implement it since I started working with monte carlo methods and once I realized that the method I used to estimate pi was a monte carlo method, I immediately tried to estimate the error in the estimation, which depends on the total number of monte carlo steps or iterations. Error in monte carlo integration is a function of the inverse square root of the total number of monte carlo steps, which is exactly what i saw in the log-log plot of step size vs error in estimation. After a bit of trouble, i ported the code to fortran and got the same results, with fitting and plotting being done on gnuplot. The ipynb file is available here and the fortran file here. I now need to look for more interesting functions which I can apply the mont…

Mode locking and numerical methods in fortran

I made a visualization that shows how mode locking creates short pulses; the more the number of modes in the cavity, the shorter the pulse width, with the condition that they all have the same phase. You can find it here. It's not yet complete, I also need to show how the output pulse looks when the modes have random phases. The code is in python, was written using the ipython notebook and uses ipywidgets to create the interactive plot.

On the flip side, I was hitting my head against the wall trying to adapt a code to perform numerical integration in fortran. The code would compile but not execute in the first place and google told me to move the executable to a folder in the home directory. Weirdly enough, this worked. Apparently this problem is an after effect from when i was copying these files out of my home dir earlier. chmod helped fix that problem. Having figured out how to define and call functions in fortran, I was now stuck on a type mismatch error, because the function…

Numerical computational methods in python

I procrastinated for a day on a code that took me an hour to write. I commented code, rearranged old code and my data, wrote mails and did everything under the sun but write this code all day, for reasons that are still beyond me. And now that i'm done with it, I honestly don't understand why i was procrastinating.

On a seperate note, accuracy on precision sucks and additions are error riddled, way more than that seen in C, something which i'm noticing more and more as i'm writing the same algorithm in python and C.Maybe this will be the push that I needed to learn cython, which i've been talking about for a while. Too much talk, isnt it?

Fabry Perot Etalon transmission curves

After a long time, I got back to making small interactive plots/visualizations using ipywidgets on ipython. For the time being, nbviewer doesn't seem to be working but you can access the .ipynb file here and the relevant .html file here. Simply put, the Fabry Perot etalon is two mirrors aligned parallel to each other. Their transmission properties depend on the reflectivity of the mirrors and on the phase of the incoming wave. It seemed like an easy enough one to make but I never worked on it, made it in about 15 mins in the evening when I wasn't able to get much else done. Otherwise, I'm catching up on gnuplot tricks and function definitions in fortran.

setup files

I don't even remember how many times I've installed ubuntu over the last 5 years but I did it one more time last week. Installing the system got easier with time but setting up the system, installing the necessary software was my bottleneck, taking up atleast half a day. And I never bothered writing a shell script to automate this. As the saying goes, necessity is the mother of all invention, I got my ass of in december and wrote a shell script that would setup dependencies and install relevant software. I also dabbled around with modifying my .bashrc file a bit, setting up a prompt that would change in size depending on the window size. There's a lot more to do in terms of bash scripting, I've barely scratched the surface. My afternoon was spent working on numerical integration routines and I guess tomorrow will be spent writing the same in fortran and python. And on the side, I'm trying to learn how to use APIs to fetch data from websites, specifically arXiv. I …

Gravitational redshift

Before I talk about gravitational redshift, let me just briefly talk about doppler shift.Doppler shift is a high school concept that most of us have learnt at some point or the other in our lives. If you haven’t learnt it, safe to say you’ve surely experienced it. Say you’re on a platform and a train is approaching you. The train is sounding a horn, to catch the attention of passengers on the platform. The increase in the pitch of the horn as the train is approaching you and the decrease in pitch as the train is moving away is the phenomenon of doppler shift.The same can happen to light. Say a source of light is moving towards you, the frequency you perceive the light to be at is not the same as the frequency of light emitted by the source. This is because of the fact that a clock in the frame of the source ticks slower than your clock, which is at rest. This is the phenomenon of time dilation.Venturing further now, the Schwarzschild metric describes the spherically symmetric curved s…

Popular astronomy videos

Phil Plait does a great job at introducing various concepts in astronomy, with brilliant visuals, to help understand them. PhD comics also has interesting videos talking about disparate topics in astronomy, one of which is on Dark Matter, linked below.

Blackbody Radiation

It was surprising to learn that radiation was quantized by Max Planck to explain blackbody radiation. In 1901 he published a distribution of the form
that fit the experimental data perfectly and it took him a decade more to develop the theoretical framework that could explain such a distribution.Before Planck, Lord Rayleigh and Sir J. H. Jeans proposed, independently, a distribution of the form

and before that, Wilhelm Wien proposed a distribution of the form
One could say that all Planck did was to add a one in the denominator of the distribution initially proposed by Wien but the Nobel prize that was awarded to him was awarded not for proposing the distribution of blackbody radiation but for proposing quantum statistics. Radical to the prevailing knowledge at that time, Planck proposed that the energy of oscillators that were emitting radiation wasn’t continuous but was quantized, into discrete units, measured by an integral multiple of the fundamental frequency of the oscillator…

stefan boltzmann law

Stefan-Boltzmann LawUnderstanding the radiation from a blackbody was a problem that many prominent physicists tacked in the late nineteenth and early twentieth century. Part of problem was to understand the total energy emitted by a blackbody, which is solely dependent on the temperature of the blackbody. It can be argued that there is no dependence on the direction of radiation i.e isotropy. Boltzmann finally came up with a physical basis to show that the total energy radiated by a blackbody is proportional to the fourth power of the temperature of the body.Radiation can be described using the radiation density or the radiation pressure and take it from me, for now, that the radiation density is related to the radiation pressure as such where is the radiation pressure and is the radiation density.Now, let’s use

where is radiation density per unit volume

we can therefore say that

and since

This document is written in Markdown using StackEdit1StackEdit is a full-featured, open-sou…

Just another day

Most of the day was spent in classes, working out the action of a relativistic particle in an electromagnetic field, brushing up on pointer arithmetic in C (and finally understanding it!) and pondering over what the difference between an opinion and a value is.I wouldn't call myself a patriot but the documentary on how adivasis of the Jharkhand state were being displaced for the benefit of Uranium mining on their ancestral land. It was on parallel with some of the stories I remember from 'Everybody is a good drought' by P. Sainath, in which he talks about such adivasis being displaced by the government to build dams. The topic of naxalites came up during discussions after the documentary was screened in the class and while pondering over what the solutions of such a problem would be, how the adivasis should face such events and so on, the one thing that I am certain of is that had information of the government's wrong doings been made public, the adivasis might've …

Carbon Dioxide l(m)asers in the martian atmosphere

It was interesting to find out that co2 maser emissions were observed from the martian atmosphere. As part of a course on ultrafast lasers, the professor gave us examples of natural occurrences of stimulated emission. I talked about astronomical earlier, in fact I gave a short presentation on the same topic last semester as part of a course on laser theory. Anywho, co2 maser emission from planetary atmospheres. This got me thinking...Going on a tangent, adaptive optics is a technique used in astronomical observations to reduce the harmful effects of turbulence in the atmosphere. It involves the use of a laser to generate an artificial guide star which can help us calibrate the atmospheric noise during the observations. The artificial star we generate is back scattered light from upper layers of the atmosphere. My question now is, can the laser that we are currently using to generate the artificial star also work as a pump that could be amplified by the atmosphere, to generate a maser …