Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- maxIter = 100; %max # of iterations
- tol = 10.^-6.; %error tolerance
- X = []; %sequence of nodes
- a = 6.; %starting point
- X(1.) = a;
- pw = MypiecewiseFunction(x)
- dpw = diff(pw, x)
- for i = 1:maxIter
- X(i+1) = X(i) - (pw(X(i))/dpw(X(i)));
- if abs(X(i+1)-X(i)) < tol;
- disp(X)
- break;
- end
- end
- function pw = MypiecewiseFunction(x)
- if x<0
- pw = -sqrt(-x);
- else
- pw = sqrt(x);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement