- #1
Galizius
- 14
- 0
Hello I am trying to exchange following code into two functions which I will need to use in further programs.
The code is as follows:
I would like to swap lj and l arrays for the functions. I have tried something like that:
And then I am trying to call it in the main program
But it does not seem to be working as before. What am I doing wrong?
The code is as follows:
Code:
do i=0,k
do j=0,k
if (i/=j) then
lj(i)=lj(i)*((xx-x(i))/(x(j)-x(i)))
end if
enddo
l(i)=l(i)+y(i)*lj(i)
write(2,*) x(i),y(i),l(i)
enddo
I would like to swap lj and l arrays for the functions. I have tried something like that:
Code:
real(8) function lj(j,xx,x,k)
real(8) :: x(1000)
real(8) :: xx
integer :: i,j,k
lj=1.d0
do i=0,k
do j=0,k
if (i/=j) then
lj=lj*((xx-x(i))/(x(j)-x(i)))
end if
enddo
enddo
Code:
real(8) function l(xx,x,y,k)
real(8) :: x(1000),y(1000), xx
integer :: i,j,k
do i=0,k
l=l+y(i)*lj(i,xx,x,k)
enddo
And then I am trying to call it in the main program
Code:
do i=0,k
write(2,*) x(i),y(i),l(x(i),x,y,k)
enddo
But it does not seem to be working as before. What am I doing wrong?
Last edited: