# Why does it return 0 value? (Plotting fourier series)

5 ビュー (過去 30 日間)
Tu Nguyen 2022 年 3 月 3 日
コメント済み: Paul 2022 年 3 月 4 日
clc
clear all
close all
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
rp1 = real(F_rectn)*cos(2*pi*n*x/L);
ip1 = imag(F_rectn)*sin(2*pi*n*x/L);
F_0 = F_rectn(x==0);
for i = 1:numel(n);
y1 = 1/L*(F_0 + 2*symsum(rp1(i),x,-4,4) - 2*symsum(ip1(i),x,-4,4));
fplot(y1)
end
Dear all, I want to plot function y1 based on variable x in loop of range n in [-4:4], but it returns y1 = 0? Can anyone please help me fix this plot?
##### 1 件のコメント表示非表示 なし
Paul 2022 年 3 月 4 日
Is there a source for the equations the code is trying to implement?
For sure, one problem is that the computation of F_0 is incorrect.
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
F_rectn
F_rectn =
simplify(F_rectn)
ans =
We see that F_rectn is a function only of w. So what the code probably should try to do is
F_0 = subs(F_rectn,w,0)
but that won't work because it will divide by zero. So either F_0 will have to be hard coded to F_0 = 2, or an alternative code will be needed to compute F_0.
Having said that, it looks like the code has some other issues, like rp1 and ip1 are both functions of w and x, so it's likely that other correctsion will be needed as well.

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

### 回答 (1 件)

Alberto Cuadra Lara 2022 年 3 月 3 日
Hello Tu,
Check the definition of F_0, it's empty
clc
clear all
close all
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
rp1 = real(F_rectn)*cos(2*pi*n*x/L);
ip1 = imag(F_rectn)*sin(2*pi*n*x/L);
F_0 = F_rectn(x==0)
F_0 = [ empty sym ]

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

### カテゴリ

Find more on Assumptions in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by