MATLAB The following question needs to be programmed in MATL
(MATLAB) The following question needs to be programmed in MATLAB.
Find a root of the equation tan x = x on the interval [4, 5] by using the bisection method. What happens on the interval [1, 2]?Solution
Code:
function x = bisection(a,b,M)
disp(\"test\");
f = @(x)x - tan(x);
u = f(a);
v = f(b);
e = b-a;
x = [a, b, u, v]
if (u > 0 && v > 0) || (u < 0 && v < 0)
return;
end
for k = 1:M
e = e/2;
c = a + e;
w = f(c);
x = [k, c, w, e]
if (abs(e) < 10^(-5) || abs(w) < eps)
return;
end
if (w < 0 && u > 0) || (w > 0 && u < 0)
b = c;
v = w;
else
a = c;
u = w;
end
end
end
y = bisection(1,2,15);
The value of c converges to pi/2. The tan has singularity at this point and so does x - tan(x).
Output for [1,2]
x =
1.2000e+01 1.5706e+00 -4.1706e+03 2.4414e-04
x =
1.3000e+01 1.5707e+00 -8.5007e+03 1.2207e-04
x =
1.4000e+01 1.5707e+00 -1.7672e+04 6.1035e-05
x =
1.5000e+01 1.5708e+00 -3.8367e+04 3.0518e-05
Output for [4,5]
x =
4.0000 5.0000 2.8422 8.3805
![(MATLAB) The following question needs to be programmed in MATLAB. Find a root of the equation tan x = x on the interval [4, 5] by using the bisection method. Wh (MATLAB) The following question needs to be programmed in MATLAB. Find a root of the equation tan x = x on the interval [4, 5] by using the bisection method. Wh](/WebImages/41/matlab-the-following-question-needs-to-be-programmed-in-matl-1128488-1761602303-0.webp)