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. also there is no error in the forumla and all please help me find the error in the computational process only. The error is probably in the for and nested for loop i hope
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
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