KMU206 Numerical Analysis Instructor: Dr. Selis Önel
HOMEWORK 5 Print and submit to the course instructor
|
Q1. Consider data points (0,0), (1,1), (2,4), (3,3) and apply piecewise polynomial interpoplation:
§ Set up the linear system of equations using piecewise quadratic interpolation
§ Place knots at the midpoints of the data intervals
§ Show all your equations
§ Set up the linear equations in matrix form [A][c]=[y]
§ Determine the coefficients [c] of the linear system ( [c]=[A]\[y] )
§ Write the interpolating piecewise polynomial for each data interval
§ Write a script in MATLAB® to plot a graph of the interpolating polynomials in each interval
§ Copy the script and the graph on a word document, print and submit with the homework
For example:
%plotting the quadratic piecewise polynomial solution
format short
syms x
xi=[0;1;2;3]; yi=[0;1;4;3];
A=[1 -1 0 0 2 0; 0 1 -1 0 2 2; 0 0 1 -1 0 2; 1 1 0 0 -1 0; 0 1 1 0 1 -1; 0 0 1 1 0 1];
r=[4;12;-4;0;0;0];
c=A\r; %since b1=0 and b4=0:
c=[c(1); c(2); c(3); c(4); 0; c(5); c(6); 0];
n=length(xi);
for k=1:n,
if k<n, h(k)=(xi(k)+xi(k+1))/2;end
a(k)=c(k); b(k)=c(k+n); C(k)=yi(k);
P(k)=c(k)*(x-xi(k))^2+b(k)*(x-xi(k))+C(k);
end
h1=[xi(1):.01:h(1)]; h2=[h(1):.01:h(2)];
h3=[h(2):.01:h(3)]; h4=[h(3):.01:xi(4)];
plot(h1,subs(P(1),h1),h2,subs(P(2),h2),h3,…
subs(P(3),h3),h4,subs(P(4),h4),xi,yi,'*m')
legend('P1','P2','P3','P4','Data points',4);
xlabel('x'); ylabel('y');
grid on