Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Manual increment
- % increment = (2 * pi) / 100
- % x = [-pi:increment:pi]
- x = linspace(-pi, pi, 101);
- N = 1000;
- empty_mat = zeros(N+1, 101);
- for i = 0:N
- expression = (sin((2*i+1).* x)) / (2*i + 1);
- % disp(size(expression))
- % empty_mat(i+1)
- empty_mat(i+1, :) = expression;
- end
- SNf1 = empty_mat .* (4 / pi);
- % disp(SNf1)
- SNf = sum(SNf1);
- f = [0:100];
- f(find((x < 0) & (x >= -pi))) = -1;
- f(find((x <= pi) & (x >= 0))) = 1;
- % Error
- E = abs(f - SNf);
- % Plotting x against SNf and x against err
- plot(x, SNf)
- title("x-values against partial sum (SNf)");
- xlabel("x-values");
- ylabel("SNf");
- % Plotting x against SNf
- plot(x, E)
- title("x-values against partial sum (SNf)");
- xlabel("x-values");
- ylabel("SNf");
- % Plotting x against err
- plot(x, E)
- title("x-values against E (absolute error between Fourier series of f and N-th partial sum)");
- xlabel("x-values");
- ylabel("E");
- % Maximum and average error
- disp(["Maximum error:", max(E)])
- disp(["Average error:", mean(E)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement