You are on page 1of 16

&

2

spline s( x)S 3 ( n) , n = x i , i=0,1,2,... ,n ,
.
cubicSpl(x,y).
: x
n . , y.
n+2 .
Hermite ( )
x.
s( x i) ,i=0,1,2,. .. , n
.
cubicSpl chck_xy(x,y),
(
x & y).

. (input)
cubicSpl(x,y) x.
chckSort(x),
() x
quicksort(x),
( ,
MatLab1,
).
,
, xx, n ' ,
n '

x.

spline. menu
3 S3 ( n ) (
1...3,
).
spline
xx
1 , R2011b MatLab

spline_a(x,y,xx), spline_b(x,y,xx) & spline_c(x,y,xx),


.
,
Hermite ,
, spline MatLab.
( Splines):
l
n1

l
: s( x)= a x + b (xx v ) .+ . .
=0
=1
splines,
x> x .
n+l . A
= (n+l)(n+l) .
: n+1 , 4
Vandermonde, '
, . :
A (i=1 :n+1, j=1 :4 )= {x ij1 }
spline.

,
:
A (i=2 :n+1, j=l+2 :l+(i1))= {( x i x jl )l }
l1 .
Hermite. ( )
, ( )
spline. , :
(i=n+l1: n+l , j=2 :l+1)={( j1) x (1j2) } ,
(i=n+l , j=l+2 :n+l)={3( x i x k )2 , k =2,... , n } .
A .

.
, :
(1 :n+l2)= y j , j=2,. .. , n+1 ( )
B(n+l1:n+l)= y (1, n+2) ( Hermite).
A gauss_jordan,
=
. splines
3
, s( x )S ( n)
xx .
. , spline_a(x,y,xx)
kampylothta_a
( x) ,

xx .
. n={x , =1,. .. , n} .
s( x )S 3 ( n)
. n
n ,
.
A ,
(
).

x x
xx m
s( x)= y m m+1
+ y m+1
+hm2 q m F (1t)+h m2 q m+1 F (t) ,
hm
hm
xx m
t 3t
t=
, h m= x m+1 x m , m=1,... , n1, F (t)=
. x
hm
6
:
y y
h q
q
s' ( x)= m+1 m + m m {13(1t )2 }+hm m+1 (3t2 1) .
hm
6
6
,
:
h1 q 1 h 1 q 2 y 2 y 1
+
=
1 ,
3
6
h1
hm1 q m1 hm1+h m
h q
y y
y y
+(
)q m + m m+1 = m+1 m m m1 , m=2,... , n1
6
3
6
hm
hm1
q n1 h n1 qn h n1
y y
+
= n n n1 .

