Sine Fourier transform (dst) for diffusion PDE

3 views (last 30 days)
Good day, following the exposition presented on this site PDE with FFT I'm trying to solve a simple diffusion equation u_t = u_xx with u(x,0)=3*sin(2*pi*x) and u(0,t)=u(2,t)=0.
Here is my program, but it doesn't produce the correct answer : u(x,t) = 3sin(2pix)e^{-4pi^2t}:
clear all; close all;
n=128;
T=0.1;
L0=0
L=2;
u0=zeros(N,1);
x = linspace(L0,L,N)
u0(1:N)=3*sin(2*pi*x(1:N));
figure
plot(x,u0);
xlabel('x');
ylabel('u0(x,0)');
title('Initial conditions');
figure
% Set up a matrix in which all columns are the same as u0.
A=u0*ones(1,n);
% Compute the sine (or Fourier-) coefficients in each column.
B=(dst(A));
% Multiply Fourier coefficient a_k(t) = a_k exp(-k^2 t).
t=(0:n-1)/(n-1)*T;
p=[0:(N-1)/2 -N/2:-1];
p2=p.*p; W=p2'*t; W=exp(-W); B=B.*W;
% Take the inverse sine (or Fourier-) transform.
u=idst(B);
surf(x,t,u')
axis([0,L,0,T,-3,3])
figure
hold on
plot(x,u(:,1));
xlabel('x');
ylabel('u(x,0)');
plot(x,u0,'+')
%axis([0 L -3 3]);
title('Initial conditions');
hold off
%difference in initial conditions
norm(u(:,1)-u0)
figure
plot(t,u(1,:));
xlabel('t');
ylabel('u(0,t)');
%axis([0 T -3 3]);
title('Boundary condition at L=0');
figure
plot(t,u(end,:));
xlabel('t');
ylabel('u(0,t)');
%axis([0 T -3 3]);
title('Boundary condition at L=2');
figure
plot(x,u(:,end))
title ('at time 0.01')

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!