Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -28,18 +28,16 @@ func aitken p0 .
func steffAitken p0 tol maxiter .
for i to maxiter
p = aitken p0
if abs (p - p0) < tol
return p
.
if abs (p - p0) < tol : return p
p0 = p
.
return number "nan"
.
for i to 11
numfmt 1 0
numfmt 0 1
write "t0 = " & t0 & " : "
t = steffAitken t0 0.00000001 1000
numfmt 3 0
numfmt 0 3
if t <> t
# nan
print "no answer"

View file

@ -0,0 +1,69 @@
use std::f64;
fn aitken(f: fn(f64) -> f64, p0: f64) -> f64 {
let p1 = f(p0);
let p2 = f(p1);
let p1m0 = p1 - p0;
p0 - p1m0 * p1m0 / (p2 - 2.0 * p1 + p0)
}
fn steffensen_aitken(f: fn(f64) -> f64, pinit: f64, tol: f64, maxiter: i32) -> f64 {
let mut p0 = pinit;
let mut p = aitken(f, p0);
let mut iter = 1;
while (p - p0).abs() > tol && iter < maxiter {
p0 = p;
p = aitken(f, p0);
iter += 1;
}
if (p - p0).abs() > tol {
f64::NAN
} else {
p
}
}
fn de_casteljau(c0: f64, c1: f64, c2: f64, t: f64) -> f64 {
let s = 1.0 - t;
let c01 = s * c0 + t * c1;
let c12 = s * c1 + t * c2;
s * c01 + t * c12
}
fn x_convex_left_parabola(t: f64) -> f64 {
de_casteljau(2.0, -8.0, 2.0, t)
}
fn y_convex_right_parabola(t: f64) -> f64 {
de_casteljau(1.0, 2.0, 3.0, t)
}
fn implicit_equation(x: f64, y: f64) -> f64 {
5.0 * x * x + y - 5.0
}
fn f(t: f64) -> f64 {
let x = x_convex_left_parabola(t);
let y = y_convex_right_parabola(t);
implicit_equation(x, y) + t
}
fn main() {
let mut t0 = 0.0;
for _i in 0..11 {
print!("t0 = {:.1} : ", t0);
let t = steffensen_aitken(f, t0, 0.00000001, 1000);
if t.is_nan() {
println!("no answer");
} else {
let x = x_convex_left_parabola(t);
let y = y_convex_right_parabola(t);
if implicit_equation(x, y).abs() <= 0.000001 {
println!("intersection at ({}, {})", x, y);
} else {
println!("spurious solution");
}
}
t0 += 0.1;
}
}