In this problem, you will be creating the function globalmin that uses MATLAB to
ID: 3885593 • Letter: I
Question
In this problem, you will be creating the function globalmin that uses MATLAB to approximate the global minimum of a function within a given domain, and the index of that global minimum. Inputs Func - an arbitrary function. eg. @(x) x.^2 + 4 xStart - The first x value in the function domain xEnd - The last x value in the function domain Outputs: yMin -- The global minimum of the function within a given domain index -- The index for the global minimum of the function (i.e. in what position of the y vector was yMax located?) 1. Create an x vector with 668 elements in it that starts at xStart and finishes at xEnd. 2. Create a y vector which is the input function with the x vector as an input (ie, y = Func(x)). 3. Apply MATLAB's in-built min function to solve y. 4. Apply MATLAB's in-built find function to solve index. Function Template: function [yMin, index] = globalmin(Func, xStart, xEnd) %INSERT CODE endExplanation / Answer
globalmin.m file
function [yMin,index] = globalmin(Func,xStart,xEnd)
% create a vector betwen xStart and xEnd with 668 elements
x = linspace(xStart,xEnd,668);
%pass the vector x to Func
y = Func(x);
%get min from y
yMin = min(y)
% find index of min in y
index = find(y=yMin)
end
main.m file
%anonymus function
Func = @(x) x.^2+4;
%calling function globalmin
globalmin(Func,1,668)
%output
% yMin = 5
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.