Friday, March 21, 2014

Estimating Systems of Higher-Order Equations

Evolving the Runge-Kutta method to solve higher-order equations is an interesting challenge. To get the first program working I did it in stages.  First the entire problem was in main, and I was happy to just get u1 and u2 sorted out.  After that I just got one iteration of the K1_1 - K4_2 sorted out, all eight values.  I found a couple of problems with my formulas and fixed them so that I got the same values as the example from the book.

The main loop was next.  I was able to loop through all 10 iterations without any problems because I took my time on that first iteration.  I printed out the results and it matched the output from the example in the book.  All that took about 4 hours.  It is tough to translate from a math book to a computer program, but I guess with practice one probably gets faster at it.

After that I wrapped the code in a C object and created an interface to the function.  I followed the same interface as the Runge-Kutta module I previously did.

I solved a homework problem as well, and print out the results from the actual function. 

The source code:

As I find problems in the code I will update the git repository.

Left to do:

This solves a specific order (order 2) of higher order problems.  To be truly general this should be made into a general function where you can add a function and matching initial values one at a time, then tell it solve all the levels, no matter how wide.

In that case this should solve when you tell it to print or try to pull out a value from the solved array.  It should not allocate the arrays for the work or the temp k values until you know how level of order you need.

No comments:

Post a Comment