![](https://csdnimg.cn/release/download_crawler_static/86189990/bg1.jpg)
FUNCTION
F= x.^3-x-2; …..Function which I implemented in matlab
MATLAB CODE
clc
close all
clear all
syms x % symbol representation
a=input('Initial value of a: '); % enter value of 'a'
b=input('Initial value of b: '); % enter value of 'b'
tolerance=input('Enter tolarence value: '); % enter Tollarance value'
[X1,X2,c,F_c,err1,t_bisection]=Bisection(a,b,tolerance); % Bisection method
[Xin,F,F_d,err,t_NRmethod]=NRmethod(a,tolerance); % NR method
%% Bi-Section Method -------Output variable display----------------------------
-------------------------------
fprintf('\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BI-
SECTION METHOD RESULTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\n');
fprintf('-----------------------------------------------------------------------
--------------------------------------------\n');
fprintf('\n Iteration\t| a | b | c
| F(c) | Tolerance | \n');
fprintf('-----------------------------------------------------------------------
----------------------------------------------\n');
for j=1:length(F_c);
fprintf('%5d \t|\t%5f \t|\t%5f\t\t|\t%5f \t|\t%5f \t|\t%5f \t|\n',j,X1(j),X
2(j),c(j),F_c(j),err1(j));
end
format long;
fprintf('-----------------------------------------------------------------------
----------------------------------------------\n');
fprintf('time elapsed in milliseconds:\tt = %-10f\n',t_bisection*10^3);
%% NR Method results----- Output variable display----------------------------
----------------------------
fprintf('\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NR METHOD RESULTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n');
fprintf('\n --------------------------------------------------------------------
-----------------------\n');
fprintf('\n Iteration\t| Value of x | function F(x) | F_d(x)
| Tolerance | \n');
fprintf('-----------------------------------------------------------------------
----------------------\n');