필터 지우기
필터 지우기

Why I'm I getting results in terms of t for an and bn even though it is an integration with specific limits?

조회 수: 4 (최근 30일)
%Excercise 4
syms t
syms N
%prompt = "Please enter a function rules for variable segments of the function f: ";
%'Enter 2D array with [] around it and commas between the columns and semicolon at end of each row '
f = input('Please enter function rules for variable segments of the function f:')
flim= input('Please enter real numbers to define the limits of the segments of f:')
N= input('Please enter an intiger to specifie the max order of Fourier coefficients of f:')
%flimFirst= flim(1);
%filmEnd= flim(end);
%a0= 2/(flim(end)-flim(1))*int(f(1),flim(1),flim(2));
%a0= sprintf('%.4f', a0)
%a02= 2/(flim(end)-flim(1))*int(f(2),flim(2),flim(3));
%a02= sprintf('%.4f', a02)
T = flim(end)-flim(1);
w0 = 2*pi/T;
a0= (2/T)*int(f(length(f)),t,flim(length(flim)-1),flim(length(flim)));
sprintf('%.4f', a0)
a02= (2/T)*int(f(1),t,flim(1),flim(2));
sprintf('%.4f', a02)
a03= (2/T)*int(f(2),t,flim(2),flim(3));
sprintf('%.4f', a02)
for i = 1:N
for k= 2:length(flim)
an= (2/T)*int((f(k-1))*cos(N*w0*t)),t,flim(k-1),flim(k);
an(i)=an;
bn= (2/T)*int((f(k-1))*sin(N*w0*t)),t,flim(k-1),flim(k);
bn(i)=bn;
fs= (a0/2)+(an*cos(w0*N*t))+(bn*sin(w0*N*t));
end
end
an
%sprintf('%.4f', an);
bn
%sprintf('%.4f', bn);
fs
%sprintf('%.4f', fs);
  댓글 수: 3
Stephen23
Stephen23 2022년 12월 14일
편집: Stephen23 2022년 12월 14일
Original question by Stefanos retrieved from Google Cache:
"Why I'm I getting results in terms of t for an and bn even though it is an integration with specific limits?"
%Excercise 4
Theme
syms t
syms N
%prompt = "Please enter a function rules for variable segments of the function f: ";
%'Enter 2D array with [] around it and commas between the columns and semicolon at end of each row '
f = input('Please enter function rules for variable segments of the function f:')
flim= input('Please enter real numbers to define the limits of the segments of f:')
N= input('Please enter an intiger to specifie the max order of Fourier coefficients of f:')
%flimFirst= flim(1);
%filmEnd= flim(end);
%a0= 2/(flim(end)-flim(1))*int(f(1),flim(1),flim(2));
%a0= sprintf('%.4f', a0)
%a02= 2/(flim(end)-flim(1))*int(f(2),flim(2),flim(3));
%a02= sprintf('%.4f', a02)
T = flim(end)-flim(1);
w0 = 2*pi/T;
a0= (2/T)*int(f(length(f)),t,flim(length(flim)-1),flim(length(flim)));
sprintf('%.4f', a0)
a02= (2/T)*int(f(1),t,flim(1),flim(2));
sprintf('%.4f', a02)
a03= (2/T)*int(f(2),t,flim(2),flim(3));
sprintf('%.4f', a02)
for i = 1:N
for k= 2:length(flim)
an= (2/T)*int((f(k-1))*cos(N*w0*t)),t,flim(k-1),flim(k);
an(i)=an;
bn= (2/T)*int((f(k-1))*sin(N*w0*t)),t,flim(k-1),flim(k);
bn(i)=bn;
fs= (a0/2)+(an*cos(w0*N*t))+(bn*sin(w0*N*t));
end
end
an
%sprintf('%.4f', an);
bn
%sprintf('%.4f', bn);
fs
%sprintf('%.4f', fs);

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2022년 12월 13일
syms t
f = [pi+t,pi-t];
flim= [-pi,0,pi];
N = 5;
T = flim(end)-flim(1);
w0 = 2*pi/T;
fs = 0.0;
for i = 0:N
for k= 2:length(flim)
an= (2/T)*int(f(k-1)*cos(i*w0*t),t,flim(k-1),flim(k));
bn= (2/T)*int(f(k-1)*sin(i*w0*t),t,flim(k-1),flim(k));
fs= fs + an*cos(w0*i*t)+bn*sin(w0*i*t);
end
if i==0
fs = fs/2;
end
end
fs = matlabFunction(fs);
t = -pi:0.01:pi;
plot(t,fs(t))
  댓글 수: 15
Torsten
Torsten 2022년 12월 14일
Summarizing Walters's response:
You should improve your MATLAB skills and invest two hours of your time to visit MATLAB's online course for free:

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by