88.3k views
2 votes
Write a MATLAB script that will find the roots of a given equations using the BISECTION METHOD. Format your output to look similar to the examples given. You should write your output to a file. Set the maximum number of iterations to 100 and the tolerance to 0.000005. Use a tolerance definition of are the interval endpoints for the nth iteration Use the script to solve the given equations. Use the interval endpoints as your initial a and b. Eq1 f(x) = ex - (x2 + 4) = 0 on [2,3] Eq2 f(x) = x - 2-x = 0 on [1/3,1] Eq3 f(x) = x3 - 1.8999 x2 + 1.5796 x - 2.1195 = 0 on [1,2].

User Rinesse
by
4.6k points

1 Answer

2 votes

Answer:

For Eqiation 1 using Matlab code

clc;

clear all;

s=1200;

h=20;

f=@(x) exp(x)-(x^2+4) ;

a=2;

b=3;

format long

eps_abs = 0.000005;

eps_step = 0.000005;

n=0;

while ((b - a )/2>= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs )&& n~=100 )

n=n+1;

c = (a + b)/2;

if ( f(c) == 0 )

break;

elseif ( f(a)*f(c) < 0 )

b = c;

else

a = c;

end

err=abs( (b-a)/2);

end

n

c

err

output

n =

18

c =

2.158725738525391

err =

1.907348632812500e-006

For Equation 2

change the function f(x) and interval a=1/3 , b=1 in above code (remaining same code)

clc;

clear all;

s=1200;

h=20;

f=@(x) x-2^(-x) ;

a=1/3;

b=1;

format long

eps_abs = 0.000005;

eps_step = 0.000005;

n=0;

while ((b - a)/2 >= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs )&& n~=100 )

n=n+1;

c = (a + b)/2;

if ( f(c) == 0 )

break;

elseif ( f(a)*f(c) < 0 )

b = c;

else

a = c;

end

err=abs( (b-a)/2);

end

n

c

err

out put

n =

17

c =

0.641189575195313

err =

2.543131510435170e-006

For Equation 3

change the function f(x) and interval a=1 , b=2 in above code (remaining same code)

Output

n =

17

c =

1.367546081542969

err =

3.814697265625000e-006

User Ben Greenman
by
5.0k points