Friday, April 29, 2011

Pocket Solver

Greetings.

For the past few days, I have been busy working on an iPhone Application. I will let you know the details later, but first let me narrate my journey in the mysterious and interesting world of iPhone application development.
    Being a generally Windows/Linux guy, I had no way to get my hands on a Mac. I wasn't willing to spend in the excess of $600 for a Mac(Mini). But thanks to the hacker community, I had a cheaper option. I used VMware Workstation and bought a copy of Mac OS 10.6. Then I proceeded to create a .iso file of the 10.6. Using a preconfigured Virtual Machine along with with custom built audio and video drivers and my Mac OS 10.6, I was able to run 10.6 on a virtual machine on Windows! I will create a blog post explaining how to do this, but tutorials can be found online.
    Once I got my "Mac" up and running, it was only a short while before I downloaded Xcode and the iOS SDK and started working on my app. It is a simple app that solves math equation AND outputs the full written solution. It is thus called Pocket Solver. It is a free application that my company Affordable Software Solutions released.  You can download it later find out about its features. Until then, here are some pics.





Anyway, this post is not to discuss the various features of my app or to promote it. Okay, maybe a little. But in this post, I will share some of the algorithms I  came up with to solve linear equations in two and three variables that will make your life much easier (if your life consists of solving linear equations...)

1) Linear Equation in two variables

Suppose you have a system of two equations that are in the form:

ax  + by = c    
dx + ey = f

then your x value will be equal to:

((c*d)-(f*a))/((b*d)-(e*a))

and your y value will be equal to:

(c*d-(x*b*d))/(a*d)

where x = ((c*d)-(f*a))/((b*d)-(e*a)).

looks complex, doesn't it?  All these algorithms actually do is eliminate the y variable and solve for x, and solve for y by substituting the newly found value of x in the equation.

If that didn't explode your head, here is another one...

2) Linear Equation in three variables

Suppose you have a system of three equations that are in the form:

ax  + by + cz = d    
ex  + fy + gz = h    
ix  + jy + kz = l 

Let us create six variables that contain a certain series of functions that we will use the most.
Let

    ae1 = (b*e)-(f*a)
    be1 = (c*e)-(g*a)
    ce1 = (d*e)-(h*a)   
    ae2 = (b*i)-(j*a)
    be2 = (c*i)-(k*a)
    ce2 = (d*i)-(l*a)

Now we will use these substitutions to find out the values of x, y and z.

So now, your z value will be equal to:

((ce1*ae2)-(ce2*ae1))/((be1*ae2)-(be2*ae1))

and your y value will be equal to:

((ce1-(z*be1))/ae1)

where z is equal to the equation above.

And your x value will be equal to:

(d-(z*c)-(b*((ce1-(z*be1))/ae1)))/a

where z can be found using the first equation.

Once again, I systematically eliminate x, create two equations with only y and z variables, eliminate y, find the value of z, substitute for z in one of the two newly created equations and find y, and substitute for y and z in the given equation and find x.

Wow, that was a lot! I am sure that you can further simply the algorithms, but  I haven't tried to do so. I encourage you to tinker with the algorithms, simplify them and make them more elegant. You have permission to use this algorithms in your projects, but with proper credit given to Aravind Rao.

This is not the end....





No comments:

Post a Comment