Question: Please solve this using MATLAB since it requires you to code. Please and thank you! Also this is what I have so far: function [x,fx,ea,iter]

Please solve this using MATLAB since it requires you to code. Please and thank you!

Also this is what I have so far:

function [x,fx,ea,iter] = parainterpmin(f,x1,x2,x3,es,maxit,varargin)

% goldmin: minimization golden section search

% [x.fx,ea,iter] = goldmin(f,xl,xu,es,maxit,p1,p2,...):

% uses golden section search to find minimum of f

% INPUT:

% f = name of function

% xl,xu = lower and upper guesses

% es = desired relative error (default = 0.0001%)

% maxit = maximum allowable iterations (default = 50)

% p1,p2,... = additional parameters used by f

% OUTPUT:

% x = location of minimum

% fx = minimum function value

% ea = approximate relative error (%)

% iter = number of iterations

if nargin

if nargin

if nargin

phi = (1+sqrt(5))/2; % golden ratio

iter = 0; % initialize iteration index

x1new = x1; x2new = x2; x3new = x3;

% ^^ set additional copies of intial brackets (guesses)

x4 = x3; % set new point as intermediate point

while(1)

d = (phi-1)*(xu - xl);

% ^ distance b/w each interior point and the corresponding bracketing

% point

x1 = x1new;x2 = x2new;x3 = x3new; % first (right) interior point

x4old = x4; % second (left) interior point

x4 = x2-1/2*(((x2-x1)^2)*(f(x2)-f(x3))-((x2-3)^2)*(f(x2)-f(x1)))/...

((x2-x1)*(f(x2)-f(x3))-(x2-x3)*(f(x2)-f(x1)));

if x4>x2

if f(x4,varargin{:}) > f(x2,varargin{:})

x1new = x1;x2new = x4;x3new = x3;

end

else

if f(x4,varargin{:}) > f(x2,varargin{:})

x1new = x4;x2new = x4;x3new = x2;

else

x1new = x1;x2new = x4;x3new = x2;

end

end

iter = iter+1; % update iteration index

if x4 ~=0, ea = abs((x4-x4old)/x4);end % evaluate relative error

if ea =maxit,break,end % stopping criterion

end

x = x4; % set the final 'xopt' as the location of the minimum value

fx = f(x4,varargin{:}); % evaluate the optimum or mimimum function value

Please solve this using MATLAB since it requires you to code. Pleaseand thank you! Also this is what I have so far: function

Problem 1: In class, we discussed in detail about the numerical method and the corresponding M-function for the golden-section search to locate the optimum of a function. As an alternative, one can use the so-called parabolic interpolation method to accomplish the same objective, which was also discussed during Lecture 8 (see section 7.2.2 in the textbook along with the accompanying Example 7.3) Write a MATLAB function to implement the parabolic interpolation method for finding a local optimum of any one-dimensional function. The overall structure of the M-function can be taken to be similar to that for the golden-section search function discussed in class (see also "goldmin.m" posted on Canvas under Lecture 8), with the following major differences: (i) The parabolic interpolation method requires three initial guesses x1 , x2 and x3, based on which a new value x4 for the optimum location is determined from Equation (7.10) in the textbook, which is obtained from a parabolic fit. (ii) a strategy is required to determine three new guesses (brackets) x1 , X2 and X3 for the subsequent iteration by discarding one of the points above. These two aspects can be incorporated in your M-function by modifying the following pieces of a code: function [x,fx,ea,iter] parainterpmin(f,x1,x2,x3,es,maxit,varargin) % fill in the details here, such as comments and setting default values, % similar to that in the "goldmin.m" discussed in class-Lecture 8 iter-0; % initialize iteration index x1new-x1; x2new-x2; x3new-x3; % set additional copies of initial brackets (guesses) x4-x3; % set new point as intermediate point while(1) x1-x1new, x2-x2new; x3-x3new; % start with new bracket for each iteration x4old x4; % set previous iteration optimum value (x4) to x4old % parabolic interpolation formula to locate optimum, i.e. min, with bracket (x1,x2,x3) % write formula given in Equation (7.10) in the textbook x4-x2-1/2*( ((x2-x1)A2)*(f(x2)-f(x3)-((x2-x3)A2)*(f(x2)-f(x1)))/ ((x2-x1)*(f(x2)-f(x3))-(x2-x3)*(f(x2)-f(x1))); % strategy to discard a point and determine new brackets if x4 > x2 % new point to the right of intermediate point if f(x4,varargin(:)) > f(x2,varargin{:)) % new brackets (x1,x2,x4) x1new -x1; x2new -x2; x3new -x4; else % new brackets (x2,x4,x3) Problem 1: In class, we discussed in detail about the numerical method and the corresponding M-function for the golden-section search to locate the optimum of a function. As an alternative, one can use the so-called parabolic interpolation method to accomplish the same objective, which was also discussed during Lecture 8 (see section 7.2.2 in the textbook along with the accompanying Example 7.3) Write a MATLAB function to implement the parabolic interpolation method for finding a local optimum of any one-dimensional function. The overall structure of the M-function can be taken to be similar to that for the golden-section search function discussed in class (see also "goldmin.m" posted on Canvas under Lecture 8), with the following major differences: (i) The parabolic interpolation method requires three initial guesses x1 , x2 and x3, based on which a new value x4 for the optimum location is determined from Equation (7.10) in the textbook, which is obtained from a parabolic fit. (ii) a strategy is required to determine three new guesses (brackets) x1 , X2 and X3 for the subsequent iteration by discarding one of the points above. These two aspects can be incorporated in your M-function by modifying the following pieces of a code: function [x,fx,ea,iter] parainterpmin(f,x1,x2,x3,es,maxit,varargin) % fill in the details here, such as comments and setting default values, % similar to that in the "goldmin.m" discussed in class-Lecture 8 iter-0; % initialize iteration index x1new-x1; x2new-x2; x3new-x3; % set additional copies of initial brackets (guesses) x4-x3; % set new point as intermediate point while(1) x1-x1new, x2-x2new; x3-x3new; % start with new bracket for each iteration x4old x4; % set previous iteration optimum value (x4) to x4old % parabolic interpolation formula to locate optimum, i.e. min, with bracket (x1,x2,x3) % write formula given in Equation (7.10) in the textbook x4-x2-1/2*( ((x2-x1)A2)*(f(x2)-f(x3)-((x2-x3)A2)*(f(x2)-f(x1)))/ ((x2-x1)*(f(x2)-f(x3))-(x2-x3)*(f(x2)-f(x1))); % strategy to discard a point and determine new brackets if x4 > x2 % new point to the right of intermediate point if f(x4,varargin(:)) > f(x2,varargin{:)) % new brackets (x1,x2,x4) x1new -x1; x2new -x2; x3new -x4; else % new brackets (x2,x4,x3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!