! ! ****** Calculate sine by Talor-series expansion ****** ! program taylor implicit none integer i, n, ns real(8):: dx, xmax, pi real(8), allocatable:: x(:),s1(:),s2(:) real(8):: T_sine character(20):: fmt1 pi = 4.0d0 * atan(1.0d0) fmt1 = '(3f12.7)' write (6,*) 'Input number of samples for 1 period' read (5,*) ns write (6,*) 'Your input for number of samples = ',ns dx = 2.0d0 * pi / dfloat(ns) allocate ( x(0:ns),s1(0:ns),s2(0:ns) ) write (6,*) 'Input maximum order of Taylor series' read (5,*) n write (6,*) 'Your input maximum order of Taylor series = ',n write (6,*) write (6,*) ' x sin(x) T_sine(x)' open (10,file='mysine.dat') do i = 0,ns x(i) = dx * dble(i) s1(i) = dsin(x(i)) s2(i) = T_sine(x(i),n) write ( 6,fmt1) x(i), s1(i), s2(i) write (10,fmt1) x(i), s1(i), s2(i) end do stop end program taylor