OK, what's wrong with my Runge-Kutta implementation?

Started by
10 comments, last by Axter 22 years, 2 months ago
quote:Original post by LilBudyWizer
Well, anyway, you just need to call a function returning x/(1-x) instead of the ForceAtDepth function. You don''t need the fT# or second parameters at all assuming you want to integrate x/(1-x).


Could you be so kind and give an example of how I would change my code above to do what you say? For some reason I can''t figure out how to make it work. You say my function should return x/(1 - x), so I should pass in x, but where do I get x from, in each of the four calls?

Sorry for the confusion, and thanks in advance...

SS

SS
Advertisement
Your x''s are fDepth1, (fDepth1+fDepth2)/2 and fDepth2 just as it is shown in your post. You just get rid of the second parameter. Your Runge-Kutta routine is roughly the equivalent of one iteration of the loop in the Euler routine. After modification (fK1+fK4)/2 is the trapazoid rule value. The fK2 and fK3 values are both the same and is the midpoint rule value. You then average those as either ((fK1+fK4)/2+2*fK2))/3, ((fK1+fK4)/2+2*fK3))/3 or ((fK1+fK4)/2+fK2+fK3))/3 which all give the same value. The accuracy of the routine is still dependant upon how many sub-intervals you break an interval into just like with the Euler routine. It just takes fewer sub-intervals to get a given level of accuracy.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement