Verifying Fourier Series In MATLAB

Click For Summary

Discussion Overview

The discussion revolves around verifying a MATLAB implementation of Fourier series calculations, specifically focusing on the computation of coefficients and the series sum itself. Participants explore potential errors and simplifications in the code provided.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant requests verification of their MATLAB code for calculating the Fourier series of the hyperbolic cosine function.
  • Another participant suggests that the calculation of the series sum could be simplified and points out potential errors in the Fourier series implementation.
  • A further suggestion is made to calculate the coefficients an and bn inside the loop to avoid unnecessary storage, which could enhance efficiency.

Areas of Agreement / Disagreement

Participants express differing views on the correctness of the original Fourier series implementation, with some proposing corrections and simplifications while others do not explicitly agree or disagree on the overall validity of the initial approach.

Contextual Notes

Limitations include the assumption of convergence for the series and the handling of infinite sums, which may not be fully addressed in the provided code.

Jovany_17
Messages
2
Reaction score
0
HI please help me this could someone verify it for me please find attachement

clc;
clear all;
k=0;
s=0;
N=inf;
for i=1:N
s=s+(1/(k^2+1));
k=k+1;
end

syms x n
a0=1/pi*int(cosh(x),-pi,pi);
an=1/pi*int(cosh(x)*cos(n*x),-pi,pi);
bn=1/pi*int(cosh(x)*sin(n*x),-pi,pi);

fs=0;

for l=0:100
fs=fs+(an*cos(l*x)+bn*sin(l*x))
end

fs-fs+a0/2;
 

Attachments

  • TD.jpg
    TD.jpg
    6.2 KB · Views: 658
Physics news on Phys.org
Jovany_17 said:
HI please help me this could someone verify it for me please find attachement

clc;
clear all;
k=0;
s=0;
N=inf;
for i=1:N
s=s+(1/(k^2+1));
k=k+1;
end

syms x n
a0=1/pi*int(cosh(x),-pi,pi);
an=1/pi*int(cosh(x)*cos(n*x),-pi,pi);
bn=1/pi*int(cosh(x)*sin(n*x),-pi,pi);

fs=0;

for l=0:100
fs=fs+(an*cos(l*x)+bn*sin(l*x))
end

fs-fs+a0/2;
The calculation of s looks OK. It could have been done slightly easier.
N=inf;
s=1;
for k = 1:N
s=s+(1/(k^2+1));
end
The Fourier series sum has a couple of errors. I would do the following:
fs = a0/2;
N = inf;
for n = 1:N
fs=fs+(an*cos(n*x)+bn*sin(n*x));
end
 
Thanks
 
A further simplification: Except for a0, the values of an and bn can be calculated inside the loop, so they don't have to be stored in advance.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K