Need to find difference in maximum and minimum concentration

1 visualización (últimos 30 días)
Dinesh Kumar
Dinesh Kumar el 29 de Mayo de 2020
Respondida: Dinesh Yadav el 2 de Jun. de 2020
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
subplot(11,1,k/100+1);
for m = 1:length(c),
fill(vertices(:,1)+m, vertices(:,2)-k/100,c(m)); hold on
end
caxis([1 32])
h = ylabel(sprintf('t = %gs ',k*dt));
set(gca,'ytick',[],'xticklabel',[],'ticklength',[0 0]); grid on
set(gca,'xtick',1.5:1:100,'gridlinestyle','-','linewidth',4);
set(h,'rotation',0,'horizontalalignment','right','verticalalignment','middle')
end
end
xlabel('x location'); text(16,-14.25,'Diffusion example','horizontalalignment','center');
  3 comentarios
Sindar
Sindar el 31 de Mayo de 2020
what happens when you try? An error or an answer you think is wrong? Regardless, can you share the code you tried?

Iniciar sesión para comentar.

Respuestas (1)

Dinesh Yadav
Dinesh Yadav el 2 de Jun. de 2020
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.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by