×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# 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?'

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.

### RE: Problem with cubic spline interplation

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.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!