Elementary Row Operations with Mathematica

Gaussian and Gauss Jordan methods are a cool way to do stuff, but at the same time, they are tedious. You have to calculate and write each row separately which is a menace. Wolfram Mathematica provides the options to manipulate rows through simple commands which we will do here. Note: although Mathematica has functions to directly reduce matrices to row echelon and reduced row echelon form, this is not what we want to do. We want to learn how to perform individual row operations using Mathematica.

Download Mathematica Workbook
Download Mathematica Workbook

In this example, we will find the inverse of this matrix using row operations:

 \begin{bmatrix} -1 & -2 & 2 \\ 2 & 1 & 1 \\ 3 & 4 & 5 \end{bmatrix}

We append the 3 x 3 identity matrix to its right side.

 \begin{bmatrix} -1 & -2 & 2 & 1 & 0 & 0 \\ 2 & 1 & 1 & 0 & 1 & 0 \\ 3 & 4 & 5 & 0 & 0 & 1 \end{bmatrix}

We now need to perform the appropriate operations with Mathematica to reduce the first 3 columns to an identity matrix so that we get the inverse of the original matrix on the right.

The Mathematica Interface
The Mathematica Interface

1. First off, declare your matrix (with an augmented identity matrix):

A = {{-1, -2, 2, 1, 0, 0}, {2, 1, 1, 0, 1, 0}, {3, 4, 5, 0, 0, 1}}

2. To view your matrix any time in matrix form, type:

A // MatrixForm

3. Perform the operation R_1 + R_2:

A[[1, All]] += A[[2, All]]

or simply,

A[[1]] += A[[2]]

Regarding the sign “+=”, remember X += Y means X = X + Y, and similarly X -= Y means X = X – Y. This sign is widely used in programming languages.

4. Perform the operation R_2 -2R_1:

A[[2]] -= 2*A[[1]]

5. Perform the operation R_3 - 3R_1:

A[[3]] -= 3*A[[1]]

6. Swap  R_2 and R_3:

A[[{2, 3}]] = A[[{3, 2}]]

Reminder: You might want to check the state of your matrix anytime by typing

A // MatrixForm

7. Perform the subsequent operations:

A[[2]] -= 2 A[[3]]
A[[3]] -= 3 A[[2]]
A[[3]] /= -23
A[[1]] += A[[2]]
A[[1]] -= 9 A[[3]]
A[[2]] -= 6 A[[3]]

8. Then show the final output by:

A // MatrixForm

 \begin{bmatrix} 1 & 0 & 0 & 1/23 & 18/23 & -4/23 \\ 0 & 1 & 0 & -7/23 & -11/23 & 5/23 \\ 0 & 0 & 1 & 5/23 & -2/23 & 3/23 \end{bmatrix}

The rightmost three columns now show the inverse of the original matrix. You might want to use the inverse function of Mathematica to check out the answer.



Virtual WiFi Miniport Adapter – Set your hotspot from your Windows PC directly

Connectify and Virtual Router have been around for a while, but did you know you could share your internet directly from your Windows machine as a Wifi hotspot?

From Windows 7 onwards there is this inbuilt feature, namely Virtual WiFi Miniport Adapter. You can broadcast your internet connection in access point mode and use it on any device. In this example, we will share a LAN connection on Virtual Wifi.

Open up an elevated Command Prompt or a PowerShell and issue this command:

netsh wlan set hostednetwork mode=allow ssid=YourHotspotName key=YourPassword keyUsage=persistent

You have enabled your Miniport Adapter. Now issue the following command:

netsh wlan start hostednetwork

Right click on the network icon in your taskbar and open Network and Sharing center. Chose “Change Adapter Settings” on the left side. You will see a new connection with “Microsoft Hosted Network Virtual Adapter” in its description:


This is your Virtual Adapter (and KOSMOS-2251 is my hotspot name).

Now right click the LAN connection (the one you want to share on the Virtual Adapter) and open Properties:


Move onto the Sharing tab and check “Allow other users to connect through this computer’s internet connection”:


You will have to mention the name of your Virtual Miniport Adapter here.

Next click settings and enable all services that you want to share. That’s it, you can use the internet on your hotspot from any Wifi enabled device around!

To stop the Wifi connection, issue:

netsh wlan stop hostednetwork



Algorithm to Solve a User Defined Maze

Level of Mathematics Required: None

So I decided to make a “Pathfinder Robot” as my first semester MATLAB project. Not only did I learn lots of new stuff while doing it, I also ended up making my own algorithm for it. The usual one that is used is called A*. A* finds out the shortest path, but does not use the shortest number of moves. This one uses a different approach, to solve the maze in the shortest number of turns as well as the shortest path.

