Question

In: Computer Science

Optimization Technique: Consider one-variable function f(x). Use Newton Method to find minimum/maximum and plot the graph....

Optimization Technique: Consider one-variable function f(x). Use Newton Method to find minimum/maximum and plot the graph. Use Matlab.

Solutions

Expert Solution

clear;

close all;

clc;

f1 = @(x) exp(2*sin(x))-x; // %function //

x0 = 3;    // %initial guess //

maxIter = 1e6;    // %max iteration of the function //

epsilon = 10e-6; // %tolerance value //

[xk,i,error,errorVect] = NewtonsMethod(x0,maxIter,epsilon);    //% Calling the Newton's Method function //

fprintf('\nThe solution of the function exp(2*sin(x))-x = 0 is %4.5f in %u iteration with %e error.\n', xk,i,error)

xk; // % Printing Newton's Method Results in the console //

ymin = f1(xk);

errorVect;

//% Function for Newton's Method function //

// %Graphing the error vector //

x_axis = 1:1:length(errorVect);    // %x-axis values //

semilogy(x_axis,errorVect,'-mo'); // %graph of error vector in logarithmic y-axis //

grid on // %logarithmic grid (y-axis only) //

function[xk,i,error,errorVect] = NewtonsMethod(xk,maxIter,epsilon)

xold = xk;

for i = 1:maxIter

[f1x,df1x,ddf1x]=myfunction(xk);

xk = xk - (df1x/ddf1x);

error = abs(xk-xold);

xold = xk;

errorVect(i) = error;

if (error<epsilon)

break;

end

end

end

   //% Function for calling the value and the derivative of the function//

function [f,g,h] = myfunction(x)

f1 = @(z) exp(2*sin(z))-z;    // %function //

dx = 0.1;

ff = f1([x-dx, x, x+dx]); // % this is a 3-element vector //

f = ff(2);    // % the middle value is f1(x) //

if nargout > 1   // % (not sure why you use this) //

gg = diff(ff)./dx; // % this is a 2-element vector from diff(ff) //

g = gg(1);

h= diff(gg)./dx; // % single value from diff(gg) //

end

end


Related Solutions

7. Find the maximum and minimum of the function. f (x, y) = x^ 2 +...
7. Find the maximum and minimum of the function. f (x, y) = x^ 2 + y^ 2 − xy − 3x − 3y on the triangle D ={(x, y)| x ≥ 0, y ≥ 0, x + y ≤ 4}
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x),...
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x), 0 ≤ x ≤ π; correct to six decimal places.
Find the absolute maximum and the absolute minimum of the function f(x,y) = 6 - x²...
Find the absolute maximum and the absolute minimum of the function f(x,y) = 6 - x² - y² over the region R = {(x,y) | -2 <= x <= 2, -1 <= y <= 1 }. Also mention the points at which the maximum and minimum will occur.
Find the relative maximum and minimum value if the following one variable function (If there is...
Find the relative maximum and minimum value if the following one variable function (If there is any): a) y = x^2 + 2x + 1 b) y = 6x^2 - 12x c) y = x^2 + 2x + 1 d) y = x^4
Find the absolute maximum and minimum values for the function f(x, y) = xy on the...
Find the absolute maximum and minimum values for the function f(x, y) = xy on the rectangle R defined by −8 ≤ x ≤ 8, −8 ≤ y ≤ 8.
Find the maximum and minimum and draw the graph of f(x) = 4x 2 - 40x + 80, for x = [0,8].
Find the maximum and minimum and draw the graph of f(x) = 4x 2 - 40x + 80, for x = [0,8].
Find the absolute maximum and minimum values of the function f(x, y) = x^2 + ((4/3)...
Find the absolute maximum and minimum values of the function f(x, y) = x^2 + ((4/3) y^3) − 1 on the disk x^2 + y^2 ≤ 1.
Find the absolute maximum and minimum values of the function f(x)=x^6 e^(−x) on the interval [−3,9]
Find the absolute maximum and minimum values of the function f(x)=x^6 e^(−x) on the interval [−3,9]
Find the global maximum and global minimum of the function f(x, y) = y^2 − 2xy...
Find the global maximum and global minimum of the function f(x, y) = y^2 − 2xy + 4y on the square 1 ≤ x ≤ 3, 0 ≤ y ≤ 2.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT