Question

*1. (This problem is to be solved manually, but you can use MATLAB or any other software as a calculator only) Consider the p

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code for Golden section search clear all close all %function for which minimum have to find f-ê(x) 0.65-(0.75./(1+x.2)C-c+1 %counter and error count (C)c error (c)Ferr end fprintf(InTotal number of iterations for getting minima of accuracy 0.0f(x) vs. x plot 0.05 -0.1 0.15 0.2 0.25 -0.3 0.35 051152 25 3354 45 Published with MATLAB R2018a

%Matlab code for Golden section search
clear all
close all
%function for which minimum have to find

f=@(x) 0.65-(0.75./(1+x.^2))-0.65.*x.*atan(1./x);
xx=linspace(0,5,100);
yy=f(xx);

fprintf('Function for finding minima using Golden section method.\n f(x)=')
disp(f)

%plotting of the function
plot(xx,yy)
title('f(x) vs. x plot')
xlabel('x')
ylabel('f(x)')

gr=1/(1.61803398875);
err=1;c=0;
%bracket for Golden section

x_low=0; x_high=5;

%error convergence
cnn=0.005;

fprintf('\nBracket for the minima [%f %f].\n',x_low,x_high)

%Loop for Golden section search method
i=0;
fprintf('All iterations for Golden section method.\n\n')
fprintf('iter cnt \tx_low\tx_high\tx1\tx2\tf(x1)\tf(x2)\n')

%loop for golden section iterations
while err>cnn
    i=i+1;
    x1=x_high-(x_high-x_low)*gr;
    x2=x_low+(x_high-x_low)*gr;
  
  
    fprintf('%d \t%f \t%f \t%f \t%f \t%f \t%f \n',i-1,x_low,x_high,x1,x2,f(x1),f(x2))
  
    if f(x1)<f(x2)
        x_high=x2;
    else
        x_low=x1;
    end
  
    err=abs(x_high-x_low);
    c=c+1;
    %counter and error
    count(c)=c;
    error(c)=err;
    x_h(c)=x_high;
    x_l(c)=x_low;
  
end

fprintf('\nTotal number of iterations for getting minima of accuracy 0.005 is %d.\n',i)

hold on
plot(x1,f(x1),'r*')

%%%%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
*1. (This problem is to be solved manually, but you can use MATLAB or any other software as a calculator only) Consider the problem of finding the minimum of the following function for x>0 0.65an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT