Page 560 - Chapra y Canale. Metodos Numericos para Ingenieros 5edición_Neat
P. 560
536 INTERPOLACIÓN
Observe que la subrutina de la figura 18.18 da sólo un valor interpolado, yu, para
un valor dado de la variable dependiente, xu. Ésta es sólo una forma en la cual se puede
implementar la interpolación mediante trazadores. Por ejemplo, a usted deseará deter-
minar los coeficientes una sola vez y, después, realizar muchas interpolaciones. Además,
2
la rutina da tanto la primera (dy) como la segunda derivadas (dy ) en xu. Aunque no es
necesario calcular esas cantidades, son útiles en muchas aplicaciones de la interpolación
mediante trazadores.
FIGURA 18.18
Algoritmo para la interpolación mediante trazadores cúbicos.
SUBROUTINE Spline (x,y,n,xu,yu,dy,d2y) SUBROUTINE Interpol (x,y,n,d2x,xu,yu,dy,d2y)
fl ag = 0
LOCAL e n , f n , g n , r n , d2x n
CALL Tridiag(x,y,n,e,f,g,r) i = 1
CALL Decomp(e,f,g,n–1) DOFOR
CALL Subst(e,f,g,r,n–1,d2x) IF xu ≥ x i–1 AND xu ≤ x i THEN
CALL Interpol(x,y,n,d2x,xu,yu,dy,d2y) c1 = d2x i–1 /6/(x i – x i–1 )
END Spline c2 = d2x i /6/(x i – x i–1 )
c3 = (y i–1 /(x i – x i–1 ) – d2x i–1 * (x i –x i–1 )/6
SUBROUTINE Tridiag (x,y,n,e,f,g,r) c4 = (y i /(x i – x i–1 ) – d2x i * (x i –x i–1 )/6
f 1 – 2 * (x 2 –x 0 ) t1 = c1 * (x i – xu) 3
g 1 – (x 2 –x 1 ) t2 = c2 * (xu – x i–1 ) 3
r 1 – 6/(x 2 –x 1 ) * (y 2 –y 1 ) t3 = c3 * (x i – xu)
r 1 – r 1 +6/(x 1 –x 0 ) * (y 0 –y 1 ) t4 = c4 * (xu – x i–1 )
DOFOR i – 2, n–2 yu = t1 + t2 + t3 + t4
e i – (x i –x i–1 ) t1 = —3 * c1 * (x i – xu) 2
f i – 2 * (x i+1 – x i–1 ) t2 = 3 * c2 * (xu – x i–1 ) 2
g i – (x i+1 – x i ) t3 = –c3
r i – 6/(x i+1 – x i ) * (y i+1 – y i ) t4 = c4
r i – ri+6/(x i – x i–1 ) * (y i–1 – y i ) dy = t1 + t2 + t3 + t4
END DO t1 = 6 * c1 * (x i – xu)
e n–1 = (x n–1 – x n–2 ) t2 = 6 * c2 * (xu – x i–1 )
f n–1 = 2 * (x n – x n–2 ) d2y = t1 + t2
r n–1 = 6/(x n – x n–1 ) * (y n – y n–1 ) fl ag = 1
r n–1 = r n–1 + 6/(x n–1 – x n–2 ) * (y n–2 – y n–1 ) ELSE
END Tridiag i = i + 1
END IF
IF i = n + 1 OR fl ag = 1 EXIT
END DO
IF fl ag = 0 THEN
PRINT “outside range”
pause
END IF
END Interpol
6/12/06 13:57:56
Chapra-18.indd 536 6/12/06 13:57:56
Chapra-18.indd 536

