SHARE
TWEET

Untitled

starm100 Dec 10th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program n101
  2. integer::i,imax,n,nmax
  3. real::x0,xk,h,eps,x,u,S,y,d
  4. print*, 'Input x0,xk,h,eps,nmax'
  5. read(*,*) x0,xk,h,eps,nmax
  6. write(*,'(a54)') '|    i    |    xi    |    ni    |    yi    |    d    |'
  7. imax=nint((xk-x0)/h+0.5)
  8. do i=1,imax
  9.     x=x0+(i-1)*h
  10.     if (abs(x)<=1) then  
  11.         u=x**2
  12.         S=x**2
  13.         do n=1,nmax
  14.             if (abs(u)>eps*abs(S)) then
  15.                 u=u*(-2*(x**2))/((n+1)*(2*n+1))
  16.                 S=S+u
  17.             else
  18.                 y=S
  19.                 goto 10
  20.             end if
  21.         end do
  22.         write(*,*) 'n>nmax,',y
  23.         stop
  24.     else
  25.         write(*,*) '|x|>1'
  26.         stop
  27.     end if
  28. 10  d=y-sin(x)**2
  29.     write(*,'("|",I9,"|",f10.3,"|",I10,"|",f10.3,"|",2x,1pe7.0,"|")' ) i,x,n,y,d
  30. end do
  31. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top