Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program n101
- integer::i,imax,n,nmax
- real::x0,xk,h,eps,x,u,S,y,d
- print*, 'Input x0,xk,h,eps,nmax'
- read(*,*) x0,xk,h,eps,nmax
- write(*,'(a54)') '| i | xi | ni | yi | d |'
- imax=nint((xk-x0)/h+0.5)
- do i=1,imax
- x=x0+(i-1)*h
- if (abs(x)<=1) then
- u=x**2
- S=x**2
- do n=1,nmax
- if (abs(u)>eps*abs(S)) then
- u=u*(-2*(x**2))/((n+1)*(2*n+1))
- S=S+u
- else
- y=S
- goto 10
- end if
- end do
- write(*,*) 'n>nmax,',y
- stop
- else
- write(*,*) '|x|>1'
- stop
- end if
- 10 d=y-sin(x)**2
- write(*,'("|",I9,"|",f10.3,"|",I10,"|",f10.3,"|",2x,1pe7.0,"|")' ) i,x,n,y,d
- end do
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement