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

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 个评论

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_x = 1×0 empty double row vector
f_index_t = find(GridPoints_t == flux_location_t)% Time Index
f_index_t =
2
Thank you atleast now i know where is the error but why is the error ?

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by