File: linapprox.gel

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 25,308 kB
  • sloc: ansic: 75,620; xml: 71,565; sh: 4,445; makefile: 1,927; lex: 523; yacc: 298; perl: 54
file content (37 lines) | stat: -rw-r--r-- 921 bytes parent folder | download | duplicates (4)
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
# Category: Calculus
# Name: Linear approximation by a tangent graphically

function f(x) = sin(ln(x+1))^2;
df = SymbolicDerivative(f);

# Where to approximate
a = 2;

# The approximation
function lf(x) = df(a)*(x-a)+f(a);

function DoGraph(x) = (
  PlotCanvasFreeze();
  LinePlot(f,lf,[-0.5,5,-0.1,2]);
  LinePlotDrawLine(x,0,x,min(f(x),lf(x)),"color","orange");
  LinePlotDrawLine(x,min(f(x),lf(x)),x,max(f(x),lf(x)),"color","red");
  LinePlotDrawLine(-0.5,f(x),5,f(x),"color","black","thickness",1);
  LinePlotDrawLine(-0.5,lf(x),5,lf(x),"color","purple","thickness",1);
  PlotCanvasThaw();
  print("at x=" + x + "  error = |" + lf(x) + " - " + f(x) + "| = " + |lf(x)-f(x)|);
);

PlotWindowPresent(); # Make sure the window is raised

for x=2 to 5 by 0.0222 do (
  DoGraph(x);
  wait(0.003)
);
for x=5 to -0.5 by -0.0222 do (
  DoGraph(x);
  wait(0.06)
);
for x=-0.5 to 2 by 0.0222 do (
  DoGraph(x);
  wait(0.003)
);