Sum of fourier series:

23 ビュー (過去 30 日間)
Real Name
Real Name 2017 年 1 月 6 日
コメント済み: Ale gutierrez 2018 年 6 月 21 日
I just have a quick question. How do I enter the formula shown above? I can't seem to get n = 1, 3, 5, ... I tried different code along the line of this:
syms k x
x = 1/2 + symsum(k^2, k, [1:2:15])
But there is an error message.
Also, on a side note, what's the purpose of syms and the "x" variable shown in the matlab documentation example where I got this code?

採用された回答

John BG
John BG 2017 年 1 月 6 日
編集済み: John BG 2017 年 1 月 6 日
Philip
the 1st part of Walter's answer has syntax error:
  • it's most likely that t will have a higher amount of elements than vector n
  • therefore sin(n.*pi.*t) will always find one or more terms (of n) with a numel(n) href = ""</a> numel(t) mismatch
returning error, from the attempted d.*t
.
Let me suggest the following:
L=100;
t=[0:2/L:2];
x=zeros(1,numel(t));
for n = 1:2:15
x=x+ sin(n*pi*t)/n;
end;
x=x+.5/pi
plot(t,x);grid on
.
Increase L to improve signal time resolution.
.
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 7 日
"the 1st part of Walter's answer has syntax error:"
No it does not. There was no indication that t was required to handle vectors.
Ale gutierrez
Ale gutierrez 2018 年 6 月 21 日
I don't understand why you divide x by./2

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 6 日
Easiest is to use a definite sum:
n = 1:2:15;
x = 1/2 + sum( 2./(pi*n) .* sin(n.*pi.*t) );
But you could use
syms n t
x = 1/2 + symsum( 2./(pi*(2*n-1)) .* sin((2*n-1).*pi.*t), n, 1, 8 );
  2 件のコメント
Real Name
Real Name 2017 年 1 月 6 日
It says: Error using .* Matrix dimensions must agree.
Error in Hw1Prob13 (line 4) x = 1/2 + sum( 2./(pi*n) .* sin(pi*n.*t));
Walter Roberson
Walter Roberson 2017 年 1 月 7 日
For vector t, if you are using R2016b or later,
n = (1:2:15).';
x = 1/2 + sum( 2./(pi*n) .* sin(n.*pi.*t) );
For previous versions,
n = (1:2:15).';
x = 1/2 + sum( bsxfun(@times, 2./(pi*n), sin( bsxfun(@times, n.*pi, t) ) ) );

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

カテゴリ

Help Center および File ExchangeGeology についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by