Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [x,y,i] = metodParabola(f,x1,x2,err,maxIter)
- x3 = x2;
- x2 = (x1+x3)/2;
- for i = 1 : maxIter;
- A = [1 x1 x1^2; 1 x2 x2^2; 1 x3 x3^2];
- b = [feval(f,x1); feval(f,x2); feval(f,x3)];
- p = A\b; % koeficijenti zeljene parabole
- xopt = -(p(2)/(2*p(3))); % vrednost optimuma
- y2 = feval(f,x2);
- yopt = feval(f,xopt)
- if( yopt >= y2)
- if ( xopt >= x2 )
- x1 = x1;
- x2 = x2;
- x3 = xopt;
- else
- x1 = xopt;
- x2 = x2;
- x3 = x3;
- end
- else
- if ( xopt >= x2 )
- x1 = x2;
- x2 = xopt;
- x3 = x3;
- else
- x1 = x1;
- x3 = x2;
- x2 = xopt;
- end
- end
- if( abs( polyval(p,xopt) - feval(f,xopt)) <= err)
- x = xopt;
- y = feval(f,xopt);
- break;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement