Solving a PDE using spectral methods in Matlab

  • MATLAB
  • Thread starter nickthequick
  • Start date
  • Tags
    Matlab Pde
It may also be helpful to consult with someone experienced in numerical methods for guidance on how to improve the code and address any limitations.
  • #1
nickthequick
53
0
Hi,

I'm trying to solve the PDE
[tex] u_{tt}-c^2u_{xx}=\omega E_{xx} [/tex] where

[tex]E= A(x)Sech^2\left(\frac{x-ct}{B(x)}+\delta(x)\right) [/tex]

To this end, I take the temporal Fourier Transform of the PDE to find that the governing equation is the forced simple harmonic oscillator:

[itex] \hat{u}_{xx}+\frac{\sigma^2}{c^2} \hat{u}=\frac{\omega}{c^2}\hat{E}_{xx} [/itex]

Expanding the RHS as a Fourier series -

[itex] \hat{E}_{xx}=\sum_n a_n \cos k_n x [/itex] means that

[tex] \hat{u}=\frac{\omega}{c^2}\sum_n \frac{a_n}{(\sigma/c)^2 -k_n^2}[/tex] and finally one can find u by taking the inverse Fourier transform of [itex]\hat{u}[/itex].

My issue is coding this up, since it appears that I'm getting nothing but nonsense for a solution. I am definitely a novice in numerical methods and I would like some input from someone with some experience about whether or not this type of method is good in this situation. Also, since I believe my code is doing what I intend it to, are there any limitations to this method that could account for my seemingly incongruous solutions? Thanks!

Nick **here F3 is the prescribed forcing function and E_hat_t is [itex] \hat{E}_{xx}[/itex]
**positiveFFT finds the positive FT as well as the associated frequencies

% E_hat_t=zeros(length(x1),length(t)/2);
% f_E_t=zeros(length(x1), length(t)/2);
% for i = 1:length(x1);
% [E_hat_t(i,:),f_E_t(i,:)]=positiveFFT(F3(i,1:length(t)),Xs1);
% end
%
% E_hat_x1= zeros((length(x1))/2,length(t)/2);
% f_E_x1=zeros((length(x1))/2,length(t)/2);
% for i =1:(length(EDa(1,:)))/2
% [E_hat_x1(:,i),f_E_x1(:,i)]=positiveFFT(E_hat_t(:,i),Xs1);
% end
%
u_hat=zeros((length(x1))/2,length(t)/2);
for i=2:(length(x1))/2
for j=2:length(t)/2
u_hat(i,j)=real(omega_c/(g*H).*(E_hat_x1(i,1)+2*sum(E_hat_x1(i,:).*exp(sqrt(-1)*2*pi*f_E_x1(i,:)*x1(i))./((2*pi*f_E_t(i,j)).^2/(g*H)-(2*pi*f_E_x1(i,:)).^2))));
end
end

% u=zeros(length(x1)/2,length(t)/2);
% for i=2:(length(x1)-1)/2
% for j=2:length(t)/2
% u(i,j)= u_hat(i,1)+2*sum(u_hat(i,:).*exp(sqrt(-1)*f_E_t(i,:)*t(j)));
% end
% end
 
Physics news on Phys.org
  • #2
Unfortunately, there are some limitations to this method that could be contributing to the seemingly incongruous solutions. The most important limitation is that Fourier transforms assume the solution is periodic in both the spatial and temporal domains. If this is not the case, then the Fourier transform will not accurately capture the behavior of the solution and the resulting solution will not be valid. Additionally, this method may also suffer from numerical errors due to discretization of the domain, truncation of the Fourier series, and other numerical approximations. To ensure accuracy, it is important to use a numerical method that considers the boundary conditions and the physical properties of the problem.
 

1. What are spectral methods in Matlab?

Spectral methods in Matlab refer to the use of mathematical techniques such as Fourier transforms, Chebyshev polynomials, and Legendre polynomials to solve partial differential equations (PDEs). These methods are based on representing the solution of a PDE as a combination of basis functions, allowing for high accuracy and efficiency.

2. How do spectral methods differ from other numerical methods?

Spectral methods differ from other numerical methods, such as finite difference or finite element methods, in that they do not require the PDE to be discretized into a system of algebraic equations. Instead, spectral methods directly solve the PDE in its continuous form, leading to higher accuracy and faster convergence.

3. What are the advantages of using spectral methods in Matlab?

One of the main advantages of using spectral methods in Matlab is their high accuracy, especially for smooth solutions. These methods also have a high order of convergence, meaning that they can achieve accurate solutions with a relatively small number of grid points. Additionally, spectral methods can handle a wide range of boundary conditions and are not limited to regular geometries.

4. What are the limitations of using spectral methods in Matlab?

One limitation of spectral methods in Matlab is that they can be computationally intensive, especially for problems with complex geometries or discontinuous solutions. They also require a high level of mathematical understanding and programming skills to implement effectively. Additionally, spectral methods may struggle with solutions containing sharp gradients or discontinuities.

5. How do I implement spectral methods in Matlab?

The implementation of spectral methods in Matlab involves several steps, including choosing an appropriate basis function, discretizing the PDE, solving the resulting system of algebraic equations, and post-processing the solution. There are also several built-in functions and packages in Matlab that can assist with the implementation of spectral methods, such as the "chebfun" package for working with Chebyshev polynomials.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top