Quantum Bayesian Networks

March 24, 2013

Easy to Customize Application For Unit Conversion

Filed under: Uncategorized — rrtucci @ 4:31 am

As part of their job, experimental physicists must have a very good feeling for the size of the quantities that they are trying to measure when those quantities are expressed in the practical units of measurement commonly used in engineering. On the other hand, in order to make their equations clearer and simpler, theoretical physicists (especially high energy physicists) usually use natural units where Planck’s constant divided by 2 pi, the speed of light, and Boltzmann’s constant are all set to one. (i.e., \hbar =c=k=1). But when the time comes to compare a theory with lab measurements, even theorists are forced to deal with engineering units. Even if a theorist writes his theory in natural units, it’s still prudent for him to have a good idea of the typical size of the quantities involved in his theory, with those quantities expressed in engineering units.

Yesterday, while I was thinking about the sizes of certain things, it dawned upon me that JavaScript is an ideal language for writing a unit conversion application.

I wrote a little proof of concept unit conversion application last night. It inter-converts between

  • temperature (in degrees Kelvin)
  • energy (in eV)
  • frequency (in Hz)
  • wavelength (in meters)

assuming that E=k T, E=hf, c=f\lambda, where T= temperature, E= energy, f= frequency, \lambda = wavelength.)

WordPress.com does not allow the blogs it hosts for free to use JavaScript. It automatically edits JavaScript out. But if you have a WordPress brand blog that runs on your own website, then there is no such limitation for you, and you can add JavaScript code to your blog posts. (WordPress.com does allow its free blogs to display spreadsheets that are public and live in your google account. Cool!)

Since this blog of mine is a cheapie run by WordPress.com, I can’t insert JavaScript directly in this post. Instead I have downloaded the webpage to my website. Here it is. Below is a dead figure (jpg) of the page:
FungibleEnergy

Though trivial, I find this little application very useful and highly mesmerizing. I keep plugging numbers into it and trying to remember physical situations I am familiar with in which those sizes arise.

Of course, there already exist lots of websites and computer widgets that do unit conversion for you. The advantage of my little application is that it is easy to customize and it runs on your computer’s web browser, without any need to download supplementary software libraries and without any need to be connected to the internet.

More detailed explanation of why I think JavaScript is an ideal language for this job

JavaScript is admirably suited for doing all the simple mathematics involved in unit conversion. Plus your computer does all the calculations involved without using any extra software other than a browser, which everyone has. If you use a script written in Perl or PHP or whatever, you either have to download much extra software into your computer, or you have to be connected to the internet and beg a remote server to do those very simple calculations for you.

Another nice thing about JavaScript for writing a unit conversion application is that the finished application is just a simple webpage. Any user can download the webpage into his computer. Then he can run the application simply by opening the webpage on his web browser. Alternatively, he can open the webpage with any text editor, whereupon he can view the source code and easily change/customize it to suit his personal taste and needs.

Besides using this application as is, you can use it as a template to write other unit converting applications that suit your taste and needs. Just change the details such as the number of rows, the text, the numerical constants and the formulas being used, and presto, you can change this to an application that, for example, expresses area in different units like acres, square feet, square miles, square meters, etc.

Even if you know very little about JavaScript, as long as you know a little html and one of the C family of languages (e.g., C, Java, C++. etc.), I think you will find it very easy to customize. Take me as an example: I knew next to nothing about JavaScript a day ago, but since I already know C, C++, Java and html, I found this application trivial to write. I just copied from lots of examples that I found on the internet. There are lots (way too many to mention individually) of VERY GENEROUS people who have posted numerous examples and tutorials and code snippets of html and JavaScript on the internet. Whenever I didn’t know how to do something in JavaScript, I just Googled with wild abandon until I found an example that did what I wanted to do.

JavaScript can also be an ideal language for writing applications that do things other than unit conversion. In general, if you want to make a webpage that interacts with the user and does a simple calculation for him based on his answer to a few button or menu choices or numerical inputs, then JavaScript is a nice way to do this.

6 Comments »

  1. Over time JavaScript became my favorite language (although I am still very fond of python). Simply because it’s always there, right in front of your nose, since most of the time when working on the computer this nose will be pointed at some web page . And being hooked to the browser’s DOM means standardized display objects are build in. It’s not the most elegant or well thought out development environment, but everything else just fades in light of its ubiquitousness.

    And you can do amazing things with it. Just recently came across this little gem.

    Comment by Henning — March 24, 2013 @ 4:50 am

  2. Hi Henning. Totally agree with you about JavaScript. Thanks for pointing out the gem.

    Comment by rrtucci — March 24, 2013 @ 5:15 am

  3. The only window I have on all my desktops all the time is Qalculate! (http://qalculate.sourceforge.net/) — I totally suck at doing arithmetic in my head (learned that at second grade or so, and not much changed since thenšŸ˜‰ )… Let me see… boltzmannā‹…18mK/planck/GHz ā‰ˆ 0.3750596

    YMMV

    Paul B.

    Comment by Paul B. — March 25, 2013 @ 6:08 pm

  4. Thanks Paul. I’ll take a look at it. I myself am very fond of a widget called
    UnitConverter Pro
    http://www.apple.com/downloads/dashboard/calculate_convert/unitconverterpro.html
    Not a very original name but a very nice tool

    Comment by rrtucci — March 25, 2013 @ 6:52 pm

  5. You can do unit conversion easiest in javascript by calling the API for wolfram alpha.

    Comment by melior — April 21, 2013 @ 8:22 am

  6. Great javascript conversion application. Check out our unit converter for Windows, it features over 100 conversion categories.

    Comment by Universal Converter — January 1, 2014 @ 5:48 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: