Finite Difference Implicit Method for Fick's 2nd Law

버전 1.0.0 (1.97 KB) 작성자: Roche de Guzman
PDE solution using the implicit method
다운로드 수: 141
업데이트 날짜: 2019/4/26

라이선스 보기

%% Finite Difference Implicit Method (Matrix Equations) with D = diffusivity: Fick's 2nd Law of Diffusion
% by Prof. Roche C. de Guzman
clear; clc; close('all');
%% Given
xi = 0; xf = 0.6; dx = 0.04; % x range and step size = dx [m]
xL = 0; xU = 0.1; % initial value x lower and upper limits [m]
ti = 0; tf = 0.05; dt = 4e-4; % t range and step size = dt [s]
ci = 2; % initial concentration value [ng/L]
cLU = 8; % initial concentration value within x lower and upper limits [ng/L]
D = 1.5; % diffusivity or diffusion coefficient [m^2/s]
%% Calculations
% Independent variables: x and t
X = xi:dx:xf; nx = numel(X); T = ti:dt:tf; nt = numel(T); % x and t vectors and their number of elements
[x,t] = meshgrid(X,T); x = x'; t = t'; % x and t matrices
% Dependent variable: c
c = ones(nx,nt)*ci; % temporary c(x,t) matrix with rows: c(x) and columns: c(t)
% Initial values and Dirichlet boundary
I = find((X>=xL)&(X<=xU)); % index of lower and upper limits
c(I,1) = cLU; % c at t = 0 for lower and upper limits
% Matrix of coefficients
muD = (dt/dx^2)*D;
M = diag([1 ones(1,nx-2)*(1+2*muD) -1])... % main diagonal
+ diag([-1 ones(1,nx-2)*-muD],1)... % 1st superdiagonal
+ diag([ones(1,nx-2)*-muD 1],-1); % 1st subdiagonal
% Vector of unknowns per time point
for j = 1:nt-1
K = [0; c(2:nx-1,j); 0]; % column vector of constants
U = M\K; % column vector of unknowns
c(:,j+1) = U; % concentration matrix
end

인용 양식

Roche de Guzman (2024). Finite Difference Implicit Method for Fick's 2nd Law (https://www.mathworks.com/matlabcentral/fileexchange/71358-finite-difference-implicit-method-for-fick-s-2nd-law), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2019a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0