## Problem with cubic spline interplation

## Problem with cubic spline interplation

(OP)

I'm trying to reconstruct a curve with the cubic spline interpolation. I wrote a code that asks me where I want to interpolate, and when I put the value of x, it gives me the value of f(x).

Here there is a piece of my code and I would like to know how to reconstruct the whole curve.

print*,'Where do you want to interpolate?'

read(*,*) int

DO i=2,num

IF (int>=x(i-1) .and. int<=x(i)) then

print*,'x is between ',x(i-1),' and ',x(i)

den=x(i)-x(i-1)

t1=(d2(i-1)/(6.*den))*(x(i)-int)**3+(d2(i)/(6.*den))*(int-x(i-1))**3

t2=(y(i-1)/den -(d2(i-1)*den)/6.)*(x(i)-int)

t3=(y(i)/den -(d2(i)*den)/6.)*(int-x(i-1))

xint=t1+t2+t3

END IF

END DO

print*,xint

END SUBROUTINE spline

I added this to generate all the x that are missing from the data, in order to obtain all the f(x) values and so reconstruct the curve:

nint=100

step=(maxval-minval)/nint

do i=1,nint

xn(i)=x(1)+step*i

print*,i,xn(i)

end do

I can't put them together, can anyone help me?

If it is not clear, I can try to explain it better.

thanks in advance

Here there is a piece of my code and I would like to know how to reconstruct the whole curve.

print*,'Where do you want to interpolate?'

read(*,*) int

DO i=2,num

IF (int>=x(i-1) .and. int<=x(i)) then

print*,'x is between ',x(i-1),' and ',x(i)

den=x(i)-x(i-1)

t1=(d2(i-1)/(6.*den))*(x(i)-int)**3+(d2(i)/(6.*den))*(int-x(i-1))**3

t2=(y(i-1)/den -(d2(i-1)*den)/6.)*(x(i)-int)

t3=(y(i)/den -(d2(i)*den)/6.)*(int-x(i-1))

xint=t1+t2+t3

END IF

END DO

print*,xint

END SUBROUTINE spline

I added this to generate all the x that are missing from the data, in order to obtain all the f(x) values and so reconstruct the curve:

nint=100

step=(maxval-minval)/nint

do i=1,nint

xn(i)=x(1)+step*i

print*,i,xn(i)

end do

I can't put them together, can anyone help me?

If it is not clear, I can try to explain it better.

thanks in advance

## RE: Problem with cubic spline interplation

By the way, for your variable names, try to use something other that Fortran keywords for statements or functions.