6
3
h n1
1 , n , .
n ,
A & AX= B .
spline
spline_b(x,y,xx).
. O A nn
. :
x(2) x(1)
(1, j=1: 2)={
} ( )
3j
x(i)x (i1) ((x(i) x (i1))+( x (i+1) x(i))) x (i+1) x(i)
(i=2 :n1, j=i1:i+1)={
,
,
}
6
3
6
( )
x(i) x(i1) x(i)x(i1)
,
}
6
3
( ).
A (i=n , j=n1:n)={

y (3) y(2)
y(i+2) y(i+1) y(i+1) y(i)

y(1) , B(i=2: n1)=

x(i+1) x(i)
x(i)x(i1)
x(2) x(1)
y(n+1) y(n)
B(i=n)= y(n+2)
.
x(n) x(n1)
B(1)=


y Hermite.

= , ,
. ,
Thomas,
Gauss,
. solve3diag,

. n1 q i , i=1,... , n
.
,

spline .
kampylothta_b
. , ,
(
q i , i=1,... , n ),
[ x i , x i+1 ], i=1,. .. , n1 ( spline),
q i , q i+1 .
. ,
x x i
{t , =0,... , l}, t=
, x[ x i , x i+1 ], hi =x i+ 1 x i , i=1,... , n1 .
hi
, x
t , [ x i , x i+1 ]
[0,1] . ,
= .
4(n1) .
, .
(
2 ),
. , : 2+2 (n2)=2 (n1)
spline ,
2+(n2)=n
( Hermite), n2
.
, 2(n1)+n+(n2)+2=2n2+n+n2=4n4=4(n1)
, .

s( x )S 3 ( n)
spline_c(x,y,xx).
. , x= {x i , i=1,... , n} ,
4(n1) 4(n1) .
.
, 2(n1)
spline
y .
:
A ({i=1,3,... , 2(n1)1}, { j=2(i1)+1})=1
A ({i=2,... , 2(n1)},{ j=2(i2)+1,... , 2(i2)+4})=1
,
x t .
[ x i , x i+1 ], i{1,... , n1} spline ,
x x i
s(t)=a0 +a1 (t)+a2 (t2 )+a 3 (t3 ), t=
, x[ x i , x i+1 ] . spline
x i+1 x i
( x= x i ) s(0)=a 0 ,
, ( x= x i+1 ), s(1)=a 0+a1 +a2+a 3 .
.

n2 .
spline [ x i , x i+1 ], i{2,. .. , n1}
x :
ds ds dt 1
=
= (a +2a 2 t+3a 3 t 2 ), hi =x i+1 x i , i{1,2,... ,n1} ,
dx dt dx hi 1
. spline

x x i1
2
3
[
x
,
x
]
,
, s(t)=b0 +b1 t+b2 t +b 3 t ,t=
.
i1
i
hi1

, : d s = d s dt = 1 (b1 +2b 2 t+3b3 t 2 ) .


dx dt dx hi 1
x i ,

a
: ds (x i )= d s (x i ) 1 = 1 (b1+2b 2+3b3 )
dx
dx
hi h i1
, n2
.
spline
x i ,
2
1
a=
(2b 2+6b 3) .
:
2 2
hi
h i12
2(n2) :
(2(n1)+i{1,3,. .. , 2(n2)1}, { j=2i , ... , 2i+2})=

1
h i1
2

{1,2,3}
+1

&

A (2(n1)+i{1,3,... , 2(n2)1}, { j=2i+4})=

1
h i1
2

+2

,
1
A (2(n1)+i{2,4,... ,2 (n2)}, { j=2(i1)+1,2(i1)+2})= 2 {2,6}
&
hi
2

A (2(n1)+i{2,4,... ,2(n2)}, { j=2(i1)+4})=

2
h i 2
2

+1

. ,
Hermite:
A (i=4 (n1)1, j=2)=1 & A (i=4(n1), { j= 4(n1)2,... , 4(n1)})={1,2,3}
B : 2(n1)
,
:
B(1)= y(2) ,
B({i=2,3,. .. , 2(n1)1})= y (k), k=dv (i+1,2)+(1)md (i ,2) [md(i, 2)+1]+md (i+1,2) 2,
B(i=2(n1))= y (n+1) .
2(n2)
2 .

,
. ,
B(2(n1)+i{1,2,... , 2(n2)})=0
, .
: B(i=4 (n1)1)= y(1), B (i= 4(n1))= y(n+2) .
= ,
,
x x i
2
3
, x[ x i , x i+1 ] .
: s(t)= X 4i +1+ X 4i+2 t+ X 4i+3 t + X 4 (i+1) t , i{1,2,... , n1}, t=
x i+1 x i
spline
xx. , kampylothta_c
spline
.
. ,
,
spline
.
20
[ x i , x i+1 ], i=1,2,... , n1 , xx
20,
( 20) .
2
i

{3,3,4,4,... , n+1, n+1}

.
kampylothta_a(x,xx,q).
splines ( splines).
x , xx
, q
( & splines ).

.m , function handles. ' ,

2 , [ x 1 , x 2 ] .
20 ( ,
) ,
,
[ x i , x i+1 ], i=2,3,... , n1 ,
function handles,
splines.

.
kampylothta_b(x,y,xx,q).
splines.
x,xx & q .
(:
f ' ' (x)
( x)=
3
),
'
2 2
(1+(f (x)) )
spline
s( x i ),i=1,... , n , y .

function handle
,
(
) (
, )
.
kampylothta_c(x,xx,q).

splines. x q .
, q,
function handles ,
spline
. ,
.

.
(output).
cubicSpl
. menu ( MatLab)
spline,
, .
,
xx.
, .

visual(xx,yy,x,y,k,mgn). xx,x,y .
yy spline
xx. k
,
. mgn


(
).
visual.
spline
plot(xx,yy), [ x i , y i ], i=1,2,... , n
plot(x,y,'oc'), .
.
LINES TRIBON. ,

. ,

k.
,
90 .
.

, 90 (

) ,
. rotate.
( )

mgn,
.
( ).
,


(by default, MatLab
).

[ x i , x i+1 ], i=1(1)n1

xx ,
.
,

.
.
,
,
mgn.

=
: cond_a,cond_b & cond_c
splines,
.
, .
,
x. ,
condNum(A)3.
.
gauss_jordan(A,B),

.
, Gauss
Jordan, ,
, ,
( ).
,
chckCond.
25,50,100 , .
, cond_a(x),
cond_b(x), cond_c(x), x .
.

3
condNum.
, .

,
. ,
: 2 ,
3 , 1 .
3
3 s( x)S ( n)
.
, f g [ x 1 , x n ]

n={x i , i=1 (1)n} , : (af +bg)=aT (f )+bT (g), a , b .

x 3 .
splChck.m.
3={1,0,1} , 3 3,
3
s( x i )= x i ,i=1(1)3 .
spline f (x)=x 3 , x[1,1] .
cubicSpl.
, .

spline
.
.
,
Hermite ( ),
[1,8] . ,
. ,
, [0,1] ,[1,8],[8,10] .
.
, [0,1] ,
6={0, 0.095, 0.305,0.51, 0.77,1} , s( x i )={0, 0.38,0.71, 0.855,0.965, 1}, i=1,... ,6 .
Hermite tan(80 o) ,0 ()
, .
, [1,8] , 2={1,8}
s( x i )={1, 1}, i=1,2 . Hermite
. ,
spline .
, [8,10] , 2={8, 10}
s( x i )={1, 0} Hermite 0,tan (25 o )
() .
MatLab,
cubicSpl.
waterline
.
spline
, .
.
:

,
.

Runge
Runge
1
runge.m. ,

2
x +1
[5,5 ] .
5, 5, 25, 125,
625, .
( , '
).

( Hermite)
splines, .

maxElem, max MatLab.

.
1

,
2
x +1
spline
.
,
5h 4 (4)
: f s=
f , h=max =1 (1)n 1 (x +1 x ) .
384
24(110x 25x 4 )
(4)
Runge, f (x)=
, 24
2 5
(1+x )
x=0 . ,
120h 4
. ,
384
.

.
f runge s=


splines.

.

:

, .. ,
.

.
gauss_jordan(A,B):
= (
). Gauss-Jordan,

n n . nm ,
m ,

. '
( ,
(n 3) ),

.
,
.
({i=2,3,... , n},{ j=1,2,... , i1})=d( j ,i) , d( j , i)
j i
( j , i) .

,

. -
.
Gauss-Jordan, nn (
, ),
2
= .
quicksort(x): x.
. , (Pivot)
. , L R.

( ' 2).
L R .

( ).
solve3diag(a,b,c,d):
Thomas.
Gauss. a: , b: ,
c: d:
. ,
(
) ,

, (,

a, '
).
d. ,
x.
Gauss-Jordan (
,
O(n) ).
gauss_jordan, d
, ,
d.
maxElem(x):
x. .
.

. ,

.
chckSort(x): x
. ( )
. ,
.
flag ,
, .
condNum(A):
. ,
.
, 1 gauss_jordan.
normInf
. 2
normInf.
normInf(x):
x. .
, .
rotate(x,fi): x fi.
x 21 .
cos(fi) sin (fi)
, A=

sin (fi) cos(fi)
y=Ax, 21 .
chckSort(x): (
). ( ),

.,
. ,
. , .
binSearch(x,key,imin,imax): key
x. . imin
imax
, .
. ,
.
,
, .