How to run exp in bisection method

2 views (last 30 days)
Nadiah
Nadiah on 21 Jun 2022
Commented: James Tursa on 21 Jun 2022

How to find the root of e^x-x^2+3x-2=0 by using bisection method using Matlab?

  1 Comment
James Tursa
James Tursa on 21 Jun 2022
Is this a homework assignment where you have to hand-code the bisection method?

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 21 Jun 2022
Edited: Sam Chak on 21 Jun 2022
This fzero algorithm uses a combination of bisection and secant methods. Very efficient! 👍
fcn = @(x) exp(x) - x.^2 + 3*x - 2;
x0 = 0; % initial guess
xroot = fzero(fcn, x0)
xroot = 0.2575
fplot(fcn, [-pi, pi], 'linewidth', 1.5)
hold on
plot(xroot, 0, 'ro', 'linewidth', 1.5, 'MarkerSize', 10)
grid on, xlabel('x'), ylabel('f(x)')

Categories

Find more on MATLAB 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!