SHARE
TWEET

pr7

starm100 Dec 4th, 2018 (edited) 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function f(x)
  2.     real::f,x
  3.     f=sqrt(x**2+x+1)-sqrt(x**2-x+1)
  4. end function
  5.    
  6.    
  7. program pr7
  8. integer::l,n,i,j,k
  9. real::x0,xk,h,sup=-(10**5),inf=10**5,u,v,t
  10. real,dimension(1:100)::xi,yi !В примере из учебника размер массивов задан, можно сделать динамические
  11. print*, 'input x0,xk,h,l'
  12. read*,x0,xk,h,l
  13. write(*,*) 'i      x      f(x)'
  14. n=nint(((xk-x0)/h+0.5)+1)
  15. do i=1,n
  16.     u=x0+(i-1)*h !из примера
  17.     v=f(u)       !зачем-написано в книге
  18.     xi(i)=u
  19.     yi(i)=v
  20.     write(*,'(I5,2(f7.3))') i,u,v
  21.     if (sup<v) then
  22.         sup=v
  23.     end if
  24.     if (inf>v) then
  25.         inf=v
  26.     end if
  27. end do
  28. t=(sup-inf)/l
  29. write(*,10) sup,inf,t
  30. 10 format (2x,"sup=",f7.3,2x,"inf=",f7.3,2x,"t=",f7.3/7x,"x")
  31. do i=1,n
  32.     k=nint((yi(i)-inf)/t)
  33.     write(*,'(f7.3,"-"\)') xi(i)
  34.     write(*,'(a\)') repeat(" ",k)
  35.     write(*,'(a1)') '*'
  36. end do
  37. write(*,'(a,a\)') repeat(" ",8), repeat("|",nint((yi(n)-inf)/t)+1)
  38. write(*,*) 'y'
  39. write(*,'(2x,f7.3\)') inf
  40. write(*,'(a,f7.3)') repeat(" ",nint((yi(n)-inf)/t)),sup
  41. 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
 
Top