Advertisement
Guest User

Secante

a guest
Nov 23rd, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. cf = input('Ingrese función: ');
  2. f = inline(cf);
  3. x0 = input('Ingrese primer valor: ');
  4. x1 = input('Ingrese segundo valor: ');
  5. tol = input('Ingrese tolerancia: ');
  6. error = 100;
  7. n = 0;
  8. fprintf(' n x0 x1 x2 error\n');
  9. fprintf(' %i %4.4f %4.4f ----- ----\n',n,x0,x1);
  10. while(error>tol)
  11. x2 = x1 - (x1-x0)*f(x1)/(f(x1)-f(x0));
  12. error = abs(f(x2));
  13. fprintf(' %i %4.4f %4.4f %4.4f %4.4f\n',n,x0,x1,x2,error);
  14. x0=x1;
  15. x1=x2;
  16. n=n+1;
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement