% ECE 111 Lecture #4 % Compute the derivative of y(x) function [dy] = Derivative(x, y) npt = length(x) dy = 0*x; for i=2:npt-1 dy(i) = ( y(i+1)-y(i-1) ) / (x(i+1)-x(i-1)); end dy(1) = (y(2)-y(1))/(x(2)-x(1)); dy(npt) = (y(npt)-y(npt-1))/(x(npt)-x(npt-1)); end