Finding an Automated Algorithm to Solve Hess’ Law II

Update: You can see my current progress here. As of now, I have the modified Gaussian elimination completed, meaning part I is now done (unless more matrices break under it). It’s beta code and shouldn’t be considered complete until a battery of linear equations are run against it to check for validity.

Well, it’s been almost one week since I started working on this problem. To start off, I had several great answers from my question posted on LinkedIn, but it was shut down since someone flagged it as “commercial services”, which it really isn’t, but the person who shut down the problem clarified why it was, and that made sense.

Overall, I put out $100 because I wanted to put my money where my mouth was – it gave this problem value to others, and it also motivated me to work on it, as I was putting my own money on the line.

Anyways, I’ll be splitting the $100 to two people who were really helpful with providing their own pseudo-algorithms for this, Viacheslav Usov and Mkrtich Laziev, which helped me find a path towards developing an algorithm to do what I want.

I’ve spent probably over 15 hours on this program and managed to finish 99% of my initial code to solve the matrices that may represent Hess Law equations (I’ll explain why I said may at the end). I’ll never know if it’s possible to solve these problems until I run a lot of problems against the algorithm to see if I can get the expected values.

Then, there’s another issue once I feel I’m done with my algorithm. Although at first I thought I figured out how to translate a set of chemical equations to a matrix, there are some special cases where I cannot fit the equations into the rules that I use to form the matrix. Instead, I have to re-arrange it a bit to have a proper matrix that is solvable.

By the end of this, I hope to:

1. Have a PHP version of my own algorithm for Gaussian elimination with partial partitioning, backsubbing, as well as a least squares algorithm implemented. (99% done),

2. Be able to demonstrate that with any given Hess Law set of equations, that it can be applied to a matrix and that there will be one unique solution (assuming the set of equations has a solution, as textbooks tend to).

Needless to say, it’s been really fun doing this so far. I’ve never been so involved in working with algorithms or math for that matter. I had to do hours of research on linear algebera and figure out with my limited knowledge how to translate scary math notation into code.

Finding an Automated Algorithm to Solve Hess’ Law

Last week in my chemistry class, I was exposed to Hess’ Law and while doing some example problems in class, I immediately wondered if there was some way to apply linear algebra to automagically solve the equations. I asked my professor if he knew if linear algebra could be applied to solve them, but he said he was unsure since he’s actually not a math person.

I really hate throwing things like that out in class where it doesn’t really apply to what’s being taught (you know, those jerks that ask these stupid wiseguy questions in class just to look like they know more than everyone else), but I just had to get some affirmation if it was possible.

During the weekend I tried to see if I can do it with matrix operations, but I eventually realized that the linear algebra I know is too limited to find a solution. I’ve completely mapped out what the problem looks like, I know how it can be solved via human guess and check, but I really feel there’s a set of consistent mathematical operations that would just give me what I need (kind of like gaussian elimination to solve linear systems of equations).

If anyone knows the algorithm, I will give $100 USD to the first person who does. Note that I’ve also posted this on LinkedIn, meaning whoever is the first, gets it. The algorithm needs to be able to solve all matrices that can be assembled from problems found in Hess’ Law without human intervention (other than inputting initial and final values of the problem). What I’m looking for is an automatic generation of the intermediate Xn values that are required to multiply each row to get the final values.

Edit 1: Piyush Pant discovered that Wolfram Alpha can be used to solve these problems. However, it does not give the algorithm.

http://www95.wolframalpha.com/input/?i=Solve+{w,x,y,z}.{{1,0,0,-3,-1,3,0},+{0,2,3,0,-1,0,0},+{0,0,1,0.5,0,0,-1},{0,0,0,0,0,-1,1}}%3D{-2,4,0,3,0,0,0}

Here is an actual application of this possible algorithm:

Solution: http://www95.wolframalpha.com/input/?i=Solve+{w%2Cx}.{{1%2C3%2C-2%2C-3%2C0}%2C+{0%2C3%2C-2%2C-2%2C1}}%3D{-1%2C0%2C0%2C1%2C1}

Do you use analytic functions?

I’m currently programming a who’s online for leads at work, and was having lots of difficulty in getting the results I needed to properly display the most recent activity.

We have three tables that need to be looked up due to the way the schema was designed. The primary table is a user_log table that stores all actions that a user performed along with a timestamp. However, this log table does not include any user information aside from a user_id. So, to get the information about a user, we need to join that user_id to the user_id in a users table.

But, here’s where it gets really messed up – the users table doesn’t contain the information we need. Instead, it has a contact_id field in the users table, which must be then joined to a contacts table.

So it goes like this:

.. WHERE user_log.user_id = users.user_id AND users.contact_id = contacts.contact_id

Yeah, three tables just to get contact information.

I was finding that the standard SQL Distinct/Group By keywords were proving ineffective in getting the results I needed, which would be to just give me one user_id and the most recent created timestamp in the user_log table. Instead, I was getting multiple rows for the same user_id.

Fortunately, I found out about analytic functions in Oracle, which helped me isolate out unique user_ids and get the latest timestamp for that user by using ROW_NUMBER( ) where the sequence_number = 1 (giving me the topmost result for each user_id).

Unfortunately, I also learned that mySQL does not have analytic functions built in, but it can be emulated in native SQL (Part 1) (Part 2).

The best explanation I can give about the common aggregation functions that most people tend to use like SUM(), AVG(), etc vs analytic functions is:

Assume you have a set of rows.

