Guest User

Untitled

a guest
Feb 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. % Parameters
  2. V = 0.35; % [m^3]
  3. L = 3; % [m]
  4. r = 0.3; % [m]
  5.  
  6. % Initial guess
  7. h = 0; % [m]
  8.  
  9. % Loop until convergence
  10. hold = 1;
  11. iter = 0; % Counter to limit # of iterations, in case of no convergence
  12. while abs(h - hold) > 1e-7 && iter < 100
  13. % Compute the value of the function
  14. f = L*(r^2*acos(h/r) - h*sqrt(r^2-h^2)) - V;
  15.  
  16. % Compute the derivative of the function
  17. fderiv = -2*L*sqrt(r^2-h^2);
  18.  
  19. % Compute the Newton update
  20. hold = h; % Remember old value for comparison
  21. h = h - f / fderiv;
  22.  
  23. % Increase the counter for the number of iterations
  24. iter = iter + 1;
  25. end;
  26.  
  27. % Display result with an accuracy of 6 digits
  28. fprintf('h = %.6fn', h); % h = 0.041306
Add Comment
Please, Sign In to add comment