% Matlab script der_script_template % Finds numerical derivative of y = x.*2 % Steve Martel % Date 8_26_04 % Set the increment dx dx = 0.01; % Set the domain of x (let x range from 0 to 10) x = 0:dx:10; % Determine how many values of x there are n = ; % Break the set of x-values into two sets, % one that has all values but the last, % the other that has all values but the first x_beg = ; x_end = ; % Find the x-midpoints x_mid = ; % Calculate y at the values of x, x_beg, and x_end y = ; y_beg = ; y_end = ; % Find the slope using the values for y_beg, y_end, and dx slope = ; % Plot figures % Open up a figure window called "figure 1" figure(1) % Clear the figure clf % Plot the curve y = x.^2 on figure 1 plot(x,y) % Keep the figure window to plot another curve hold on % Plot a red stairstep approximation of the curve stairs(x,y,'r') % Add title and labels to axes title('y=x^2') xlabel('x') ylabel('y') % Open up a figure window called "figure 2" figure(2) % Clear the figure clf % Plot the analytical solution for the slope plot(x,2*x) % Keep the figure window to plot another curve hold on % Plot the approximate slope of the curve y = x.^2 on figure 2 plot(x_end,junk,'r'); % Add title and labels to axes title('Slope for the curve y=x^2 and numerical approximation (red)') xlabel('x') ylabel('y')