Advertisement
Albinutte

theory_rect

Dec 24th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.62 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 : ns(i)
  11.         error = error + h^3 * exp(-(h * (j - 1))) / 24;
  12.     end;
  13.     y_theory(i) = error;
  14.     y_fact(i) = abs(Rectangle(0, 0.4, ns(i)) + exp(-0.4) - 1);
  15.     y_runge(i) = (Rectangle(0, 0.4, idivide(ns(i), 2, 'floor')) - Rectangle(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