Please solve the following in MATLAB Please add the comments

Please solve the following in MATLAB. Please add the comments in each line and provide the coding window and the command window. Try to make the codes as universal as possible. Write a function file that performs the golden-section search and determine the maxima, minima, and inflection points for the following function over the range from 0 to 4. Determine what your inputs and outputs should be x^6 - 10x^5 + 36x^4 - 58x^3 + 43x^2 -12x-13

Solution

function [a,b] = gss(f,a,b,eps,N) % % Performs golden section search on the function f. % Assumptions: f is continuous on [a,b]; and % f has only one minimum in [a,b]. % No more than N function evaluation are done. % When b-a < eps, the iteration stops. % % Example : % [a,b] = gss(\'myfun\',0,1,0.01,20) % c = (-1+sqrt(5))/2; x1 = c*a + (1-c)*b; fx1 = feval(f,x1); x2 = (1-c)*a + c*b; fx2 = feval(f,x2); fprintf(\'------------------------------------------------------\ \'); fprintf(\' x1 x2 f(x1) f(x2) b - a\ \'); fprintf(\'------------------------------------------------------\ \'); fprintf(\'%.4e %.4e %.4e %.4e %.4e\ \', x1, x2, fx1, fx2, b-a); for i = 1:N-2 if fx1 < fx2 b = x2; x2 = x1; fx2 = fx1; x1 = c*a + (1-c)*b; fx1 = feval(f,x1); else a = x1; x1 = x2; fx1 = fx2; x2 = (1-c)*a + c*b; fx2 = feval(f,x2); end; fprintf(\'%.4e %.4e %.4e %.4e %.4e\ \', x1, x2, fx1, fx2, b-a); if (abs(b-a) < eps) fprintf(\'succeeded after %d steps\ \', i); return; end; end; fprintf(\'failed requirements after %d steps\ \', N);
 Please solve the following in MATLAB. Please add the comments in each line and provide the coding window and the command window. Try to make the codes as unive

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site