Why does it return 0 value? (Plotting fourier series)
4 次查看(过去 30 天)
显示 更早的评论
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
simplify(F_rectn)
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!