Borrar filtros
Borrar filtros

Lopping error while doing 2D (x,t) finite difference method solution for a particle simulation

1 visualización (últimos 30 días)
I tried loops of for and while with if inside but its showing only zeros in the n matrix , some how the loop is not getting incorporated. Please help me finding what is the error in this case particularly.
clear all;
clc
D = 1e-4 * 1e-4 ; % 1e-4 cm^2/sec
J=1e6 * 1e6; %input flux at half
format long;
%% Grid defination
del_x = 1e-9;
del_t=1e-6;
GridPoints_x=0:del_x:10e-6;
GridPoints_t=0:del_t:1e-5;
npoints_x=length(GridPoints_x);
npoints_t=length(GridPoints_t);
n=zeros(npoints_x,npoints_t);
Source = zeros(npoints_x, npoints_t);% Source Profile
flux_location_x = 5 * 1e-6; % Injection Location
flux_location_t = 1 * 1e-6; % Injection Time
f_index_x = find(GridPoints_x == flux_location_x);% Location Index
f_index_t = find(GridPoints_t == flux_location_t);% Time Index
i = 1;
Source(f_index_x, f_index_t) = J ;
tol = 1e-10;
dn=10;
while 1
n_old=n;
for m=2:npoints_t
n_old=n;
for i= 2:npoints_x-1
n(i , m) = ((1/del_x^2) * (n(i + 1, m) + n(i - 1, m)) +n(i, m - 1)/(D * del_t) + Source(i, m) ...
)/(2/del_x^2 + 1 / (D * del_t));
end
n_new=n;
if(abs(n_old-n_new)<=tol)
break
end
end
end
  4 comentarios

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by