) 中图学技术大荸学系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS ●二次插值 x-nu(x-x X-X 0 X-x (x0-x1)(x-x2) X-x 0 X-x l2(x) 2 )(x2-x1) L2(x)=f(x0)(x)+f(x)1(x)+f(x2)2(x)
数 学 系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS ⚫二次插值 1 2 0 0 1 0 2 ( )( ) ( ) ( )( ) x x x x l x x x x x − − = − − 2 0 0 1 1 2 2 L x f x l x f x l x f x l x ( ) ( ) ( ) ( ) ( ) ( ) ( ) = + + 0 2 1 1 0 1 2 ( )( ) ( ) ( )( ) x x x x l x x x x x − − = − − 0 1 2 2 0 2 1 ( )( ) ( ) ( )( ) x x x x l x x x x x − − = − −
中图苔技术大荸数学系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS 例:(-1,2),(0,0),(2,1),(3,3) (x) (x-0)(x-2)(x-3) (x) x+1)(x-2x-3 (-1-0)(-1-2-1-3) (0+1)(0-2)(0-3) l2(x) (x+1)(x-0)(x-3) (2+1)(2-0(2-3) l3(x) (x+1)(x-0(x-2) (3+1)(3-0(3-2) g(x)=2l0(x)+01(x)+12(x)+3/3(x)
数 学 系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS 例: (−1,2),(0,0),(2,1),(3,3) ( 1 0)( 1 2)( 1 3) ( 0)( 2)( 3) ( ) 0 − − − − − − − − − = x x x l x (3 1)(3 0)(3 2) ( 1)( 0)( 2) ( ) 3 + − − + − − = x x x l x (2 1)(2 0)(2 3) ( 1)( 0)( 3) ( ) 2 + − − + − − = x x x l x (0 1)(0 2)(0 3) ( 1)( 2)( 3) ( ) 1 + − − + − − = x x x l x ( ) 2 ( ) 0 ( ) 1 ( ) 3 ( ) 0 1 2 3 g x = l x + l x + l x + l x
中图苔技术大荸数学系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS 算法:L=(xx)…(x-x1)(x=x)…(x=x,) )(x1-x+1)…(x 0.0 for(1=0;i<=ni++) tmp=1.0: for(j=0; j<1,j ++) tmp=tmp*(x-x[D/(xi]) fo(=i+1j<=n1j++) tmp=tmp*(x-xLD/(x[-XLD fxfx+tmp*yi return fx
数 学 系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS 算法: fx=0.0 for(i=0;i<=n;i++) { tmp=1.0; for(j=0;j<i;j++) tmp=tmp*(x-x[j])/(x[i]-x[j]); for(j=i+1;j<=n;j++) tmp=tmp*(x-x[j])/(x[i]-x[j]); fx=fx+tmp*y[i]; } return fx; 0 1 1 0 1 1 ( ) ( )( ) ( ) ( ) ( )( ) ( ) i i n i i i i i i i n x x x x x x x x l x x x x x x x x − + − + − − − − = − − − −
) 中图学技术大荸学系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS Lab02 Lagrange插值 对函数f(x)=,2,x∈[-5,5构造插值,并求 1+x max f(x)-p(x)x max f(y)-plyil,y -5.i=0.…500 50 为近似的误差。插值节点取为: 10 (1)x=-5+x1=0,…N N Chebyshev点 2i+1 -5 cos 丌|,i=0,1,…N 2N+2 对N=5,10,20,40比较以上两组节点的结果
数 学 系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS Lab02 Lagrange插值 2 1 ( ) , [ 5,5] 1 f x x x = − + 对函数 构造插值,并求 5 5 max ( ) ( ) max ( ) ( ) , 5, 0, 500 50 i i i x i i f x p x f y p y y i − − − = − = 为近似的误差。插值节点取为: 10 5 , 0,1, i x i i N N (1) = − + = 2 1 5cos , 0,1, 2 2 i i x i N N + = − = + (2) 对N=5,10,20,40比较以上两组节点的结果。 Chebyshev点
) 中图学技术大荸学系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS Sample Output( represents a space) 第1组节点,误差为 n=5■,■0.244934066848e+001 n=10■,■0.534607244904e+001 第2组节点,误差为 n=5■,■0.244934066848e1+001 n=10■,■0.534607244904e+001
数 学 系 University of Science and Technology of China DEPARTMENT OF MATHEMATICS Sample Output ( represents a space) 第1组节点,误差为 n=5,0.244934066848e+001 n=10,0.534607244904e+001 ... 第2组节点,误差为 n=5,0.244934066848e+001 n=10,0.534607244904e+001