Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! NAME: T.S.Vilasini
- ! ROLL NUMBER: I14PH010
- ! DATE OF PROGRAM:
- program Lagrange
- integer::n,o,m
- real::a1,a2,a3,a4,a5,p,c,d,b,e,f,a
- dimension x(50),y(50),t1(50),t2(50),t3(50),t4(50),t5(50),temp(5)
- 12 write(*,*),'number of x points'
- read(*,*),n
- write(*,*),'number of y points'
- read(*,*),o
- write(*,*),'values of x'
- do i=1,n
- read(*,*),x(i)
- enddo
- write(*,*),'values of y'
- do i=1,o
- read(*,*),y(i)
- enddo
- write(*,*)'Select 1 if there is a third variable'
- read(*,*),d
- if (d==1) then
- goto 3
- else
- goto 7
- endif
- 3 write(*,*),'values of t1,t2,t3,t4,t5'
- do i=1,n
- read(*,*)t1(i),t2(i),t3(i),t4(i),t5(i)
- enddo
- 1 write(*,*),'x at which calculation is to be done'
- read(*,*),x0
- a=0
- do i = 1,n
- p = 1
- do j = 1,n
- if(i.NE.j)then
- p = p*(x0-x(j))/(x(i)-x(j))
- endif
- enddo
- if(d==1)then
- temp(1) = temp(1)+p*t1(i)
- temp(2) = temp(2)+p*t2(i)
- temp(3) = temp(3)+p*t3(i)
- temp(4) = temp(4)+p*t4(i)
- temp(5) = temp(5)+p*t5(i)
- else
- a = a+p*y(i)
- endif
- enddo
- if(d.NE.1)then
- write(*,*)'value at x =',x0,'is',a
- goto 11
- endif
- 14 write(*,*),'y at which calculation is to be done'
- read(*,*),y0
- a1=0
- a=0
- do i =1,o
- p = 1
- do j = 1,o
- if(i.NE.j)then
- p = p*(y0-y(j))/(y(i)-y(j))
- endif
- enddo
- if(d==1)then
- a1 = a1+p*temp(i)
- else
- a = a+p*x(i)
- endif
- enddo
- if(d==1)then
- write(*,*),'value at x =',x0,'y =',y0,'is',a1
- else
- write(*,*),'value at y =',y0,'is',a
- endif
- 11 write(*,*),'select 1 if further calculations is to be done'
- read(*,*),c
- if (c==1) then
- write(*,*),'reset the values of x and y. If yes then select 1.If not select 0'
- read(*,*),f
- if (f==1) then
- goto 12
- else
- goto 7
- endif
- else
- goto 2
- endif
- 7 write(*,*),'select 1 if calculating x else 0 if calculating y'
- read(*,*),b
- if (b==1) then
- goto 1
- else
- goto 14
- endif
- goto 11
- 2 end program
Add Comment
Please, Sign In to add comment