Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cf = input('Ingrese función: ');
- f = inline(cf);
- x0 = input('Ingrese primer valor: ');
- x1 = input('Ingrese segundo valor: ');
- tol = input('Ingrese tolerancia: ');
- error = 100;
- n = 0;
- fprintf(' n x0 x1 x2 error\n');
- fprintf(' %i %4.4f %4.4f ----- ----\n',n,x0,x1);
- while(error>tol)
- x2 = x1 - (x1-x0)*f(x1)/(f(x1)-f(x0));
- error = abs(f(x2));
- fprintf(' %i %4.4f %4.4f %4.4f %4.4f\n',n,x0,x1,x2,error);
- x0=x1;
- x1=x2;
- n=n+1;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement