Bisection method code - question.
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi, I wrote the following function for solving V=L[arccos(h/r)r^2 - h(r^2-h^2)^0.5] using the bisection method. However, as I execute the program it gets stuck, yet I cannot figure out why. I'd appreciate any comments.
function h = volume(V,L,r,h1,h2)
h=(h1+h2)/2;
err=abs(V-L*(acosd(h/r)*r^2-h*sqrt(r^2-h^2)));
while (err > 0.01)
    if (V-L*(acosd(h1/r)*r^2-h1*sqrt(r^2-h1^2))*(V-L*(acosd(h/r)*r^2-h*sqrt(r^2-h^2))) < 0)
        h2=h;
    else
        h1=h;
    end
    h=(h1+h2)/2;
    err=abs(V-L*(acosd(h/r)*r^2-h*sqrt(r^2-h^2)));
end
0 comentarios
Respuestas (1)
  Matt J
      
      
 el 26 de Dic. de 2013
        I think you're just missing some parentheses in
 if (V-L*(acosd(h1/r)*r^2-h1*sqrt(r^2-h1^2))*(V-L*(acosd(h/r)*r^2-h*sqrt(r^2-h^2))) < 0)
4 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

