Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Вот было у тебя считай так:
- function Pogreshnost
- true_integral = besseli(0, 1/2) * pi * exp(-0.5);
- ns = 6 : 24;
- y_R = zeros(length(ns), 1);
- y_runge = zeros(length(ns), 1);
- y_fact = zeros(length(ns), 1);
- y_theory = zeros(length(ns), 1);
- for i = 1 : length(ns)
- %y_R(i) = 2 * sqrt((Simpson10(0, pi, ns(i)))^2 + (Simpson10_2(0, pi, ns(i)))^2);
- an = Simpson10(0, pi, ns(i));
- bn = Simpson10_2(0, pi, ns(i));
- y_R(i) = 2 * sqrt(an^2 + bn^2);
- y_fact(i) = abs(true_integral - Rectangle10(0, pi, ns(i)));
- h = pi / ns(i);
- y_theory(i) = pi * 0.828115 * h * h / 24;
- y_runge(i) = abs(Rectangle10(0, pi, ns(i) * 2) - Rectangle10(0, pi, ns(i))) / (2^2 - 1);
- end;
- semilogy(ns, y_R, '--', ns, y_fact, '-.', ns, y_theory, ':', ns, y_runge);
- legend('с периодом', 'фактическая', 'теоретическая', 'рунге');
- end
- А теперь в цикле будет так:
- for i = 1 : length(ns)
- %y_R(i) = 2 * sqrt((Simpson10(0, pi, ns(i)))^2 + (Simpson10_2(0, pi, ns(i)))^2);
- an = Simpson10(0, pi, ns(i));
- bn = Simpson10_2(0, pi, ns(i));
- a2n = Simpson10(0, pi, ns(i) * 2);
- b2n = Simpson10_2(0, pi, ns(i) * 2);
- y_R(i) = 2 * (sqrt(an^2 + bn^2) + sqrt(a2n^2 + b2n^2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement