필터 지우기
필터 지우기

Need to find difference in maximum and minimum concentration

조회 수: 2 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by