Question:Approximation causes a problem in my loop

Question:Approximation causes a problem in my loop

Maple

Hi everyone.

I have a loop in which initial data of ODE is found on every iteration and is substituted to find new solution. The system is striking 1 or -1 and x'(t) changes its sign, to -x'(t)

I do it this way (k[i] stands for the values of time t):

S1 := RootFinding:-NextZero(unapply(rhs(X[i])-1, t), k[i]);

S2 := RootFinding:-NextZero(unapply(rhs(X[i])+1, t), k[i]);

k[i+1] := min(select(type, [S1, S2], numeric));

But the problem is that when S1 and S2 are found approximately, on some iteration the next k[i+1] may be by 0.0000001 larger than k[i] (which definetely means that it is just the same) - BUT Maple thinks that it is the next solution and substitutes this (wrong) initial data.

Example:

#iteration 2:
S1 := FAIL
S2 := 0.5937908569
k3 := 0.5937908569

Everything is ok here, but on the next iteration a problem happens:

#iteration 3:
S1 := 1.061306871
S2 := 0.5937908571
k4 := 0.5937908571

S2 from iteration 3 is in fact the same thing as S2 from iteration 2, and if approximation was better it should have been FAIL.

How can  avoid these false solutions?

Thanks.

﻿