This problem is from Numerical Methods for Engineers andScientist from Amos Gilat and Vish Subramaniam.
Cramster doesn't have this book here so this is the closest Icould get.
According to Archimede's principle, the buoyancy force actingon that object that is partially immersed in a fluid is equal tothe weight that is displaced by the portion of the object that issubmerged.
A spherical float with mass of mf = 70kg and adiametre of 90cm is placed in the ocean ( density of sea water isapproximately ?=1030kg/m3 . The height, h, of theportion of the float that is over the water can be determined bysolving an equation that equates the mass of the float to the massofthe water that is displaced by the portion of the float that issubmerged:
?Vcap=mf (Equation3.59)
where for a pshere of radius r, the volume of a cap of depth,d, is given by:
Vcap= (1/3)pd2(3r-d)
Write equation (3.59) in terms of h and solve for husing:
(a) the user defined function NEWTONROOT. Use 0.0001for Err, and 0.8 for Xest
(b) MATLAB's built-in fzero function
NEWROOT is:
function Xs= NewtonRoot(Fun,FunDer,Xest,Err,imax)
%NewtonRoot finds the root of Fun=0 near the point Xest usingNewton's method.
%Input variables:
%Fun Name(string) of a function file that calculates Funfor a given x.
%FunDer Name(string) of a function that calculates thederivative of Fun for a given x.
%Xest Initial estimate of the solution.
%Err Maximum error.
%Output variable:
%Xs Solution
for i = 1:imax
Xi= Xest-feval(Fun,Xest)/feval(FunDer,Xest);
if abs((Xi-Xest)/Xest) < Err
Xs=Xi;
break
end
Xest=Xi
end
if i == imax
fprintf('Solution was not obtained in %iiterations.\n',imax)
Xs= ('No Answer');
end