vilasini97

Untitled

Sep 3rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! NAME: T.S.Vilasini
  2. ! ROLL NUMBER: I14PH010  
  3. ! DATE OF PROGRAM:
  4. program Lagrange
  5. integer::n,o,m
  6. real::a1,a2,a3,a4,a5,p,c,d,b,e,f,a
  7. dimension x(50),y(50),t1(50),t2(50),t3(50),t4(50),t5(50),temp(5)
  8.  
  9. 12 write(*,*),'number of x points'
  10. read(*,*),n
  11.  
  12. write(*,*),'number of y points'
  13. read(*,*),o
  14.  
  15. write(*,*),'values of x'
  16. do i=1,n
  17.     read(*,*),x(i)
  18. enddo
  19.  
  20. write(*,*),'values of y'
  21. do i=1,o
  22.     read(*,*),y(i)
  23. enddo
  24.  
  25. write(*,*)'Select 1 if there is a third variable'
  26. read(*,*),d
  27.  
  28. if (d==1) then
  29.     goto 3
  30. else
  31.     goto 7
  32. endif
  33.  
  34. 3 write(*,*),'values of t1,t2,t3,t4,t5'
  35. do i=1,n
  36.     read(*,*)t1(i),t2(i),t3(i),t4(i),t5(i) 
  37. enddo
  38.  
  39. 1 write(*,*),'x at which calculation is to be done'
  40. read(*,*),x0
  41. a=0
  42. do i = 1,n
  43.     p = 1
  44.     do j = 1,n
  45.     if(i.NE.j)then
  46.         p = p*(x0-x(j))/(x(i)-x(j))
  47.     endif
  48.     enddo
  49.     if(d==1)then
  50.         temp(1) = temp(1)+p*t1(i)
  51.         temp(2) = temp(2)+p*t2(i)
  52.         temp(3) = temp(3)+p*t3(i)
  53.         temp(4) = temp(4)+p*t4(i)
  54.         temp(5) = temp(5)+p*t5(i)
  55.     else
  56.         a = a+p*y(i)
  57.        
  58.     endif  
  59. enddo
  60.  
  61. if(d.NE.1)then
  62. write(*,*)'value at x =',x0,'is',a
  63. goto 11
  64. endif
  65.  
  66. 14 write(*,*),'y at which calculation is to be done'
  67. read(*,*),y0
  68. a1=0
  69. a=0
  70.  
  71. do i =1,o
  72.     p = 1
  73.     do j = 1,o
  74.     if(i.NE.j)then
  75.         p = p*(y0-y(j))/(y(i)-y(j))
  76.     endif
  77.     enddo
  78.     if(d==1)then
  79.         a1 = a1+p*temp(i)
  80.     else
  81.         a = a+p*x(i)
  82.     endif
  83. enddo
  84.  
  85. if(d==1)then
  86.         write(*,*),'value at x =',x0,'y =',y0,'is',a1
  87.     else
  88.         write(*,*),'value at y =',y0,'is',a
  89.     endif
  90.  
  91. 11 write(*,*),'select 1 if further calculations is to be done'
  92. read(*,*),c
  93.  
  94. if (c==1) then
  95.     write(*,*),'reset the values of x and y. If yes then select 1.If not select 0'
  96.     read(*,*),f
  97.     if (f==1) then
  98.         goto 12
  99.     else
  100.         goto 7 
  101.     endif
  102. else
  103.     goto 2
  104. endif
  105.  
  106. 7 write(*,*),'select 1 if calculating x else 0 if calculating y'
  107. read(*,*),b
  108. if (b==1) then
  109.     goto 1
  110. else
  111.     goto 14
  112. endif
  113.  
  114. goto 11
  115.  
  116. 2 end program
Add Comment
Please, Sign In to add comment