Introduction to scientific Computing A Matrix Vector Approach Using Matlab Written by Charles FVan Loan 陈文斌 Wbchen(fudan. edu. cn 复日大学
Introduction to Scientific Computing -- A Matrix Vector Approach Using Matlab Written by Charles F.Van Loan 陈 文 斌 Wbchen@fudan.edu.cn 复旦大学
Chapter3 Piecewise polynomial Interpolation Piecewise Linear Interpolation Piecewise Cubic Hermite Interpolation Cubic splines
Chapter3 Piecewise Polynomial Interpolation • Piecewise Linear Interpolation • Piecewise Cubic Hermite Interpolation • Cubic Splines
Piecewise Linear Interpolation 0.8 0.6 0.4 0.2 0.2 -0.4 -0.6 -0.8
0 1 2 3 4 5 6 7 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Piecewise Linear Interpolation
(x,y) L(=)=a+b(-2;) y+1-y i+1 Piecewise Linear L(=)ifx1≤z≤x l()=」L2()x,sz∠3 (=)ifxn-1≤z≤x
( ) ( ) i i i i ( , ) L z = a +b z − z i i x y i i i i i i i x x y y a y b − − = = + + 1 1 , = n− n− n L z x z x L z x z x L z x z x L z 1 1 2 2 3 1 1 2 ( ) if ( ) if ( ) if ( ) Piecewise Linear
for i=1 b(1)=(y(i+1)-y(1)/(x(i+1)-x(1) function [a, b]=pwL(x,y) end n=length(x) a=y(1:n-1) b=(y(2n)y(1:n-1)/(x(2n)-X(1n b= diff(y). /diff(x) b=diff(y). /diff(x) Test code zlinspace(0, 1, 9) la, b=pwL(z, sin(2*pi*z))
function [a,b] = pwL(x,y) n = length(x); a = y(1:n-1); b = diff(y) ./ diff(x); z=linspace(0,1,9); [a,b]=pwL(z,sin(2*pi*z)); for i=1:n-1 b(i)=(y(i+1)- y(i))/ (x(i+1)- x(i)); end b=(y(2:n)-y(1:n-1))./(x(2:n)-x(1:n- 1)) b=diff(y)./diff(x) Test code