File Exchange

## Fick's 2nd Law of Diffusion using Method of Lines

version 1.0.0 (1.98 KB) by Roche de Guzman

### Roche de Guzman (view profile)

PDE solution using Method of Lines

Updated 26 Apr 2019

%% Method of Lines with D = diffusivity: Fick's 2nd Law of Diffusion
% by Prof. Roche C. de Guzman
%% Custom fx
function Y1 = F(~,Y,D,nx,dx)
c = Y; % assign concentration as Y
Y1 = zeros(nx,1); % temporary derivatives
for i = 1:nx-2 % position counter
Y1(i+1) = D*(c(i+2)-2*c(i+1)+c(i))/dx^2; % solve for derivatives
end
Y1 = [Y1(2); Y1(2:nx-1); Y1(nx-1)]; % derivatives with zero-flux boundary
end

### Cite As

Roche de Guzman (2020). Fick's 2nd Law of Diffusion using Method of Lines (https://www.mathworks.com/matlabcentral/fileexchange/71354-fick-s-2nd-law-of-diffusion-using-method-of-lines), MATLAB Central File Exchange. Retrieved .

Lukas Arndt

### Lukas Arndt (view profile)

Is there a reason why you're using the Dirichlet function for this problem? Second question: Why do I have to define xL and xU?

Best

##### MATLAB Release Compatibility
Created with R2019a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux