Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function p = muller(p0, p1, p2, TOL, N)
- h1 = p1-p0;
- h2 = p2-p1;
- g1 = (f(p1)-f(p0))/h1;
- g2 = (f(p2)-f(p1))/h2;
- d = (g2-g1)/(h2+h1);
- i = 3;
- while i <= N
- b =g2+h2*d;
- D=(b^(2) -4*f(p2)*d)^(1/2);
- if abs(b-D)<abs(b+D)
- E=b+D;
- else
- E=b-D;
- end
- h=-2*f(p2)/E;
- p=p2+h;
- if abs(h)<TOL
- disp(p)
- return
- end
- p0=p1;
- p1=p2;
- p2=p;
- h1=p1-p0;
- h2=p2-p1;
- g1=((f(p1))-(f(p0)))/h1;
- g2=((f(p2))-(f(p1)))/h2;
- d=(g2-g1)/(h2+h1);
- i=i+1;
- end
- disp('Fail')
- function p = secant(p0,p1, TOL, N)
- i=2;
- q0=f(p0);
- q1=f(p1);
- while i<=N
- p = p1-(q1*(p1-p0)/(q1-q0));
- if abs(p-p1)<TOL
- disp(['The error is less than the given tolerance after ' num2str(i) ' iterations'])
- return
- end
- disp(p)
- i = i+1;
- p0=p1;
- p1=p;
- q0=q1;
- q1=f(p);
- end
- disp(['The method failed after ' num2str(N) ' iterations'])
- end
- function y = f(x)
- y = 2.7*(1+x)^(-361)-1;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement