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
|
|
| fftpoi.m |
% fftpoi - Program to solve the Poisson equation using
% MFT method (Periodic boundary conditions)
clear; help fftpoi; % Clear memory and print header
eps0 = 8.8542e-12; % Permittivity (C^2/(N m^2))
N = 32; % Number of grid points on a side (square grid)
L = 1; % System size
h = L/N; % Grid spacing for periodic boundary cond.
x = ((1:N)-1/2)*h; % Coordinates of grid points
y = x; % Square grid
fprintf('System is a square of length %g \n',L);
% Set up charge density rho(i,j)
rho = zeros(N,N); % Initialize charge density to zero
M = input('Enter number of line charges - ');
for i=1:M
fprintf('\n For charge #%g \n',i);
r = input('Enter position [x y] - ');
ii=round(r(1)/h + 1/2); % Place charge at nearest
jj=round(r(2)/h + 1/2); % grid point
q = input('Enter charge density - ');
rho(ii,jj) = rho(ii,jj) + q;
end
disp('Computing matrix P')
coeff = 2*pi/N;
cx = cos(coeff*(0:N-1));
cy = cx;
for i=1:N
for j=1:N
P(i,j) = 1/(cx(i)+cy(j)-2);
end
end
P(1,1) = 0; % Clean up divide by zero
P = -h^2/(2*eps0) * P; % Throw in the factor in front
disp('Computing potential and E field');
rhoT = fft2(rho); % Transform rho into frequency domain
phiT = rhoT .* P; % Computing phi in the frequency domain
phi = ifft2(phiT); % Inv. transf. phi into the real domain
[Ex Ey] = gradient(rot90(phi)); % Compute E field using
temp = sqrt(Ex.^2 + Ey.^2); % E = - grad phi
Ex = -Ex ./ temp; % Normalize components so
Ey = -Ey ./ temp; % vectors are equal length
% Plot potential and E field
axis('square'); % Use a square aspect ratio
subplot(121)
contour(rot90(phi),15,x,y); % Contour plot of potential
title('Potential'); xlabel('x'); ylabel('y');
subplot(122)
[xmax ymax] = size(Ex);
axis([0 xmax+1 0 ymax+1]);
quiver(Ex,Ey) % Plot E field with vectors
title('E-field (Direction)'); xlabel('i'); ylabel('j');
subplot(111)
axis; axis('normal'); % Reset auto-scaling and normal axes
|
|
Contact us at files@mathworks.com