Need to find difference in maximum and minimum concentration
조회 수: 5 (최근 30일)
In below given script i need to find difference in maximum and minimum concentration at t=0 time stamp. what change i need in given script.
c = 1:32; % initial concentration gradient (mol/(m^2*s))
D = 2; % diffusivity (m^2/s)
dt = 0.1; % time step (s)
dx = 1; % x step (m)
for k = 0:1000,
% finite-difference diffusion using explicit method, central differences
c = c + D*dt/(dx^2)*([c(2:end) c(end)] - 2*c + [c(1) c(1:end-1)]);
% The MATLAB *plotting* code presented in the lesson does not work inside the Jupyter-notebook
% Octave environment. Instead of using the "image" command, we need to "fill" individual boxes.
vertices = [0 0; 1 0; 1 1; 0 1];
if mod(k,100) == 0, % plot a snapshot
for m = 1:length(c),
fill(vertices(:,1)+m, vertices(:,2)-k/100,c(m)); hold on
h = ylabel(sprintf('t = %gs ',k*dt));
set(gca,'ytick',,'xticklabel',,'ticklength',[0 0]); grid on
xlabel('x location'); text(16,-14.25,'Diffusion example','horizontalalignment','center');
Dinesh Yadav 2020년 6월 2일
As Darova pointed out just use
minConc = min(c);
maxConc = max(c);
to get minium and maximum concentration at t = 0. And its working I tried with your code itself. Make sure you are not overwriting minimum and maximum concentration computed at t=0 as your loop is running for 1001 times.