Can you check my error code?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Ridwan Alam
il 6 Dic 2019
Modificato: Ridwan Alam
il 6 Dic 2019
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 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!