Can you check my error code?

1 Ansicht (letzte 30 Tage)
SEANGHAI THA
SEANGHAI THA am 6 Dez. 2019
Kommentiert: Ridwan Alam am 6 Dez. 2019
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:

Antworten (1)

Ridwan Alam
Ridwan Alam am 6 Dez. 2019
Bearbeitet: Ridwan Alam am 6 Dez. 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 Kommentare
SEANGHAI THA
SEANGHAI THA am 6 Dez. 2019
Oh! Many thank for your help!
Ridwan Alam
Ridwan Alam am 6 Dez. 2019
Sure. Glad to help. Please accept the response as an answer.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by