The aggregation function will take that set of rows and output only one row with the results, while an analytic function will output that set of rows with the results appended.

The analytic functions do not have to work this way, but it’s useful for performing ranking analysis or sorting rows into individual sets of results.

Hi, I create problems.

For the past month, on and off, I’ve been thinking about problem-solving – there’s too much of it. Everyone’s a problem solver, but since when did you hear someone openly say that they create problems? I think the relationship between a problem and solution is cyclical – a problem is a consequence of a solution, and a solution is a consequence of a problem. The relationship is symbiotic, they cannot exist without each other.

When did problems become… a problem? How did the word carry such a negative connotation? I’ve thought of problem-making as a form of opportunity – because the problem exists or is created, there will more-than-likely be someone devoted to finding the solution. Without the problem, the need for a solution wouldn’t exist.

The entire thought about problems came to me one day when I was thinking about outrageous ideas for a novel (which I would never write due to my lack of ability to properly describe scenarios). I thought about having a villain as the main character. Following that, I thought about the cruelest and evilest villain possible, and came up with a person who had the ability to solve any kind of problem without regard to the possible consequences of the solution.

At first, the reader would have the impression that this was a wonderful gift to have – solving any kind of problem, and that the main character is this righteous person who wants to help the world. However, as the main character begins to solve every kind of problem, s/he fails to realize the consequences of the act – people begin to lose meaning within their lives because the problems they lived and existed to solve, were no longer available.

What happens is the world sees an increase in suicide rates. I know someone will call plot hole because those people can find other problems to work with. No. The main character is out to solve EVERYTHING, and is able to do it with extreme ease. The world populace deems the main character as a threat to humanity, and the story ends with his him solving this problem with his own death. I never decided what happened to the world after that, but I’d imagine anarchy as if the idea is to promote problem generation as a ‘solution’, then the world would have to turn onto itself for people to strive to find solutions.

But that brings me to the question, why would a problem have to be chaotic, negative, so consequential?

That’s why I’m inclined to say that I’m a problem creator. There’s too many problem solvers out there already. I want to be the one that creates problems so opportunity lends itself to another’s future.

Or, I could be wrong completely. I recall situations where I have to solve a problem, and after solving that problem, there is no additional problems generated from the resolution. Maybe its kind of like division and multiplication:

Problem x Solution = Problem_New

Solution / Problem = undefined (in certain cases)

Beautiful Math: The Integral (with F-Zero!)

Note: I am not a math/calculus genius, but I do enjoy what it offers to us. Hence, I am not an expert in this topic. My explanation is meant to be extremely simple. The graphs below assume that both the F-Zero cars are going on a straight path without any obstructions, accelerating at their maximum.

What is this integral.gifthat we sometimes see in the movies, TV, or even in our calculus book? This sexy elongated s-shape is called the integral. Like people, the integral can come in many forms:

The indefinite integral integral.gif

The definite integral def_inte.gif

I’m sure you’re going, “Man, it’s hot, but what else can it do?”

Although this is the most simple way of putting it, the integral is used to find the area, the volume of a 3-d object, the mass of an object, or the displacement/distance. There are MUCH more uses, but those are the common uses at the beginning calculus level.
What do these forms mean?

In the indefinite integral integral.gif, we would be finding the entire area/volume/mass.

In the definite integral def_inte.gif, we would be finding the area/volume/mass over a range that goes from a to b.

I’ll give an example.

Let’s take one of the best racing games ever, F-Zero for the SNES. I loved playing with the Golden Fox, due to its rapid acceleration:

fzero.PNG

See the curve that represents the rate of speed? Well, if we knew the equation that gives that curve, then we can use integration to see how far the car would be going at a particular point of the curve. Let’s compare it to the Fire Stingray:

fzero21.PNG

Let’s say that we want to know how far a car is after speeding from point a (starting) to point b (the halfway point). Points a and b represent time, where a=0, and b is the halfway point of the graph. I say half-way because we don’t exactly know what time the halfway point is.

So, what we do is take the definite integral from point a to b, which is the area under the graphs from a to b.

def_inte.gif of the Golden Fox:

fzeroa.png

def_inte.gif of the Fire Stingray

fzerob.png

The blue shading represents the displacement, or how far the car has gone. So, at point b, the Golden Fox will gain a set distance (because the line is straight the entire way), while the Fire Stingray is still gaining more distance.

However, at point b, which is further along? Well, let’s combine the graphs together:

fzeroboth.gif

The above graph shows that at time point b, The Golden Fox will be further along than the Fire Stingray, because the Golden Fox has a larger area (it has the red + blue area) than the Fire Stingray (just the blue).

However, what if we took the integral from point a (time = 0) to infinity (time = MAX, although that’s not really possible in real life):

fzerobotha.gif

In the above graph, I took the integral.gif(indefinite integral), which means to take the entire area under the curve. So, we have the entire area for the Golden Fox and the Fire Stingray now.

What does it show? At the maximum time, the Fire Stingray is now ahead of the Golden Fox because the area of the Fire Stingray is greater than the Golden Fox. Since both are at their maximum time, the Fire Stingray will eventually outrun the Golden Fox.

However, when we took the def_inte.gif of the curves, the Golden Fox was further along at time b, while the Fire Stingray was lagging behind.

Let’s say that the race lasted b seconds. The Golden Fox would win, because the Fire Stingray would never be able to achieve a greater distance until after point b.

I hope you’ve learned a lot today! This was a really simple explanation without going into the actual math of it. Also, feel free to reply and correct me if I’m wrong with any of my stuff.