Implement the Bisection Method in Matlab

Implement the Bisection Method in Matlab to find a root of f(x) = x 2 − e x on the interval [−2, 2]. Use a tolerance of 1E − 8.

6 Comments

@Shivani Patel, It's strange, because my MATLAB does not understand this function. Are you 100% sure that it is correct?
f(x) = x 2 e x
By the way, in order to determine the deduction in
1E 8
You need to assign a value to E first.
@Sam Chak, the function is f(x) = x^2 - exp(x), and 1E-8 is the scientific notation format, equalto 10^-8.
@Shivani Patel, What have you tried yet, and what is the problem you are facing?
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Sam Chak
Sam Chak on 26 Apr 2022
Edited: Sam Chak on 26 Apr 2022
@Dyuman Joshi, thank you for your clarification. Honestly, I do not know that the mathematical notations have evolved a lot in the last 10 years that @Shivani Patel wrote x 2 implies x^2, and e x implies exp(x). Is that currently taught in the math curriculum? Luckily, MATLAB does not follow the shorthand of writing 'modern' mathematical notations.
I'm absolutely fine with homeworks. I still remembered when my Lecturer gave homeworks and assignments in the class, the students never had a formal introduction in MATLAB, and we were tasked to complete them by whatever means. There were no YouTube tutorials, only relying on MATLAB books in the Library, but they were quickly borrowed by other students. Most of us did not know where to begin, and therefore, we did not know what function to search to solve to the problem.
Even when we entered exactly the same formula given by the Lecturer, it still didn't work because some operations and repetition control structure were incorrect according to the MATLAB rules. Eventually, some students request for leniency if the numerical solution can be computed in the MS Excel Spreadsheet, because it was easy to understand how the cells are updated visually.
I actually got help on where I was going wrong. Thank you
@Sam Chak My guess is that the function appeared in the text of the question as "x 2 - e x" because it was copied and pasted from a document (likely PDF, maybe HTML) that typeset it as . If the copy & paste process just copied the actual characters not the positioning of the 2 and the second x as superscripts, that would appear as "x 2 - e x".

Sign in to comment.

Answers (0)

Asked:

on 26 Apr 2022

Commented:

on 26 Apr 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!