I will also upload in here the original program that I made later on.

1. Get the maze from the user. Also get the starting and ending points.

Get the maze from the user and save it in a 20 by 20 matrix of zeros and ones. Zeros denote the open area and ones indicate walls.
Get the maze from the user and save it in a 20 by 20 matrix of zeros and ones. Zeros denote the open area and ones indicate walls.

2. Break down your maze into horizontal and vertical segments. A segment is any uninterrupted path in the maze measuring 1 by n or n by 1 depending on whether it is horizontal or vertical, where n is any integer greater than 1. A 1 x 1 segment does not match our definition of segment here.

Red: some horizontal segments. Blue: some vertical segments Green and Orange: some NON segments
Red: some horizontal segments.
Blue: some vertical segments
Green and Orange: some NON segments

Do note that the orange “segments” were generated while segmenting the maze horizontally, and the green “segments” were made while segmenting the maze vertically. Do note that each of the orange parts WILL form part of some vertical segment and each of the green parts WILL form part of some horizontal segment. However, if a white box is locked by all 4 sides, then it will not form part of either a horizontal or a vertical segment.

This forms our complete definition of the segment for this program.

3. Each segment must be assigned a number. In this maze, we have 50 horizontal and 44 vertical segments. Store the information of each segment in a matrix. (The starting and ending points, for example).

4. For each horizontal segment, find out ALL the vertical segments that intersect it and save them into an array also.

5. Do the same for vertical segments. Remember a horizontal segment will ALWAYS intersect with a vertical and vice versa.

6. Run a recurrence process starting from the starting segment. Find out all possible pathways that extend from the starting segment. For example, if the starting segment has 6 intersecting segments, you have 6 possible moves in the first place. For each first move, find out all possible second moves and so on. On every level however, do keep checking if you have already encountered the destination segment. Break the loop then.

7. Highlight the path using the segments. This is tricky. You do not highlight the entire segment, only the part of it that lies between the segment before and after it in the sequence.

Important Notes

Do remember that your sequence of moves in every single possible route will be such that if the first segment was horizontal, the second will be vertical and the third will again be horizontal and the fourth will again be vertical. You can exploit this fact to prevent your robot from moving backwards (thats not what we want). Here’s how. Suppose this was your sequence (it’s stored in a array)

sequence={1, 4, 4, 51, 7, 9, 11}

Each element on an odd index of the array denotes a horizontal segment and each element on an even index denotes a vertical segment. Before appending a new horizontal segment to the sequence, check that the number does not already exist on an odd index of the array, and before appending a new vertical segment to the sequence, check that the number does not already exist on an even index of that array. 4 is used twice here, but its fine since one of them denotes a horizontal segment and the other denotes a vertical segment. We basically don’t want to encounter the same segment twice.

Do remember that as “full” as your maze is, the less the number of possible paths and the less the computation. However, if your maze has large open spaces, the number of intersections in that open space increase drastically and slow down your program. To solve this, move on to optimization.


So your user left out lot’s of extra space in the maze. You do not want it. What do you do? Well, you simply cancel it out from your main program sequence by placing a “patch” on the maze. This “patch” is more of a “crime scene, do not enter” type of stuff. You move from the sides, you do not enter it.

Yellow: Trim from the outside Magenta: Trim from the inside
Yellow: Trim from the outside
Magenta: Void/Trim from the inside

First of all, “trim” the maze from the outside, leaving just a track of unit thickness around the maze (don’t block it all).


  • Probe the maze for any 4 x 4 regions of empty space.
  • Void out (magenta) only the central 2 x 2 of this space.
  • Expand this 2 x 2 first horizontally and then vertically, as much as you can, but again, leaving a track of unit thickness on the side of expansion. (That’s the reason we void out only the central 2 x 2 of the 4 x 4 region.)
  • DO NOT search for another 4 x 4 region unless you have expanded the first one as much as it could be.
  • Assign numbers to these patches as you create them.

There’s a possibility that the patches lengthen the route while decreasing the computation. See below:

Moving between the two blue dots involves just 2 segments, but because of the magenta patch, it now needs 4 segments.
Moving between the two blue dots involves just 2 segments, but because of the magenta patch, it now needs 4 segments.

Doesn’t matter. Once you are done, correct this for each patch (that’s what we assigned them numbers for). Just scan the sides of each patch and detect the points where the path moves away from the patch. There will be two such points, connect them together and delete the part that “wipes around the patch”.

Grey part shows deleted part of the route.
Grey part shows deleted part of the route.

