Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with cubic spline interplation

Status
Not open for further replies.

JMSchubert

Programmer
Jul 25, 2017
1
IT
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
 
 http://files.engineering.com/getfile.aspx?folder=77bf710e-0adf-4f23-adad-b72f362ba6dc&file=spline.f90
In line 142 if the attached spline.f90 file you have "xn(i)=int", except that "int" has never been initialized nor assigned any value, not before entering the loop, not in the loop, not anywhere.

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

Part and Inventory Search

Sponsor

Back
Top