SHARE
TWEET

Untitled

a guest Jun 19th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 2.06733483062522    -0.615946742374531
  2. 2.25465524043858    -0.428626332561163
  3. 1.13788162420748    -1.54539994879227
  4. 1.32520203402085    -1.35807953897890
  5. 0.802454971005455   -1.88082660199429
  6. 0.989775380818824   -1.69350619218092
  7. 0.743382354827609   -1.93989921817214
  8. 0.930702764640978   -1.75257880835877
  9. 0.741429028102197   -1.94185254489755
  10. 0.928749437915565   -1.7545321350841
  11.      
  12. x1 = [2.06733~ ; 2.25465~]
  13.      
  14. % INPUT
  15. % f root function (may be vector valued )
  16. % df derivative of f (or function returning Jacobian matrix )
  17. % x0 initial guess
  18. % tol desired tolerance
  19. % maxIt maximum number of iterations
  20. %
  21. % OUTPUT
  22. % x approximate solution
  23. % success true means converged according to error estimator
  24. % errEst error estimate per iteration
  25. % xHist ( optional ) array with intermediate solutions
  26.  
  27. function [x, success , errEst, xHist ] = newton (f, df, x0 , tol , maxIt )
  28. errEst = []; xHist = [];
  29. for k = 1:1:size(f)
  30.  
  31. iter = 0; err = inf; x = x0; success = false;
  32.  
  33.  
  34. while err > 0 && iter < maxIt
  35.       Fun = f{k}(x);
  36.       Jac = df{k}(x);
  37.       delta = -JacFun;
  38.       err = norm(delta);
  39.       x = x + delta;
  40.       errEst = [errEst; err];
  41.       xHist = [xHist; x];
  42.       iter = iter + 1;
  43. end
  44. end
  45. if err < tol
  46.     success = true;
  47. end
  48.  
  49. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top