function [result] = test_function1 (x, n) % test_function1(x,n) calculates the n'th derivative of a test function % for a vector of points x. % % Input arguments: % x = where to evaluate the function or derivative (vector) % n = 0 to return the function value at x, 1 to return the first % derivative, 2 to return the 2nd derivative % Output arguments: % result = value of the function or derivative % % Programmer: Dick Furnstahl furnstahl.1@osu.edu % % Revision history: % 24-Mar-2005 -- original version for Physics 263 % 07-Apr-2005 -- switched to another function (bad first choice) % % Notes: % * This is a MATLAB "function" file like circle_area.m. % * To change the test function, you must insert the correct expression % for the function, first derivative, and second derivative by % hand below. % * In order to handle vectors x, we use ".*" in the function % definition. % * Possible upgrades: % * Can we generate the derivatives symbolically using "diff"? % % calculate the test function or derivative(s) according to the value of n switch n case 0 % calculate the function (the ";" at the end suppresses the output) result = exp(-x); case 1 % calculate the first derivative result = -exp(-x); case 2 % calculate the second derivative result = exp(-x); otherwise % notify the user of an error disp('illegal choice for n') end % this ends the "switch"