Advertisement
santiagohiguera

integral

Dec 14th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.68 KB | None | 0 0
  1. function [s, err] = integral(f, a, b fsegunda) {
  2.    
  3.     printreport = true;
  4.     maxciclos = 10000;
  5.     maxerror = 5e-4;
  6.  
  7.     err = 1;
  8.     ciclo = 1;
  9.     while err > maxerror && ciclo <= maxciclos
  10.         m = ciclo + 1;
  11.         h = (b-a)/m;
  12.         c = fmax(fsegunda, a, b);
  13.         err = abs(-(b-a) * feval(fsegunda, c) * h^2 / 12);
  14.         ciclo = ciclo +1;
  15.     end
  16.  
  17.     suma = 0;
  18.     for k = 1 : m-1
  19.         xk = a + k * h;
  20.         suma = suma + feval(f, xk);
  21.     end
  22.    
  23.     s = h/2*(feval(f,a) + feval(f,b)) + h*suma;
  24.  
  25.     if printreport
  26.         fprintf('s= %f', s)
  27.         fprintf('error= %f maxerror= %f ciclos= %d', err, maxerror, ciclo)
  28.         if(err > maxerror)
  29.             fprintf('El error es mayor que maxerror con maxciclos= %d', maxciclos)
  30.         end
  31.     end
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement