Matlab Write a code using the bisection method f a b n tes
Matlab
Write a code using the bisection method ( f, a, b, n )
testing
f(x) = x^2 - 1
a = -2
b= 2
n = 10 ( numbers of times you do bisection)
Solution
functionbijection (f,a,b,n)
f=@x x^2-1;
a=-2;
b=2
n=10
for i=1 : 10
c=(a+b)/2;
if f(c) >0
b=c;
else
a=c;
end
end
fprintf(`Roots of the given equation is %f`,c)
that is required coding.
