Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1.  
  2. maxIter = 100; %max # of iterations
  3. tol = 10.^-6.; %error tolerance
  4. X = []; %sequence of nodes
  5. a = 6.; %starting point
  6. X(1.) = a;
  7. pw = MypiecewiseFunction(x)
  8. dpw = diff(pw, x)
  9.  
  10. for i = 1:maxIter
  11. X(i+1) = X(i) - (pw(X(i))/dpw(X(i)));
  12. if abs(X(i+1)-X(i)) < tol;
  13. disp(X)
  14. break;
  15. end
  16. end
  17.  
  18.  
  19.  
  20. function pw = MypiecewiseFunction(x)
  21.  
  22. if x<0
  23. pw = -sqrt(-x);
  24. else
  25. pw = sqrt(x);
  26. end
  27.  
  28.  
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement