Untitled
unknown
plain_text
a year ago
589 B
7
Indexable
function [volume_aitken] = calcola_volume_aitken()
Q = @(t) 2 * sin(pi*t/24).^2;
n1 = 100;
n2 = 2*n1;
n3 = 2*n2;
S1 = simpson_rule(Q, 0, 24, n1);
S2 = simpson_rule(Q, 0, 24, n2);
S3 = simpson_rule(Q, 0, 24, n3);
volume_aitken = S3 + (S3 - S2)^2 / (S3-2*S2+S1);
disp(volume_aitken);
end
function S = simpson_rule(f, a, b, n)
h = (b-a)/n;
x = linspace(a, b, n+1);
y = f(x);
coeff = ones(1, n+1); %[ 1 1 1 1 1 1 1]
coeff(2:2:n) = 4; %[ 1 4 1 4 1 4 1]
coeff(3:2:n-1) = 2; %[1 4 2 4 2 4 1]
S = (h/3) * sum(coeff .* y);
endEditor is loading...
Leave a Comment