Computer Science vs Computer Software Engineering

I’m often asked this question, what’s the difference between Computer Engineering, Computer Science and Computer Software Engineering. I’d like to answer this question once and for all.

See, Computer Science and Computer Software Engineering may have common links, but Computer Engineering has nothing to do with them, even remotely.

Computer Engineering is a category of Electrical and Electronics Engineering where you mostly deal with computer hardware, its design and function. It does involve software, but only to a very basic level that we call firmware. Firmware is small software that is loaded onto microcontrollers (microchips) to control their function. Of course, it is the most fundamental piece of software that is needed to run a system, but at the same time, it is very basic as compared to that involved in the other two fields.

Computer Software Engineering, as its name says, is the design of computer software. All daily applications that you use are a product of computer software engineering. Software Engineers use programming languages like C++, C# and Java to make their applications. Do remember that software that is a result of Computer Software Engineering is generally compiled and is platform dependent. In other words, it knows on which operating system (Windows, Linux, Mac OS X) or hardware (Intel x86, x64, AMD, etc) it is supposed to be run. This software is standalone and would generally not require any other software to run it (dependencies are something else, e.g. Installing DirectX because some features of the program require it).

Computer Software Engineering can be considered easier than computer science in sense that you do not have to sit and derive the algorithms, but you should have technical knowledge of several programming libraries. Programming language, in itself is nothing but a platform for development. It’s programming libraries that give you additional functionality in that language. For example, to make the simplest Windows program, you should be aware of WinAPI. WinAPI (Windows Applications Programming Interface) is a library to interface software with the massive Microsoft Windows operating system. Windows applications are built using WinAPI libraries. UNIX software is built using libraries. (I am not referring to Command line applications since they follow a general code and do not even require knowledge of WinAPI. It’s because they are supposed to be run inside the shell, or console of the operating system, and do not generate a window on their own.)

In order to show stuff inside your Window, you need to be aware of libraries specific to the type of software you build. DirectX and OpenGL for example, are two most common libraries for building applications with 3D graphics.

Computer Science, on the other hand, is a mainly theoretical field. You will often use software like MATLAB, Mathematica, Maple to visualize systems. Of course, it also involves programming, and of more or less the same level as Computer Software Engineering. As a Computer Science major, you will be doing mathematical modeling, physical calculations, algorithm design, etc. However, the software you make will generally be platform independent. In other words, your software will not be aware of the platform it is running on. MATLAB programs for example, will run on any computer system with a copy of MATLAB installed on it (although MATLAB itself is a product of software engineering).

When it comes to deciding your major, you should be aware in the first place whether you want to work at hardware level or software level. If hardware, then Computer Engineering it is. If it’s mostly software for you, then you should know whether you want to work mostly on the technical side or the theoretical side. Do remember that both Computer Software Engineering and Computer Science have complexities at different levels. Computer Science is better if you are good at mathematics and algorithm design. Computer Software Engineering is better if you are good at reading the documentation of different libraries and putting them to practical use to build software.

At university level, Computer Science majors will often be taught courses related to Software Engineering, and vice versa. Some universities may not even have a separate program for Software Engineering. Both fields share a lot in common, and by getting a degree in any of them, you can get a job in either field.


