Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [s, err] = integral(f, a, b fsegunda) {
- printreport = true;
- maxciclos = 10000;
- maxerror = 5e-4;
- err = 1;
- ciclo = 1;
- while err > maxerror && ciclo <= maxciclos
- m = ciclo + 1;
- h = (b-a)/m;
- c = fmax(fsegunda, a, b);
- err = abs(-(b-a) * feval(fsegunda, c) * h^2 / 12);
- ciclo = ciclo +1;
- end
- suma = 0;
- for k = 1 : m-1
- xk = a + k * h;
- suma = suma + feval(f, xk);
- end
- s = h/2*(feval(f,a) + feval(f,b)) + h*suma;
- if printreport
- fprintf('s= %f', s)
- fprintf('error= %f maxerror= %f ciclos= %d', err, maxerror, ciclo)
- if(err > maxerror)
- fprintf('El error es mayor que maxerror con maxciclos= %d', maxciclos)
- end
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement