What is wrong with this forward difference central space scheme?
1 view (last 30 days)
Show older comments
The differential equation to be solved is the 1D heat equation Uxx-Ut=0 with the initial condition : u(x, 0) = g(x) = sin(pi/2)x for 0<= x< =2 and Boundary Conditions: u(0, t) = 0; u(2, t) = 0 for t > 0. I am getting a zero matrix.
The code is as follows:
function [ U ] = FTCS( M,N )
% Discretization Scheme % N points in space % M points in time
h = 2/(N-1); k = 1/(M-1); tau = k/h^2;
U = zeros(M,N); t = 0; x = 0;
if tau>0.5 'This may yield an unstable solution'; end
%initial condition for j=1:N U(1,j) =0; end
% Boundary Condition 1 for j=1:M U(j,1) = 0; end
% Boundary Condition 2 for j=1:M U(j,N) = 0; end
%internal points
for j=1:M-1 %outer loop for time for i=2:N-1 %inner loop for space U(j+1,i)=tau*U(j,i-1)+(1-2*tau)*U(j,i)+tau*U(j,i+1); end end
end
1 Comment
Torsten
on 21 Aug 2015
What do you expect if you start with U=0 for t=0 and U=0 at both boundaries ?
Best wishes
Torsten.
Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!