Matlab can be used to find roots of functions. One method is bisection method. We write a Matlab code to find approximate roots of functions using theories of bisection method which is a sub-topic of numerical methods subject.
First, an introduction to code and variables are given as comments in the program. Then Matlab codes are written. After the code, code is explained.
In this tutorial, we are going to solve a quadratic equation, x2 - 4*x - 13 = 0
% final answer accuracy is enough for
%variable introduction
% X1 is the left point
% X2 is the right point
% X3 is the average value, otherwise X3=(X1+X2)/2
% value takes the value of function when X3 is substituted it in the function
% previousX1Value takes the value of function when X1 is substituted it in the function
% nextX2Value takes the value of function when X2 is substituted it in the function
In this program, we are going to work with decimal numbers. So we should select our data as long.
We define two variables. x and value.
We give our equation as a function of x.
We define three variables as X1, X2 and n. X1 and X2 are assumed root values of the function. Variable n is used to control the loop running times.