
! taylor2.tru

def f(x)=1/(1+x^2)

sub graphfunction
set color "green"
for x=a to b step dx
  plot x,f(x);
next x
plot
end sub

def p(x,n)   ! 1-x^2+x^3+...+x^n
   let total=1
   for i= 1 to n
     let total=total+(-1)^i*x^(2*i)
   next i
   let p=total
end def

sub graphpoly
set color "yellow"
for x=a to b step dx
   plot x,p(x,n);
next x
plot
end sub


set mode "egahires"
let a = -2
let b =  2
let dx=.01
let xmin = -3
let xmax =  3
let ymin = -1
let ymax =  2
set window xmin,xmax,ymin,ymax
plot xmin,0 ; xmax,0
plot 0,ymin ; 0,ymax
call graphfunction
call pressreturn
for n=1 to 20
 call graphpoly
 call pressreturn
next n
end

! external
sub pressreturn
    get key key
end sub
   