Windows 8.1 Post Install – Do’s and Don’ts


  1. First of all, Windows 8.1 setup does not ask for your timezone during setup. Right click on your clock and set your timezone straight away, or you can run into problems that you can’t imagine.clock
  2. Windows 8.1 will frequently ask you to download and install .NET 2.0 and 3.5. But everytime you try downloading it, you will get the error 800F0906. This issue was present in the Preview editions and hasn’t been fixed so far. Here’s the universal workaround: mount your Windows 8.1 ISO and issue this command in Command Prompt or PowerShell:
    dism.exe /online /enable-feature /featurename:NetFX3 /Source:h:\sources\sxs /LimitAccess

    (where h:\ is the letter of the Virtual Drive containing Windows 8.1 Installation Media.

  3. The Lock Screen which has a very short default timeout (1 minute) will drive you crazy. By default, you cannot change its timeout in the advanced settings of your power plan. To change it, open Registry Editor.
    Navigate to the following key:


    Double Click Attributes and change its value from 1 to 2.

    Now when you edit the advanced settings of your power plan, you can see a new parameter under the Display sub menu, namely “Console lock display off timeout” (see figure below). You can set your timeout as you wish.


  4. Install DirectX.
    Quoting directly from Microsoft:

    Some applications and games require DirectX 9. However, your computer includes a more recent version of DirectX. If you install and then run an application or game that requires DirectX 9, you might receive an error message such as “The program can’t start because d3dx9_35.dll is missing from your computer. Try reinstalling the program to fix this problem.”

    To install it, go to:

  5. This one’s upto you, but I found this handy. In Windows 7, the Libraries were quickly accessible in the Navigation Pane. In Windows 8.1 however, Libraries appear beneath This PC in the pane. Ever since I started using Windows 7, I personally keep all my data in a separate hard drive and just add the location of my Documents, Music and Pictures to the appropriate Library. Hence Libraries are my most used links in the Navigation Pane. I do not like to scroll down each time to access them. Here’s a workaround to bring them above This PC in Windows 8.1.
    Open Registry Editor (Run > regedit) and navigate to the following key:


    Change the value of SortOrderIndex to 38 (hexadecimal).

    After you reboot, you will see the Libraries have moved above This PC and are quickly accessible.



  1. Do not ditch the new Metro apps instantly. Give them some time. You will soon learn you will be using these new apps for the rest of your life. It wasn’t 5 minutes I started using the new Reader app that I realized I would finally stop using Adobe Reader which I had been using for the last decade.
  2. Do not install any ISO mounting software. Windows 8.1 includes this feature by default.
  3. Do not install any third party antivirus software. Windows Defender, prebundled into Windows 8.1 is just a rebranding of the Microsoft Security Essentials and works great.

Enjoy Windows 8.1!


Wavefunctions, Space and Time

This post is meant to help you visualize the common wavefunction ψ(x)=A sin(kX-ωT).

Visualization is best done with graphs. Since the quantity ψ(x) here depends on two quantities, X and T, what we need here is a 3D graph. Y axis represents ψ(x). X axis represents Space and T axis represents Time.  The plane Y=0 is just placed for reference and does not hold any significance.

Rendered using Wolfram Mathematica
Rendered using Wolfram Mathematica

Do note that every function that depends on both space and time is actually a 3D graph. The Y quantity depends on both X and T. Y varies with both X AND T.

If you freeze your wavefunction in time, you are actually making the value of T constant at say T=0. The remaining wavefunction is simply ψ(x)=Asin(kX) since T=0. If you chose to enter a non zero value for t, the resulting expression will be ψ(x)=Asin(kx-C) where C represents ωT at a constant non zero value of T.

Freezing wavefunction in time also means looking at it from only the X-Y plane. (And freezing in space would mean looking at the Y-T plane.)

Mathematically, in ψ(x)=Asin(kX-ωT), if the value of ωT increases, you are subtracting a greater value from the argument of the sin function and the graph should shift towards the right.

Now observe the mesh lines on the 3D graph, as you move along the T axis, your graph in the X-Y plane is shifting forward. (Increasing T will also increase ωT).

The minus sign with ωT is conventional. If the sign of the quantity ω is reversed, this minus sign will disappear.

The argument of the sin function is always an angle in radians, hence the unit of both kX and ωT is rad (radian).

k is (2π rad)/(λ m) and X is in meters. Hence the unit m (meters) cancels out when k and X multiply together.
ω is (2π rad)/(t sec) and T is in sec. Hence sec (seconds) cancels out in ωT.


Did you just lose your data to a corrupt HD partition table?

WAIT. Don’t attempt suicide.

Out of the many different cases of data loss that I have been through, this is the easiest one to deal with. Geeks can be paranoid about data, huh? But at the same time, geeks are the only ones who are more prone to data losses due to corrupt partition tables, and you already know why!

…falls down, hits head, cries a little…

Geeks are guys who can’t rest with the same OS for more than two months, and they keep switching over to different flavors of Linux and BSD time and again. Surprised by my prowess in this field? Yeah, because just like you guys, I am a geek. I have sworn however, that from now on, I would rather rip my leg off than install another OS on my rig.

So guys, I can understand your situation. First off, let me introduce you to some really lifesaving gear that I keep, just in case. Download them from their specific websites:

  • A Linux Live CD: I use CRUX 2.4 which I downloaded and burnt over 3 years back, but as far as it still works for me, I’ll keep it, since it has always been there for me ;)
  • TestDisk – This little app can do business. Get this app from (and be sure to download the Linux version). Save this app on a USB.
  • Some removable storage device. If you do not have enough storage on this device to transfer all your HD data, you can use another computer to empty this drive each time it fills up.

So guys, in a nutshell, what we are going to do is boot from the Live CD (since our HD won’t boot for us at the moment), then fire up this app.  You must be knowing that deleting a file does not actually delete it from the HD. It is there and will continue to be there, unless you overwrite that specific hard disk sector with another file. And yes, files are never located on adjacent HD sectors. A file is made up of numerous clusters and each cluster of a file would be located in a very distant sector to that of its counterpart. Therefore, even if you overwrite that specific HD sector, there is a high chance that you will still recover part of that file.

