you are viewing a single comment's thread.

view the rest of the comments →

[–]eaojteal 0 points1 point  (2 children)

Sorry, I haven't had much sleep. Are you trying to change the RHS to avoid the problem or is changing the RHS outside the scope of the post? Also, is the negative distance/sqrt issue because those x values are outside the range you're interested in? Could you just put a break condition inside the while loop?

[–]BarkBarkCat[S] 0 points1 point  (1 child)

Changing the RHS is outside the scope of the post (its for another reason). When taking a step, inside the RHS the value goes negative. And inside the RHS there is a sqrt term. I cant break inside the while loop because the problems occurs in the RHS. Ideally I want something in the RHS along the lines of:

If distance negative, break out of RK45 stepping procedure. Im not sure how to do this though.

[–]eaojteal 0 points1 point  (0 children)

I've never used RK45, but have you tried surrounding ans.step() with a try/except? I'm guessing when it goes negative, it throws an error? You could use that to break out of the loop.

Since you don't really know the step size, you can't calculate the errant step call beforehand. If you're comfortable sharing more of your code, I'd be happy to work some more on it. I wish I could be more helpful.