Can you check my error code?
1 次查看(过去 30 天)
显示 更早的评论
Hello! Can you correct my code? Because I have some errors on my code.
%% Starting codes
x = linspace (-2,4,101);
span = [0 1 2];
for i = -1: 2
h1 = plot (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)), ...
zeros (size (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)))));
hold on;
h2 = plot (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)), ...
ones (size (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)))));
set (h1, 'linewidth', 3, 'color', 'b');
set (h2, 'linewidth', 3, 'color', 'b');
end
ylim ([-1 2]);
grid on;
title ('f (x) vs Fourier Series', 'front size', 16);
n = 0: 100;
for i = 1: length (x)
f (i) = 0.5-sum (2 / pi. * sin ((2 * n + 1) * pi * x (i)) ./ (2 * n + 1));
set (f (i), 'linewidth', 3, 'color', 'b');
end
plot (x, f, 'r');
hold off
And I got errors like the following:
0 个评论
回答(1 个)
Ridwan Alam
2019-12-6
编辑:Ridwan Alam
2019-12-6
x = linspace (-2,4,101);
span = [0 1 2];
for i = -1: 2
h1 = plot (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)), ...
zeros (size (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)))));
hold on;
h2 = plot (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)), ...
ones (size (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)))));
set (h1, 'linewidth', 3, 'color', 'b');
set (h2, 'linewidth', 3, 'color', 'b');
end
ylim ([-1 2]);
grid on;
title ('f (x) vs Fourier Series', 'FontSize', 16); % not 'front size'
n = 0: 100;
for i = 1: length (x)
f (i) = 0.5-sum (2 / pi. * sin ((2 * n + 1) * pi * x (i)) ./ (2 * n + 1));
set (f (i), 'linewidth', 3, 'color', 'b');
end
plot (x, f, 'r');hold off;
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!