How can I escape this loop and draw the diagram? (Find minimum of a function using Bisection method)
Show older comments
I need to find the minimum of the function using Bisection method. And I'm a beginner and this is the code I created. Can you show me the mistakes of this please? I need to draw the graph also.
x = [0,1]
tolerance = E1 = 0.01
thank you.
%% Find the minimum of a function using Bisection method
clc
clear
% Define givens
f = @(x) exp((x.^4 + x.^2 -x + sqrt(5))./5) + sinh((x.^3 + 21.*x + 9)./(21.*x + 6)) -3 ;
a = 0;
b = 1;
E1 = 0.01;
n = E1/10;
while b - a > n
X1 = (a + b)/2 - n ;
X2 = (a + b)/2 + n ;
if f(X1) >= f(X2)
a = X1 ;
else
b = X2 ;
end
Xmin = (X1+X2)/2;
end
L = [a , b];
plot (L,n*1,'black','LineWidth',6)
hold on
grid on
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!