필터 지우기
필터 지우기

Plot at t = 0, 0.001, 0.01, and 10 in one plot

조회 수: 6 (최근 30일)
Jennifer Yang
Jennifer Yang 2018년 8월 1일
댓글: Jennifer Yang 2018년 8월 1일
Hello,
I'm solving for a time dependent pde. I was wondering how do I plot multiple lines on the same plot at specific time points (ex. at t=0,0.001,0.01,10)?
function simple_time_dependent_pdepe
clear all; close all; clc;
%
D_ij = 1*10^-6; %Diffusion coefficient D (3.0*10^-7 cm^2/s -> 30 um^2/s)
L0 = 1; %c0 [nM]
x_f =0.02; %Length of domain [um]
maxt = 10; %Max simulation time [s]
%
m = 0; %Parameter corresponding to the symmetry of the problem
x = linspace(0,x_f,100); %xmesh
t = linspace(0,maxt,100); %tspan
%
sol = pdepe(m,@DiffusionPDEfun,@DiffusionICfun,@DiffusionBCfun,x,t,[]);
u = sol;
%
% Plotting
hold all
for n = linspace(1,length(t),10)
plot(x,sol(n,:),'LineWidth',2)
end
title('Time Dependent')
xlabel('Distance (\mum)')
ylabel('Concentration (nM)')
axis([0 x_f 0 L0])
%
function [c,f,s] = DiffusionPDEfun(x,t,u,dudx)
D = D_ij;
%
%Rate constants
k_1 = 0.25;
R_L = -k_1.*u;
%
% PDE
c = 1;
f = D_ij.*dudx;
s = R_L;
end
%
function u0 = DiffusionICfun(x)
u0 = 0;
end
%
function [pl,ql,pr,qr] = DiffusionBCfun(xl,ul,xr,ur,t)
c0 = L0;
pl = ul-c0;
ql = 0;
pr = 0;
qr = 1;
end
end

답변 (1개)

KSSV
KSSV 2018년 8월 1일
YOu should involve, space also while plotting. How about this approach?
[t,x,sol] =simple_time_dependent_pdepe() ;
[X,T] = meshgrid(x,t) ;
figure
surf(X,Y,sol)
ti = [0,0.001,0.01,10] ;
xi = x ;
[Xi,Ti] = meshgrid(x,ti) ;
soli = interp2(X,T,sol,Xi,Ti) ;
figure(2)
surf(Xi,Ti,soli)
  댓글 수: 1
Jennifer Yang
Jennifer Yang 2018년 8월 1일
Hello, Thank you for answering!
I'm a bit confused. That would replace the plotting section in my code right? When I tried running it, I get the error of "Too many output arguments"

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by