clear all
xpoints=linspace(-1,1,51)’;
ypoints=exp(xpoints).*sin(5*xpoints);
n=length(xpoints)-1; %order of polynomial
xint=-1:0.01:1;
yreal=exp(xint).*sin(5*xint);
dyreal=exp(xint).*(sin(5*xint)+5*cos(5*xint));
figure(1)
hold off
plot(xpoints,ypoints,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’r’)
hold on
plot(xint,yreal,’k-‘,’Linewidth’,4)
xlabel(‘x’);ylabel(‘f(x)’)
D=DerivMatrix2ndOrderCDA(xpoints,n)
derivypoints=D*ypoints;
figure(2)
hold off
plot(xint,dyreal,’k-‘,’Linewidth’,4)
hold on
plot(xpoints,derivypoints,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’b’)
xlabel(‘x’);ylabel(‘df(x)/dx’)
function D=DerivMatrix2ndOrderCDA(x,n)
D=zeros(n+1,n+1);
Delta=x(2)-x(1);
D(1,1)=;
D(1,2)=;
for i=2:n
D(i,i-1)=;
D(i,i+1)=;
end
D(n+1,n)=;
D(n+1,n+1)=;
end