I am just learning MATLAB and I am having some issues with finding the roots of this function.
Where v0 = 36m/s, t = 4, g = 9.8m/s^2, and Cd = 0.25kg/m. The interval is from [100, 200] with a precision of 10^(-4)
Based on my function, did I input my equation correctly. In addition, is this the correct way to find the roots without using fzero? When I run it, the results don't match up. My instructor said I should be close to a root in less than 20 attempts. Thanks.
clear all; close all;
xr = 200; % right boundary
xl = 100; % left boundary
tries = 0;
for j = 1:1000
xc = (xl + xr)/2;
fc = sqrt((xc*9.8)/0.25)* tanh(sqrt((0.25 * 9.8) / xc) * 4) - 36;
if fc>0
xl = xc;
tries = tries + 1;
else
xr = xc;
tries = tries + 1;
end
if abs(fc)< 10^(-4)
break
end
end
tries % record number of attempts
xc % value of root
fc % value of function