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!