필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by