
! taylor3.tru

def f(x)=sin(x)

dim c(20)

sub coeff
let c(1)=1
for i=2 to 20
 let c(i)=-c(i-1)/((2*i-2)*(2*i-1))
next i
end sub

def p(x,n)   ! x-x^3/3!+x^5/5!...
   let total=0
   for i= 1 to n
     let total=total+c(i)*x^(2*i-1)
   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 = -10
let b =  10
let dx=.01
let xmin = -10
let xmax =  10
let ymin = -2
let ymax =  2
set window xmin,xmax,ymin,ymax
plot xmin,0 ; xmax,0
plot 0,ymin ; 0,ymax
call coeff
let col=0
for n=0 to 20
   let col=col+1
   if col=16 then let col=1
   set color col
   call graphpoly
   call pressreturn
next n
end

! external
sub pressreturn
    get key key
end sub
   

