Need to find difference in maximum and minimum concentration

3 ビュー (過去 30 日間)
Dinesh Kumar
Dinesh Kumar 2020 年 5 月 29 日
回答済み: Dinesh Yadav 2020 年 6 月 2 日
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 件のコメント
Dinesh Kumar
Dinesh Kumar 2020 年 5 月 29 日
it is not working.
Sindar
Sindar 2020 年 5 月 31 日
what happens when you try? An error or an answer you think is wrong? Regardless, can you share the code you tried?

サインインしてコメントする。

回答 (1 件)

Dinesh Yadav
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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by