@@ -542,6 +542,12 @@ def chandrupatla_in(
542
542
x2 = x
543
543
y2 = y
544
544
x = secant (x1 , x2 , y1 , y2 )
545
+ if x1 < x2 :
546
+ if x < x1 :
547
+ x = x1
548
+ else :
549
+ if x > x2 :
550
+ x = x2
545
551
# Use the secant method on the final iteration for high precision.
546
552
return secant (x1 , x2 , y1 , y2 )
547
553
@@ -687,6 +693,12 @@ def chandrupatla_iter(
687
693
x2 = x
688
694
y2 = y
689
695
x = secant (x1 , x2 , y1 , y2 )
696
+ if x1 < x2 :
697
+ if x < x1 :
698
+ x = x1
699
+ else :
700
+ if x > x2 :
701
+ x = x2
690
702
# Use the secant method on the final iteration for high precision.
691
703
yield secant (x1 , x2 , y1 , y2 )
692
704
@@ -799,6 +811,12 @@ def heun_ode_in(
799
811
# Fall-back to the secant method if convergence fails.
800
812
if not is_between (x1 , x , x2 ):
801
813
x = secant (x1 , x2 , y1 , y2 )
814
+ if x1 < x2 :
815
+ if x < x1 :
816
+ x = x1
817
+ else :
818
+ if x > x2 :
819
+ x = x2
802
820
# Use the secant method on the final iteration for high precision.
803
821
return secant (x1 , x2 , y1 , y2 )
804
822
@@ -914,6 +932,12 @@ def heun_ode_iter(
914
932
# Fall-back to the secant method if convergence fails.
915
933
if not is_between (x1 , x , x2 ):
916
934
x = secant (x1 , x2 , y1 , y2 )
935
+ if x1 < x2 :
936
+ if x < x1 :
937
+ x = x1
938
+ else :
939
+ if x > x2 :
940
+ x = x2
917
941
# Use the secant method on the final iteration for high precision.
918
942
yield secant (x1 , x2 , y1 , y2 )
919
943
@@ -1028,6 +1052,12 @@ def midpoint_ode_in(
1028
1052
# Fall-back to the secant method if convergence fails.
1029
1053
if not is_between (x1 , x , x2 ):
1030
1054
x = secant (x1 , x2 , y1 , y2 )
1055
+ if x1 < x2 :
1056
+ if x < x1 :
1057
+ x = x1
1058
+ else :
1059
+ if x > x2 :
1060
+ x = x2
1031
1061
# Use the secant method on the final iteration for high precision.
1032
1062
return secant (x1 , x2 , y1 , y2 )
1033
1063
@@ -1149,6 +1179,12 @@ def midpoint_ode_iter(
1149
1179
# Fall-back to the secant method if convergence fails.
1150
1180
if not is_between (x1 , x , x2 ):
1151
1181
x = secant (x1 , x2 , y1 , y2 )
1182
+ if x1 < x2 :
1183
+ if x < x1 :
1184
+ x = x1
1185
+ else :
1186
+ if x > x2 :
1187
+ x = x2
1152
1188
# Use the secant method on the final iteration for high precision.
1153
1189
yield secant (x1 , x2 , y1 , y2 )
1154
1190
@@ -1246,6 +1282,12 @@ def newt_ode_in(
1246
1282
# Fall-back to the secant method if convergence fails.
1247
1283
if not is_between (x1 , x , x2 ):
1248
1284
x = secant (x1 , x2 , y1 , y2 )
1285
+ if x1 < x2 :
1286
+ if x < x1 :
1287
+ x = x1
1288
+ else :
1289
+ if x > x2 :
1290
+ x = x2
1249
1291
# Use the secant method on the final iteration for high precision.
1250
1292
return secant (x1 , x2 , y1 , y2 )
1251
1293
@@ -1346,6 +1388,12 @@ def newt_ode_iter(
1346
1388
# Fall-back to the secant method if convergence fails.
1347
1389
if not is_between (x1 , x , x2 ):
1348
1390
x = secant (x1 , x2 , y1 , y2 )
1391
+ if x1 < x2 :
1392
+ if x < x1 :
1393
+ x = x1
1394
+ else :
1395
+ if x > x2 :
1396
+ x = x2
1349
1397
# Use the secant method on the final iteration for high precision.
1350
1398
yield secant (x1 , x2 , y1 , y2 )
1351
1399
@@ -1433,6 +1481,12 @@ def newt_safe_in(
1433
1481
# Fall-back to the secant method if convergence fails.
1434
1482
if not is_between (x1 , x , x2 ):
1435
1483
x = secant (x1 , x2 , y1 , y2 )
1484
+ if x1 < x2 :
1485
+ if x < x1 :
1486
+ x = x1
1487
+ else :
1488
+ if x > x2 :
1489
+ x = x2
1436
1490
# Use the secant method on the final iteration for high precision.
1437
1491
return secant (x1 , x2 , y1 , y2 )
1438
1492
@@ -1523,6 +1577,12 @@ def newt_safe_iter(
1523
1577
# Fall-back to the secant method if convergence fails.
1524
1578
if not is_between (x1 , x , x2 ):
1525
1579
x = secant (x1 , x2 , y1 , y2 )
1580
+ if x1 < x2 :
1581
+ if x < x1 :
1582
+ x = x1
1583
+ else :
1584
+ if x > x2 :
1585
+ x = x2
1526
1586
# Use the secant method on the final iteration for high precision.
1527
1587
yield secant (x1 , x2 , y1 , y2 )
1528
1588
@@ -1643,6 +1703,12 @@ def nonsimple_in(
1643
1703
x2 = x
1644
1704
y2 = y
1645
1705
x = secant (x1 , x2 , y1 , y2 , power )
1706
+ if x1 < x2 :
1707
+ if x < x1 :
1708
+ x = x1
1709
+ else :
1710
+ if x > x2 :
1711
+ x = x2
1646
1712
# Use the secant method on the final iteration for high precision.
1647
1713
if 0.6 < power < 1.4 :
1648
1714
return secant (x1 , x2 , y1 , y2 )
@@ -1769,6 +1835,12 @@ def nonsimple_iter(
1769
1835
x2 = x
1770
1836
y2 = y
1771
1837
x = secant (x1 , x2 , y1 , y2 , power )
1838
+ if x1 < x2 :
1839
+ if x < x1 :
1840
+ x = x1
1841
+ else :
1842
+ if x > x2 :
1843
+ x = x2
1772
1844
# Use the secant method on the final iteration for high precision.
1773
1845
if 0.6 < power < 1.4 :
1774
1846
yield secant (x1 , x2 , y1 , y2 )
@@ -1873,6 +1945,12 @@ def rk45_ode_in(
1873
1945
# Fall-back to the secant method if convergence fails.
1874
1946
if not is_between (x1 , x , x2 ):
1875
1947
x = secant (x1 , x2 , y1 , y2 )
1948
+ if x1 < x2 :
1949
+ if x < x1 :
1950
+ x = x1
1951
+ else :
1952
+ if x > x2 :
1953
+ x = x2
1876
1954
# Use the secant method on the final iteration for high precision.
1877
1955
return secant (x1 , x2 , y1 , y2 )
1878
1956
@@ -1977,6 +2055,12 @@ def rk45_ode_iter(
1977
2055
# Fall-back to the secant method if convergence fails.
1978
2056
if not is_between (x1 , x , x2 ):
1979
2057
x = secant (x1 , x2 , y1 , y2 )
2058
+ if x1 < x2 :
2059
+ if x < x1 :
2060
+ x = x1
2061
+ else :
2062
+ if x > x2 :
2063
+ x = x2
1980
2064
# Use the secant method on the final iteration for high precision.
1981
2065
yield secant (x1 , x2 , y1 , y2 )
1982
2066
@@ -2080,6 +2164,12 @@ def secant_in(
2080
2164
x2 = x
2081
2165
y2 = y
2082
2166
x = secant (x1 , x2 , y1 , y2 )
2167
+ if x1 < x2 :
2168
+ if x < x1 :
2169
+ x = x1
2170
+ else :
2171
+ if x > x2 :
2172
+ x = x2
2083
2173
# Use the secant method on the final iteration for high precision.
2084
2174
return secant (x1 , x2 , y1 , y2 )
2085
2175
@@ -2186,6 +2276,12 @@ def secant_iter(
2186
2276
x2 = x
2187
2277
y2 = y
2188
2278
x = secant (x1 , x2 , y1 , y2 )
2279
+ if x1 < x2 :
2280
+ if x < x1 :
2281
+ x = x1
2282
+ else :
2283
+ if x > x2 :
2284
+ x = x2
2189
2285
# Use the secant method on the final iteration for high precision.
2190
2286
yield secant (x1 , x2 , y1 , y2 )
2191
2287
0 commit comments