RosettaCodeData/Task/Steffensens-method/EasyLang/steffensens-method.easy

58 lines
1.1 KiB
Text
Raw Permalink Normal View History

2023-09-16 17:28:03 -07:00
func deCasteljau c0 c1 c2 t .
2023-07-01 11:58:00 -04:00
s = 1 - t
c01 = s * c0 + t * c1
c12 = s * c1 + t * c2
2023-09-16 17:28:03 -07:00
return s * c01 + t * c12
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func xConvexLeftPar t .
return deCasteljau 2 (-8) 2 t
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func yConvexRightPar t .
return deCasteljau 1 2 3 t
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func implicitEq x y .
return 5 * x * x + y - 5
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func f t r .
x = xConvexLeftPar t
y = yConvexRightPar t
r = implicitEq x y
return r + t
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func aitken p0 .
p1 = f p0 p1
p2 = f p1 p2
2023-07-01 11:58:00 -04:00
p1m0 = p1 - p0
2023-09-16 17:28:03 -07:00
return p0 - p1m0 * p1m0 / (p2 - 2 * p1 + p0)
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
func steffAitken p0 tol maxiter .
2023-07-01 11:58:00 -04:00
for i to maxiter
2023-09-16 17:28:03 -07:00
p = aitken p0
2023-07-01 11:58:00 -04:00
if abs (p - p0) < tol
2023-09-16 17:28:03 -07:00
return p
2023-07-01 11:58:00 -04:00
.
p0 = p
.
2023-09-16 17:28:03 -07:00
return number "nan"
2023-07-01 11:58:00 -04:00
.
for i to 11
numfmt 1 0
write "t0 = " & t0 & " : "
2023-09-16 17:28:03 -07:00
t = steffAitken t0 0.00000001 1000
2023-07-01 11:58:00 -04:00
numfmt 3 0
if t <> t
# nan
print "no answer"
else
2023-09-16 17:28:03 -07:00
x = xConvexLeftPar t
y = yConvexRightPar t
r = implicitEq x y
2023-07-01 11:58:00 -04:00
if abs r <= 0.000001
print "intersection at (" & x & " " & y & ")"
else
print "spurious solution"
.
.
t0 += 0.1
.