MATLAB: Calculating the height of a liquid in a sphere using secant method

equationgraphheighthomeworkMATLABsecantspherevolume

The problem is to determine how much the spherical tank must be filled to contain 30m3 if
R = 3m. The volume is calculated according to equation: V = (?ℎ^2*[3? − ℎ])/3
Use the secant method. Print the approximations, the relative error. Ensure that the calculation ends when the error is less than a certain value.
Find the correct solutions using the appropriate matlab function. Print approximations and errors.
Bonus: show graphically the dependance of the Volume V on the Height h. f(x).

Best Answer

You need to use a function that is 0 at the h you are looking for. So you need that 30 in your function handle. E.g.,
func = @(h)(pi*h^2*(9-h))/3 - 30
If you want to compare to a MATLAB function answer, realize that you have a polynomial in h. So just make a vector of the coefficients and feed it to the roots( ) function.