Advertisement
Albinutte

theory_simpson

Dec 24th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.55 KB | None | 0 0
  1. ns = 5 : 21;
  2. n = length(ns);
  3.  
  4. y_theory = zeros(n, 1);
  5. y_fact = zeros(n, 1);
  6. y_runge = zeros(n, 1);
  7. for i = 1 : n
  8.     error = 0;
  9.     h = 0.4 / ns(i);
  10.     for j = 1 : length(ns)
  11.         error = error + h^5 * exp(-(h * (j - 1))) / 2880;
  12.     end;
  13.     y_theory(i) = error;
  14.     y_fact(i) = abs(Simpson(0, 0.4, ns(i)) + exp(-0.4) - 1);
  15.     y_runge(i) = abs(Simpson(0, 0.4, idivide(ns(i), 2, 'floor')) - Simpson(0, 0.4, ns(i))) / (2^2 - 1);
  16. end;
  17.  
  18. semilogy(ns, y_theory, ns, y_fact, '--', ns, y_runge, '-.');
  19. legend('теор.', 'факт.', 'Рунге');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement