% Floating sphere problem % x = depth at which sphere floats % x will satisfy 0 <= x <= 2 % radius is 1 unit % rho is specific gravity of sphere % Try rho = 0.25 (cork ball) % Note how we define a function of one variable % to use in fzero f = @(x,rho) x^3 -3*x^2 + 4*rho opt = optimset('display', 'iter'); height = fzero( @(x) f(x,0.25), 1, opt)