Problem 5 (computer) An aerodynamic equation for free fall that includes the effects of air resistance tells us that tha
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem 5 (computer) An aerodynamic equation for free fall that includes the effects of air resistance tells us that tha
9.1 Newton's method $rootNewton.m 2014-06-04, Scott Hudson $ Implements Newton's method for finding a root f(x) = 0. Requires two functions: y=f(x) and y=fp (x) where fp (x) is the derivative of f(x). Search starts at x0. Root is returned as r. $888 function r = rootNewton (x0, f, fp, tol) MAX_ITERS = 40; give up after this many iterations nIters = 1; 1st iteration. r = x0-f(x0) /fp (x0); %%Newton's formula for next root estimate while (abs (r-x0) >tol) & (nIters<-MAX_ITERS) nIters nIters+1; keep track of # of iterations x0= r; current root estimate is last output of formula r = x0-f(x0) / fp (x0); Newton's formula for next root estimate end end 9.2 Secant method 8888 rootSecant.m ** 2014-06-04, Scott Hudson Implements secant method for finding a root f(x) = 0. * Requires two initial x values: x1 and x2. Root is returned as r accurate to (hopefully) about tol. function r root Secant (x1, x2, f, tol) MAX_ITERS = 40; nIters = 1; fx2= f(x2); r = x2-fx2* (x2-x1) / (fx2-f(x1)); while (abs (r-x2) >tol) & (nIters<-MAX_ITERS) nIters+1; nIters x1 = x2; end &maximum number of iterations allowed 1st iteration fx1 = fx2; x2 = x; fx2= f(x2); r = x2-fx2* (x2-x1) / (fx2-fx1); end