Hello All .I want a solution with a simple explanation

조회 수: 1 (최근 30일)
Ahmed Ali
Ahmed Ali 2021년 10월 30일
댓글: William Rose 2021년 11월 17일
  댓글 수: 5
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 31일
Good attempts!
Always, post your work along with your question that helps the audience to see where and how they can help you with your question.
Ahmed Ali
Ahmed Ali 2021년 11월 1일
Thanks. I will do it next time

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

채택된 답변

William Rose
William Rose 2021년 11월 1일
Since I'm not good at symbolic math in Matlab, I'll give an example of how to do this problem non-symbolically. The code below shows off Matlab's great ability to be smart about adding things up without using for loops.
a0=0.5; A=1; T=2; %mean value; peak2peak amplitude; period
t=(0:.001:2)*T; %time vector for two cycles
b=(2*A/pi)./(1:2:9999); %coefficients for sines (odd only)
w=2*pi*(1:2:9999)/T; %frequencies for sines (odd only)
f=a0-A/2+A*(mod(t,T)<T/2); %exact square wave function
f1=a0+b(1)*sin(w(1)*t); %Fourier series, n=1
f9=a0+b(1:5)*sin(w(1:5)'*t); %Fourier series, n=1:9 odd
f99=a0+b(1:50)*sin(w(1:50)'*t); %Fourier series, n=1:99 odd
f999=a0+b(1:500)*sin(w(1:500)'*t); %Fourier series, n=1:999 odd
f9999=a0+b(1:5000)*sin(w(1:5000)'*t); %Fourier series, n=1:9999 odd
plot(t,f,'-k',t,f1,'-r',t,f9,'-g',t,f99,'-b',t,f999,'-c',t,f9999,'-m');
legend('f(t)','f1','f9','f99','f999','f9999');
Try code above.
  댓글 수: 3
Ahmed Ali
Ahmed Ali 2021년 11월 1일
Thank you so much. It's worked
Very grateful to you
William Rose
William Rose 2021년 11월 1일
@Ahmed Ali , you're welcome.
@Walter Roberson is really good at math and Matlab, so when he gives a hint, as he did in this case, I pay attention.

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

추가 답변 (3개)

Walter Roberson
Walter Roberson 2021년 10월 31일
Fixing your syntax, but not attempting to fix the logic.
Question: why do you calculate ao, an, bn, if you are not going to use them?
Note: the values for an and bn are correct for those expressions and that integration interval.
syms t n
T = 2 ;
w0 = 2 * pi / T ;
n = [1, 10, 100, 1000, 10000];
ao = ( 1 / T ) * int ( sym(1) , t , 0,2 )
ao = 
1
an = ( 2 / T ) * int ( sym(1) * cos ( n * w0 * t ) , t , 0,2 )
an = 
bn = ( 2 / T ) * int ( sym(1) * sin ( n * w0 * t ) , t , 0,2 )
bn = 
ft = (0.5 + 2/pi ) * sum ((1./n) .* sin(n*pi*t))
ft = 
fplot(ft, [-10 10])
  댓글 수: 4
Ahmed Ali
Ahmed Ali 2021년 11월 1일
@Walter Roberson These are all errors
Error using fcnchk (line 106)
If FUN is a MATLAB object, it must have an feval method.
Error in fplot (line 60)
fun = fcnchk(fun);
Error in Untitled (line 11)
fplot(ft, [-10 10])
>>
I am using the 2014b version
Walter Roberson
Walter Roberson 2021년 11월 1일
syms t n
T = 2 ;
w0 = 2 * pi / T ;
n = [1, 10, 100, 1000, 10000];
ao = ( 1 / T ) * int ( sym(1) , t , 0,2 )
ao = 
1
an = ( 2 / T ) * int ( sym(1) * cos ( n * w0 * t ) , t , 0,2 )
an = 
bn = ( 2 / T ) * int ( sym(1) * sin ( n * w0 * t ) , t , 0,2 )
bn = 
ft = (0.5 + 2/pi ) * sum ((1./n) .* sin(n*pi*t))
ft = 
fth = matlabFunction(ft);
fplot(fth, [-10 10])

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


Ahmed Ali
Ahmed Ali 2021년 11월 17일
clc
clear all
S=0;
H=0;
N=input('input N=');
for k=1:N
for I=1:40000
f=I/10000;
H(I)=(2/(pi*(2*k-1)))*sin((2*k-1)*pi*f);
end
S=S+H;
end
S=S+0.5;
plot(S)
  댓글 수: 2
Ahmed Ali
Ahmed Ali 2021년 11월 17일
The typical solution to this question
William Rose
William Rose 2021년 11월 17일
@Ahmed Ali , your solution looks very nice.

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


William Rose
William Rose 2021년 11월 1일
@Walter Roberson said he is correcting your syntax, but not your logic. @Walter Roberson sees that there are logical errors in your code, in addition to syntax errors. Therefore it will not compute the Fourrier series correctly, even when you solve the syntax errors.
I assume the figure you provided represents an infinite pulse train.
Since the function f(t) is odd, except for the mean value, the Fourier series will involve odd terms with sine only, and not any cosine components. In other words, when you solve the integral for the Fourier series coefficients, you will find that all the cosine coefficients are zero, and the sine coefficients are zero when n is even. Therefore only the odd sine coefficients, and the coefficient for the mean value, are non-zero. The Fourier series is therefore
where
(n odd)
where is the mean value, A is the peak-to-peak amplitude, T is the period. In this case, =0.5, A=1, and T=2. Your code should do the summation above, stopping after n=1, 9, 99, 999, 9999.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by