/usr/share/genius/examples/newton-calc-sqrt2.gel is in genius-common 1.0.23-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # Category: Calculus
# Name: Newton's method for sqrt(2)
#
# Calculate some number of iterations of Newton's method for sqrt(2)
# Try different functions here to try to get roots of. Note that
# if genius can't take derivative you can set the derivative function
# df below.
function f(x)=x^2-2;
#initial guess
c1 = 2;
#iterations to run
iters = 9;
# how long to pause after each iteration
thepause = 1;
df = SymbolicDerivative(f);
old_MaxDigits = MaxDigits;
old_FloatPrecision = FloatPrecision;
MaxDigits = 0;
FloatPrecision = 192;
c = c1;
for n = 1 to iters do (
print("c("+n+") = ");
print(float(c));
nc = c-float(f(c)/df(c));
wait(thepause);
c = nc;
);
MaxDigits = old_MaxDigits;
FloatPrecision = old_FloatPrecision;
|