No BSD License
-
...
sampler - function to sample density and velocities
-
...
sampler - function to sample density and velocities
-
FNewt(x,a)
Function used by the N-variable Newton's method
-
NaiveGE(a,b)
Forward elimination
-
bess(m_max,x)
Function to calculate of Bessel function
-
bess(m_max,x)
Function to calculate of Bessel function
-
colide(v,cell_n,...
colide - Function to process collisions in cells
-
colide(v,cell_n,...
colide - Function to process collisions in cells
-
fnewt(x,a)
Function used by the N-variable Newton's method
-
fund(x,n)
Return function value or derivative
-
fund(x,n)
Return function value or derivative
-
gravrk(s,time,GM)
The time is not used in this version
-
gravrk(s,time,GM)
The time is not used in this version
-
intrpf(xi,x,y)
Function to interpolate between data points
-
intrpf(xi,x,y)
Function to interpolate between data points
-
legndr(n,x)
Legendre polynomials
-
legndr(n,x)
Legendre polynomials
-
linreg(x,y,sigma)
Function to perform linear regression (fit a line)
-
linreg(x,y,sigma)
Function to perform linear regression (fit a line)
-
lorzrk(a,time,param)
Function to define the Lorenz model equations
-
lorzrk(a,time,param)
Function to define the Lorenz model equations
-
mover(x,v,npart, ...
mover - Function to move particles by free flight
-
mover(x,v,npart, ...
mover - Function to move particles by free flight
-
my_f(x,param)
Error function integrand
-
my_f(x,param)
Error function integrand
-
naivege(a,b)
x=naivege(a,b) performs naive (no pivoting) Gaussian elimination
-
pollsf(x, y, sigma, M)
Function to fit a polynomial to data
-
pollsf(x, y, sigma, M)
Function to fit a polynomial to data
-
rk4(x,t,tau,derivsRK,param)
Runge-Kutta integrator (4th order)
-
rk4(x,t,tau,derivsRK,param)
Runge-Kutta integrator (4th order)
-
rkA(x,t,tau,err,derivsRK,para...
Adaptive Runge-Kutta routine
-
rka(x,t,tau,err,derivsRK,para...
Adaptive Runge-Kutta routine
-
rombf(a,b,N,func,param)
Function to compute integrals by Romberg algorithm
-
rombf(a,b,N,func,param)
Function to compute integrals by Romberg algorithm
-
sorter(x,npart,ncell,L)
sorter - Function to sort particles into cells
-
sorter(x,npart,ncell,L)
sorter - Function to sort particles into cells
-
spinview(nviews,wait)
spinview - Routine to rotate a 3D plot
-
sprrk(a,time,param)
Function to compute 3 mass-spring system
-
sprrk(a,time,param)
Function to compute 3 mass-spring system
-
tri_GE(a,b)
Function to solve b = a*x by Gaussian elimination where
-
tri_GE(a,b)
Function to solve b = a*x by Gaussian elimination where
-
yt=sft(y)
Slow Fourier transform function
-
yt=sft(y)
Slow Fourier transform function
-
zeroj(m_order,n_zero)
Function which returns the zeros of the Bessel function J(x)
-
zeroj(m_order,n_zero)
Function which returns the zeros of the Bessel function J(x)
-
aftcs.m
-
aftcs.m
-
aftcs_p.m
-
balle.m
-
balle.m
-
balle_p.m
-
contents.m
-
contents.m
-
contents.m
-
contents.m
-
deriv.m
-
deriv.m
-
deriv_p.m
-
dftcs.m
-
dftcs.m
-
dftcs_p.m
-
dsmceq.m
-
dsmceq.m
-
dsmceq_p.m
-
dsmcne.m
-
dsmcne.m
-
dsmcne_p.m
-
factn.m
-
factn.m
-
facts.m
-
facts.m
-
fftpoi.m
-
fftpoi.m
-
fftpoi_p.m
-
galrkn.m
-
galrkn.m
-
galrkn_p.m
-
interp.m
-
interp.m
-
interp_p.m
-
jacobi.m
-
jacobi.m
-
jacobi_p.m
-
lorenz.m
-
lorenz.m
-
lorenz_p.m
-
lsftest.m
-
lsftest.m
-
lsftst_p.m
-
newtn.m
-
newtn.m
-
newtn_p.m
-
orbe.m
-
orbe.m
-
orbe_p.m
-
orbec.m
-
orbec.m
-
orbrk.m
-
orbrk.m
-
orbrka.m
-
orbrka.m
-
orthog.m
-
orthog.m
-
pendul.m
-
pendul.m
-
pendul_p.m
-
pendulv.m
-
pendulv.m
-
rndoff.m
-
rndoff.m
-
rndoff_p.m
-
schro.m
-
schro.m
-
schro_p.m
-
schrot.m
-
schrot.m
-
sftdem_p.m
-
sftdemo.m
-
sftdemo.m
-
sprfft.m
-
sprfft.m
-
sprfft_p.m
-
traffic.m
-
traffic.m
-
trafic_p.m
-
View all files
|
|
| dftcs.m |
% dftcs - Program to solve the diffusion equation
% using the FTCS scheme
clear; help dftcs; % Clear memory and print header
tau = input('Enter time step - ');
N = input('Enter the number of grid points - ');
L = 1.; % The system extends from x=-L/2 to x=L/2
h = L/(N-1); % Grid size
kappa = 1.; % Diffusion coefficient
coeff = kappa*tau/h^2;
if( coeff < .5 )
disp('Solution is expected to be stable');
else
disp('WARNING: Solution is expected to be unstable');
end
%%%%% Initial conditions and boundary conditions %%%%%
tt = zeros(N,1); % Initialize temperature to zero at all points
tt_new = zeros(N,1); % Initialize temporary array used by FTCS
tt(N/2) = 1/h; % Initial cond. is delta function in center
%% The boundary conditions are tt(1) = tt(N) = 0
%%%%% Set up loop and plot variables %%%%%
xplot = (0:N-1)*h - L/2; % Record the x scale for plots
iplot = 1; % Counter used to count plots
nstep = 250; % Maximum number of iterations
nplots = 25; % Number of snapshots (plots) to take
plot_step = nstep/nplots; % Number of time steps between plots
%%%%% MAIN LOOP %%%%%
for istep=1:nstep
% FTCS scheme
tt_new(2:(N-1)) = tt(2:(N-1)) + ...
coeff*(tt(3:N) + tt(1:(N-2)) - 2*tt(2:(N-1)));
tt = tt_new; % Reset temperature to new values
if( rem(istep,plot_step) < 1 ) % Every plot_step steps
ttplot(:,iplot) = tt(:); % record tt(i) for plotting
tplot(iplot) = istep*tau; % Record time for plots
iplot = iplot+1;
fprintf('%g out of %g steps completed\n',istep,nstep);
end
end
subplot(121)
mesh(tplot,xplot,ttplot);
view([-70 30]);
xlabel('Time'); ylabel('x');
title('Diffusion of a delta spike');
subplot(122)
cs = contour(xplot,tplot,flipud(rot90(ttplot)),0:.5:5);
xlabel('x'); ylabel('Time'); clabel(cs,0:5);
title('Contour plot');
subplot(111)
|
|
Contact us at files@mathworks.com