Plotting a Distribution of Molecules
Show older comments
Need a figure for c(x,t)
t1=0;
t2=600;
t3=1200;
t4=1800;
t5=2400;
t6=3000;
t7=3600;
D=5e-9;
Co=1;
𝛿(𝑥−𝑥0)→∞ 𝑎𝑡 𝑥=𝑥0, and 𝛿(𝑥−𝑥0)=0 𝑓𝑜𝑟 𝑥≠𝑥0.
where 𝑐(𝑥,𝑡)= (Co/(sqrt(4*pi*D*t1)))exp^(-(x-xo)^2)/(4*D*t))
Answers (1)
Star Strider
on 15 Nov 2020
Specifically:
x = linspace(-5, 5);
y = gradient(erf(x)) ./ gradient(x);
figure
plot(x, y)
grid
.
4 Comments
elle morey
on 15 Nov 2020
Star Strider
on 15 Nov 2020
Those are simply the independent variable limits I (abitrarily) set.
Experiment to get the result you want, since using your ‘c’ equation keeps producing NaN for me, so nothing plots.
Use an anonymous function representation to code it:
c = @(x,t) (Co./(sqrt(4*pi*D*t1))) .* exp(-((x-xo).^2)./(4*D*t));
then provide an appropriate range of values for the arguments.
Stopping here.
elle morey
on 15 Nov 2020
Star Strider
on 15 Nov 2020
No.
For a 3D plot (for a function with two arguments) use one of the surface plot functions.
t1=0;
t2=600;
t3=1200;
t4=1800;
t5=2400;
t6=3000;
t7=3600;
D=5e-9;
Co=1;
xo = 0;
c = @(x,t) (Co./(sqrt(4*pi*D*t1))) .* exp(-((x-xo).^2)./(4*D*t));
figure
fsurf(c, [1 10 0 10])
[X,T] = ndgrid(-5:01:5, 0.1:10);
figure
mesh(X, T, c(X,T))
grid on
This runs without error, however it doesn’t plot anything since all the elements of the matrix that ‘c’ produces are NaN.
You need to resolve that problem, so something shows up on the plot. I have no idea what you’re doing, so I can’t help you with that.
Categories
Find more on Graphics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!