/usr/share/genius/examples/newton-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 39 40 41 42 43 44 45 | # Category: Calculus
# Name: Newton's method graphically computing sqrt(2)
function f(x)=x^2-2;
c1 = 2;
LinePlotWindow=[1,2.5,-3,4];
df = SymbolicDerivative(f);
LinePlotDrawLegends=false;
LinePlotClear();
PlotWindowPresent(); # Make sure the window is raised
LinePlot(f);
LinePlotDrawLine(c1,-100,c1,100,"color","red","thickness",1);
AskButtons("We're starting with an estimate at x=2","OK");
LinePlot(f,
`(x)=df(c1)*(x-c1)+f(c1));
c2=c1-f(c1)/df(c1);
LinePlotDrawLine(c1,-100,c1,100,"color","black","thickness",1);
LinePlotDrawLine(c2,-100,c2,100,"color","red","thickness",1);
PlotWindowPresent(); # Make sure the window is raised
AskButtons(float(c2)+" (real sqrt(2) is " + sqrt(2) + ")","OK");
LinePlot(f,
`(x)=df(c2)*(x-c2)+f(c2));
c3=c2-f(c2)/df(c2);
LinePlotDrawLine(c1,-100,c1,100,"color","black","thickness",1);
LinePlotDrawLine(c2,-100,c2,100,"color","black","thickness",1);
LinePlotDrawLine(c3,-100,c3,100,"color","red","thickness",1);
PlotWindowPresent(); # Make sure the window is raised
AskButtons(float(c3)+" (real sqrt(2) is " + sqrt(2) + ")","OK");
LinePlot(f,
`(x)=df(c3)*(x-c3)+f(c3));
c4=c3-f(c3)/df(c3);
LinePlotDrawLine(c1,-100,c1,100,"color","black","thickness",1);
LinePlotDrawLine(c2,-100,c2,100,"color","black","thickness",1);
LinePlotDrawLine(c3,-100,c3,100,"color","black","thickness",1);
LinePlotDrawLine(c4,-100,c4,100,"color","red","thickness",1);
PlotWindowPresent(); # Make sure the window is raised
AskButtons(float(c4)+" (real sqrt(2) is " + sqrt(2) + ")","OK");
|