Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Parameters
- V = 0.35; % [m^3]
- L = 3; % [m]
- r = 0.3; % [m]
- % Initial guess
- h = 0; % [m]
- % Loop until convergence
- hold = 1;
- iter = 0; % Counter to limit # of iterations, in case of no convergence
- while abs(h - hold) > 1e-7 && iter < 100
- % Compute the value of the function
- f = L*(r^2*acos(h/r) - h*sqrt(r^2-h^2)) - V;
- % Compute the derivative of the function
- fderiv = -2*L*sqrt(r^2-h^2);
- % Compute the Newton update
- hold = h; % Remember old value for comparison
- h = h - f / fderiv;
- % Increase the counter for the number of iterations
- iter = iter + 1;
- end;
- % Display result with an accuracy of 6 digits
- fprintf('h = %.6fn', h); % h = 0.041306
Add Comment
Please, Sign In to add comment