NB. Find 2nd derivatives for spline fit. NB. Usage: x spline y --> D spline=: dyad define h2=. }. h=. DEL x a=. 0.5 - c=. -: h2 * hh=. % h2 + }:h b=. 1#~#c u=. 3*hh*DEL (DEL y)%h 0,(tridgl a;b;c;u),0 ) NB. Solve tridiagonal system by direct substitution. NB. Rows are a_i*x_(i-1)+b_i*x_i+c_i*x_(i+1) = u_i NB. a,b,c,u have same length, i.e., a[0]=0 and c[n]=0. NB. Usage: soln <-- tridgl a;b;c;u NB. tridgl=: monad define 'a b c u'=. y n1=. <: n=. <: #b x=. %{.b c=. (x*{.c) 0}c u=. (x*{.u) 0}u j=. 0 while. n1>:j=.>:j do. x=. %(j{b)-(j{a)*((<:j){c) c=. (x*j{c)j}c u=. (x*(j{u)-(j{a)*((<:j){u))j}u end. u=. (((n{u)-(n{a)*(n1{u))%(n{b)-(n{a)*(n1{c))n}u j=. n while. 0<:j=.<:j do. u=. ((j{u)-(j{c)*((>:j){u))j}u end. )