Please do code for this matlab
MCE 505 Spring 2023 - Project 04 Submitted by Bhaumik patel(CSU ID:-2863859) Table of Contents Problem 1: One dimensional minimization............................................................................................................... 1 Solutions:..................................................................................................................................................................1 Problem 1: One dimensional minimization Problem statement Write two solvers: • one that finds the minimum of a function f(x) using the golden section search method • one that finds the minimum of a function f(x) using the parabolic interpolation method A suitable API might be: [x, ux] = solver(func, a, b, c, niterations) with inputs: function handle, initial bracket a,b,c, and the number of iterations. The outputs are the location of the minimum (x) and the uncertainty which is the size of the final bracket. Define a test problem, show that the solvers work. For each solver, try to determine the convergence rate (defined as in Module 3). According to the textbook, the golden section search method has a linear convergence, and the parabolic interpolation method should be supralinear (a higher exponent than 1). Solutions: f = @(x) x.^2 - 2*x + 1 f = function_handle with value: @(x)x.^2-2*x+1 a = -1; b = 2; c = 4; niterations = 20; [xgs, uxgs] = buggumethod(f, a, b, c, niterations) xgs = 1.0000 uxgs = 1.9832e-04 [xpi, uxpi] = parabolic_interpolation(f, a, b, c, niterations) xpi = 0.0020 uxpi = 0.0029 fprintf(' buggumethod:\n') buggumethod: 1 fprintf('x = .6f, uncertainty = .6f') x = .6f, uncertainty = .6f function [x, ux] = buggumethod(func, a, b, c, niterations) phi = (1 + sqrt(5))/2; % golden ratio x1 = b - (b-a)/phi; x2 = a + (b-a)/phi; fx1 = func(x1); fx2 = func(x2); for i = 1:niterations if fx1 < fx2="" b="x2;" x2="x1;" fx2="fx1;" x1="b" -="" (b-a)/phi;="" fx1="func(x1);" else="" a="x1;" x1="x2;" fx1="fx2;" x2="a" +="" (b-a)/phi;="" fx2="func(x2);" end="" end="" x="(a+b)/2;" ux="b-a;" end="" function="" [x,="" ux]="parabolic_interpolation(func," a,="" b,="" c,="" niterations)="" fa="func(a);" fb="func(b);" fc="func(c);" for="" i="1:niterations" denom="(b-a)*(b-c)*(c-a);" num="b^2*(fa-fc)" +="" c^2*(fb-fa)="" +="" a^2*(fc-fb);="" x="0.5*num/denom;" if="" x="">< a="" ||="" x=""> c x = (a + c)/2; end fx = func(x); 2 if x < b="" if="" fx="">< fb="" c="b;" b="x;" else="" a="x;" end="" else="" if="" fx="">< fb a = b; b = x; else c = x; end end end ux = c-a; end 3 fb="" a="b;" b="x;" else="" c="x;" end="" end="" end="" ux="c-a;" end=""> fb a = b; b = x; else c = x; end end end ux = c-a; end 3>