0% found this document useful (0 votes)
22 views

CLC Clear Tolerence 0.0001 A 0.8 B 1.0 R 1 I 0 : While

This document describes an iterative method to find the root of an equation. It initializes variables including a tolerance value, starting values for a and b, an initial guess r, and an iteration counter i. It then enters a while loop to calculate new values of r using bisection between a and b until the difference between (r^3) and sin(r) is within the tolerance. It updates a or b depending on whether the difference is positive or negative, and increments i. After the loop, it prints the number of iterations and the calculated root r.

Uploaded by

Ahmad Almasri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

CLC Clear Tolerence 0.0001 A 0.8 B 1.0 R 1 I 0 : While

This document describes an iterative method to find the root of an equation. It initializes variables including a tolerance value, starting values for a and b, an initial guess r, and an iteration counter i. It then enters a while loop to calculate new values of r using bisection between a and b until the difference between (r^3) and sin(r) is within the tolerance. It updates a or b depending on whether the difference is positive or negative, and increments i. After the loop, it prints the number of iterations and the calculated root r.

Uploaded by

Ahmad Almasri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

clc; clear;

tolerence=0.0001;
a=0.8;
b=1.0;
r=1;
i=0;

while abs((r^3) - sin(r))>tolerence;

r=(a+b)/2;
if ((r^3) - sin(r))<0;
a=r;
else ((r^3) - sin(r))>0;
b=r;
end
i=i+1;
end

fprintf('Number of iterations = %g',i)


fprintf('\nThe root = %g\n',r)

Number of iterations = 11
The root = 0.928613

Published with MATLAB 8.0

You might also like