Guest User

Untitled

a guest
Dec 6th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. function fp=falsa_posicion(f,p0,p1,iteraciones,tol)
  2. fp="No existe"
  3. if(f(p0)*f(p1)==0) then
  4. if (f(p0)==0) then
  5. fp=p0
  6. else
  7. fp=p1
  8. end
  9. end
  10.  
  11. if (f(p0)*f(p1)>0) then
  12. fp="Los extremeos tienen mismo signo"
  13. else
  14. if(fp<>"No existe") then
  15. i=2
  16. q0=f(p0)
  17. q1=f(p1)
  18. _p0=p0
  19. _p1=p1
  20. while (i<=iteraciones) do
  21. p=_p1-q1*(_p1-_p0)/(q1-q0)
  22. if abs(p-_p1)<tol then
  23. fp=p
  24. i=iteraciones+1
  25. else
  26. i=i+1
  27. q=f(p)
  28. if q*q1<0 then
  29. _p0=_p1
  30. q0=q1
  31. end
  32. _p1=p
  33. q1=q
  34. end
  35. end
  36. end
  37. end
  38. if (fp=="No existe" | fp=="Los extremeos tienen mismo signo") then
  39. error("Metodo fallo")
  40. end
  41. endfunction
Add Comment
Please, Sign In to add comment