%% Lecture 7 % % Last week. % .) Newton's method. % .) Stopping conditions. % % This week, what if you can't compute the derivative of the function % analytically? % estimating the derivative. % why you might want to "smooth" first. % This continues the exploration of % "Finding the roots of an equation", finding the % values x such that f(x) = 0. % Last time, we had a function in matlab: function x = newton(x0) % % Special case coded for function y = x.^2 + 2x - 14 x = x0; y = x.^2 + 2*x - 14; % next class, when y = foo(x); while abs(y) > 0.01 % solve for value y = f(x0); y = x.^2 + 2*x - 14; % solve for value of y' = df(x0)/dx yprime = 2*x + 2; % solve for offset = -y / yprime offset = -y / yprime; x = x + offset end % 1) which line here computes the derivative of the function? % 2) Suppose we don't know the derivative, what could we do? % 3) "estimate derivative" procedure %%% what parameters should it take? % 4) Could we make a function that does this generically (for any function?) % the "feval" function in matlab % picture on the board of the numberical derivative? % 5) Write "function dydx = numericalDerivative(foo,x,step); %%%%%%%%%%%%% Numerical Integration % how could we do generic numerical integration? % Trapezoidal rule? % "left side of the rectangle rule? %%%%%%%%%%%%% Why do we work so hard to think about generic function? % to give insight in how matlab uses them. For many things: % find x s.t. f(x) = 0 %fsolve %fminbnd %fminsearch %"differential equation solvers..."