Are we ready?

Insert the CRUX Live CD into the tray and boot into CRUX Live CD:

Press enter and wait until the console is ready, then login as root:

Create the mount point for the USB:

If you are not sure about the device node for your USB, just issue the fdisk -l command:

From this I know  that my USB (which is 1 GB) is on /dev/sda1.

Mount the USB on which testdisk is stored. Then cd to the directory where the testdisk binary is:

All right! Fire up testdisk!

The following steps would be self explanatory and you may need to choose different options depending on your rig:

Next we press the Quick search button. This will search for partitions by analyzing the cylinders hence bypassing the need for the partition table! This is the magic behind data recovery from a corrupt partition table!

You may stop the search anytime, if you want to skip over to Deeper search. But I recommend using the Quick search before you do Deeper search.

Unfortunately, I am running this on a Virtual machine and the HD is virtual as well. As it is empty, no partition shows up:

But this is the point where you should take solace! Your partitions (which would otherwise be gone for good), will appear here. Just select each one one after the another and start copying the files over to a removable storage. To mount the storage device, you can simply switch to a secondary console by pressing CTRL + ALT + F2. Once you have mounted your drive, revert to this screen by pressing CTRL + ALT + F1. Then start copying your data. Easy, wasn’t it?

Happy recovery!


Setting up an Android Development Environment using Eclipse IDE

As you read this, you are most likely to be tapping on a smartphone screen. In this era of smartphones, Android development is one of the most demanded skills out there.

First off, we will stick to Eclipse. We will first set up a generic Java development environment, followed by the necessary tools on top of it for Android programming functionality.

Before doing any installation, fetch all the necessary tools to your hard drive. Here’s a list of what you need:

  1. Eclipse IDE for Java Developers
    Download from:
  2. Java Development Kit (JDK), contains libraries for Java development
    Download from:
  3. Android SDK tools (contains the Platform and Build tools)
    Download from: ; click “USE AN EXISTING IDE” > “Download the SDK Tools for Windows”.
  4. Android Development Tools (contains libraries for Android development; it is dependent on JDK)
    Download from:, scroll to the bottom of the page, “Troubleshooting ADT Installation” section.



  1. First off, install JDK.
  2. After JDK installation, go to your Computer properties. On Windows 7, 8 and 8.1, right click on Computer/This PC, click Properties and then in the window that appears, click “Advanced system settings” in the left pane.
  3. Go to the “Advanced” tab in the window that appears, and click the “Environment Variables…” button towards the bottom.
  4. Add a new variable in the “User Variables” section, with the name JAVA_HOME, and the value should be the address that points to your JDK installation:
  5. Do not close the window. In the System variables section, find the “Path” variable, and click Edit:Path
  6. At the end, append the path to your JRE installation (include the semicolon in the beginning and the /bin at the end).
  7. Save your configuration; extract Eclipse in a directory such as C:\ and create a shortcut for eclipse.exe on your desktop.
  8. At this point, your Eclipse has been set up for Java development. Move onto the next steps for Android development.
  9. Once the installation completes, the installer offers to start the Android SDK Manager. DO NOT start the Android SDK Manager.
  10. Install the ADT plugin in your Eclipse installation. There are two ways to do this. Either install it from the online repository, or download it first, and install it as an archive. I recommend installing it directly from the repository, because even if you are installing it from the archive, a lot of dependencies have to be downloaded from the internet during install. To install it directly from the online repository,
    1. Start Eclipse, then select Help > Install New Software.
    2. Click Add, in the top-right corner.
    3. In the Add Repository dialog that appears, enter the following URL for the Location:
    4. Click OK and follow the steps to complete the installation (you will need to accept the license agreement).
    5. If you downloaded ADT as an archive, follow the method here:
  11. Fire up Eclipse. You will get a warning that the Platform tools and Build tools are absent.
  12. The required tools will be checked by default, just click the “install packages” button. (Do not compare your selected packages with mine, since the screenshot was taken during the installation, when some packages had already been installed).
  13. 13. If you get an error, close SDK tools, and run it from the Start Menu or the Start Screen in elevated (administrator) mode by right clicking on it.
  14. Wait for the installation to finish:
  15. Once it’s done, congratulations. Your computer is all set for Android programming. Fire up Eclipse to create a new project straight away.

Happy coding!

reduction to the absurd


Get every new post delivered to your Inbox.