Extending the number of terms in a specific sequence.

2 ビュー (過去 30 日間)
Oscar Kilby
Oscar Kilby 2020 年 12 月 25 日
コメント済み: Oscar Kilby 2020 年 12 月 25 日
Hello all,
Im trying to add a larger number of terms to the sequence labeled as 'Base' in the code below and display them together however my extended sequence doesnt match as closely to the base form as i was expecting, would it be possible for someone to verify if i've done it correctly / point out errors in my code?
T = 1;
w = 2*pi*(1/T);
t = linspace(0 , 3*T, 1000);
max_harmonics = 11;
Base = zeros(size(t));
Base = sin(w*t) - (1/9)*sin(3*w*t) + (1/25)*sin(5*w*t) - (1/49)*sin(7*w*t);
Base = Base + (1/(9.^2))*sin(9*w*t) - (1/(11.^2))*sin(11*w*t);
synth_f1 = zeros(size(t));
for n = 3:4:max_harmonics
synth_f1 = synth_f1 - (1/(n*n))*sin(n*w*t) + (1/((n+2).^2))*sin(n*w*t);
end
synth_f1 = sin(w*t) + synth_f1;
plot(t, synth_f1, 'r-', t, Base, 'b--' );

回答 (1 件)

per isakson
per isakson 2020 年 12 月 25 日
編集済み: per isakson 2020 年 12 月 25 日
A copy&paste mistake:
synth_f1 = synth_f1 - (1/(n*n))*sin(n*w*t) + (1/((n+2).^2))*sin((n+2)*w*t);
% ^^^^^
  1 件のコメント
Oscar Kilby
Oscar Kilby 2020 年 12 月 25 日
Oh i see it now, thank you.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by