Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.75 KB | None | 0 0
  1. clear
  2.  
  3. function y=f(x)
  4.     y = x **3 - x ** 2 + x - 8
  5. endfunction
  6.  
  7. function [root,ea]=biseccion(x1,xu,es)
  8.     root = (x1+xu)/2
  9.     ea = 100 * abs((x1-xu)/(x1+xu))
  10.    
  11.     while ea > es
  12.         if f(x1)*f(root) < 0 then
  13.             xu = root
  14.         else if f(x1)*f(root) == 0
  15.             ea = 0
  16.         else
  17.             x1 = root
  18.         end
  19.         if ea <> 0 then
  20.             root = (x1+xu)/2
  21.             ea = 100 * abs((x1-xu)/(x1+xu))    
  22.         end
  23.     end
  24. end
  25. endfunction
  26.  
  27. x1 = input("Limite Inferior: ")
  28. xu = input("Limite Superior: ")
  29. es = input("Tolerancia: ")
  30. [root,ea] = biseccion(x1,xu,es)
  31. disp("La raiz aproximada es " + string(root))
  32. disp("El error de aproximacion = " + string(ea))
  33. disp("f(root)="+string(f(root)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement