필터 지우기
필터 지우기

Fourier Series for odd integers only

조회 수: 1 (최근 30일)
Tashanda Rayne
Tashanda Rayne 2023년 12월 16일
댓글: Paul 2023년 12월 18일
Can someone please help me to get this function B to only apply to odd integers but for every other odd integers the formula is negative. So for integer 1,5,9... its positive and for 3,7,11.... its negative
% Fourier Series
syms x k L
f1(x) = x;
f2(x) = L-x;
f1 = simplify(f1);
f2 = simplify(f2);
%Solving for Bn
b(k) = (2/L)*int(f1*sin(k*pi*x/L),[0,L/2]);
b(k) = 
b1(k) = (2/L)*int(f2*sin(k*pi*x/L),[L/2,L]);
b1(k) = 
B(k) = b1 + b
B(k) = 
B = simplify(B)
  댓글 수: 2
Image Analyst
Image Analyst 2023년 12월 16일
I formatted your code as code so people can easily copy it into their MATLAB, and I ran the code. But I'm not sure what you're asking. What are the "integers" that you're talking about?
Paul
Paul 2023년 12월 18일
I see that one issue in the code has been fixed, but I still think the equations for b(k) and b1(k) are incorrect based on my assumption of what the goal of this code actually is.

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

답변 (2개)

Walter Roberson
Walter Roberson 2023년 12월 16일
symsum( (-1)^(k+1)*B(2*k-1), k, 1, inf)
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 12월 16일
% Fourier Series
syms x k L
f1(x) = x;
f2(x) = L-x;
f1 = simplify(f1);
f2 = simplify(f2);
%Solving for Bn
b(k) = (2/L)*int(f1*sin(k*pi*x/L),[0,L/2]);
b(k) = simplify(b(k))
b(k) = 
b1(k) = (2/L)*int(f2*sin(k*pi*x/L),[L/2,L]);
b1(k) = simplify(b(k))
b1(k) = 
B(k) = b1 + b
B(k) = 
syms N integer
val(N) = symsum( (-1)^(k+1)*B(2*k-1), k, 1, N)
val(N) = 
val(25)
ans = 
vpa(ans)
ans = 
val(100)
ans = 
vpa(ans)
ans = 
val(200)
ans = 
vpa(ans)
ans = 
val(1234)
ans = 
vpa(ans)
ans = 
val(inf)
ans = 
NaN
Walter Roberson
Walter Roberson 2023년 12월 18일
% Fourier Series
syms x k L
f1(x) = x;
f2(x) = L-x;
f1 = simplify(f1);
f2 = simplify(f2);
%Solving for Bn
b(k) = (2/L)*int(f1*sin(k*pi*x/L),[0,L/2]);
b1(k) = (2/L)*int(f2*sin(k*pi*x/L),[L/2,L]);
B(k) = b1 + b
B(k) = 
B = simplify(B)
B(k) = 
syms N integer
val(N) = symsum( (-1)^(k+1)*B(2*k-1), k, 1, N)
val(N) = 
val(100), vpa(ans)
ans = 
ans = 
val(200), vpa(ans)
ans = 
ans = 
val(201), vpa(ans)
ans = 
ans = 

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


Paul
Paul 2023년 12월 16일
Hi Tashanda,
I see a couple of issues with the code
Though not an error, it would be clearer if you specified the variable of integration. And it's always best to use sym(pi). With these changes, the equation for b(k) would look like
%b(k) = (2/L)*int(f1*sin(k*pi*x/L),[0,L/2]);
b(k) = (2/L)*int(f1*sin(k*sym(pi)*x/L),x,[0,L/2]);
b(k) = simplify(b(k))
But even with those changes, the equation for b(k) is incorrect. Go back to your source and carefully compare this code to what the equation should be.
Then, the same comments apply to b1(k).
b1(k) = (2/L)*int(f2*sin(k*pi*x/L),[L/2,L]);
Finally, this line is a typo. i don't think you want b(k) on the right hand side.
b1(k) = simplify(b(k))

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by