Monday, 27 October 2014

How to use TLCalc's unit converter

If you have used some of the command line based unit converters, you should find this implementation of unit converters very intuitive to use. The difference is that the command line is split into 4 boxes.

Unit converter is accessed from the the menu on the main calculator screen

User interface of unit converter

Fields for quantity and units

The left column is the quantity and the right column is the unit. The unit represent the scaling to use for the number on that row. In the example, to convert 5 in/min^3 to m/s^3 results in 588E-9 m/s^3 or 588 nm/s^3. The converter is very flexible and you can use any of the built in units like m, kg, lb and so on or you can make up your own like shown in the example.

Built-In Units

The basic units include second (s), metre (m), mile (mi), pound (lb) and so on and are available automatically in the calculator. Basically, the built-in units tries to cover as many of the units that are used to quantify the four natural quantities as much as possible which are time, length, mass and temperature. Other units composed of natural quantities (referred to as compound units in this post) that are frequently used, such as joule and pascal, are also included built into the calculator. You are also free to choose whether to use the abbreviation or full name for most units. Note that all units are case sensitive so joUle is considered an unknown unit. Do not use plurals, none of the units are specified with plurals.

Below the input fields is the auto-complete functionality. This area updates with units you can insert into the unit field as you type. Just tap a box to add the unit into the field. You can also start typing the beginning of the unit name to narrow the list down.

SI Prefixes

You can append prefixes to any of the built-in units (even on imperial units which is probably wrong). Prefixes are definitely case sensitive since mg (milligram) is not the same as Mg (megagram). Note that micro is specified as u and not μ for compatibility with keyboard. The full 20 SI prefixes are supported and can be typed in as the shortened form (kg) or the long form (kilogram). In addition, the binary prefixes are also accepted and are intended for use with bits (b) and bytes (B), e.g. MiB.

Powers

Use ^ to apply a power to the unit. You would normally use this for squared or cubed quantities such as cubic metres (m^3) although any power that is integer is allowed. 

Compound Units and Rates

When making up units, you use the built in units and build them up with spaces in between. E.g. kg L, miles lb, g ft s. You are also able to use rates which are specified using the forward slash '/'. E.g. kg/m. Rates must be specified by one / only. Any units after the / are implied to be on the bottom of the fraction. This is different to how the calculator normally interpret expressions where A/BC is interpreted as (A/B)C in the main calculator instead of A/(BC) as in the case of the unit converter. Do not use brackets to change this, the calculator will not accept it. Note that each sub-unit that make up the compound unit must be valid standalone units so you can give each sub-unit prefixes and powers. It is also possible to use ^-1 instead of /, e.g. m s^-1

Also note that using non-scalar units such as temperature in compound units results in a conversion that is affected by the order you specify the units. It is advised you do not use non-scalar units in conversions and a warning will be displayed if the conversion of compound non-scalar units is detected. 

Scaling Factors and Reciprocals

You can scale a unit by a positive whole number. Like other units, ensure you separate the scaling factor from other units using spaces. This feature can be useful if you would like to compare rates of uneven quantities such as g/50. An example of where a scaling factor is used is fuel mileage:


The unit converter will also automatically reciprocate the conversion process if the quantities are reciprocals of each other. In the fuel mileage example above, the top unit is a distance divided by volume whereas the bottom unit is a volume divided by distance.

Equivalence

The units you convert between must be equivalent. E.g. you cannot convert metres into seconds. This also applies to compound units so you cannot convert kg/s to N/s although Pa m^2/s to kN/s is valid. The way the calculator checks this is to decompose the unit into powers of natural quantities which will be a mix of length (L), mass (M), time (t) and temperature (T). The power of each quantity must match up (remember dimensional analysis in physics?). Some units don't have dimensions such as %, rad and deg and these don't have any effect on the equivalence of a unit with another unit. 

When the units don't match up, you will get a message indicating what unit A has too much of compared to unit B. E.g. converting m^3 to km gives dimensional mismatch L2 meaning unit A has the power of length that is greater than unit B by 2.

Summary

In summary:
  • Quantities go in the left column, units on the right column
  • All units are case sensitive and do not use plurals
  • You can use SI prefix on any unit but note that micro is typed as 'u' and not μ
  • Use spaces between each compound unit. E.g. ms is treated as millisecond and not metre seconds... be careful. Syntax highlighting will highlight in green the base unit, everything just before is prefix and just after is power so use this to check.
  • Use only one '/' sign to specify rates (all units to the right of / will have their powers multiplied by -1)
  • Use ^ to apply integer powers to units
  • Units must be equivalent for conversion to occur

Extras

  • SI units can be used in the input quantity by adding them as a suffix. E.g. 3000=3k. This is useful to allow you to type in large range of values independent of the unit. You can choose to have the output also use SI prefix by ticking the check box. 
  • You can edit the quantity on either rows. The conversion is updated on the other row

Blog for my android calculator: TLCalc

I have created this blog to document the development of TLCalc and also to explain how some parts of the calculator work. Anyone who reads this is welcome to use the ideas I have posted in their own projects. I most definitely welcome anyone to use the ideas here on Windows Phone calculator since I am looking at getting a Windows phone next but would be hard pushed to go through with it if there isn't a decent scientific calculator on it. At the time I ported the calculator, the ones available were rather limiting but in the year that followed, the situation has now improved. There are probably 3-8 apps I would call acceptable and even surpass what I need for a calculator but bear in mind there are also hundreds of junk calculators flooding the store so finding a good one is rather difficult.

For now, I will introduce you to my calculator... TLCalc


The app is available for free on the Google Play Store at: https://play.google.com/store/apps/details?id=com.thompson.lam783.testtlcalc  

Basically, the calculator allows you to type in equations and the calculator will evaluate them at the end, very similar to a TI-84 graphics calculator. It supports 24 variables, numerous functions, complex numbers, graphing, basic algebraic manipulation and unit conversions. I believe it is self-explanatory to use except for the advance features which I will discuss in future posts.