complementary error function (surf plot)

I'm new to MATLAB and i'm trying to plot the following function with surf:
.
Parameter values:
My code so far:
x = linspace(0,10^(-6),20);
t = linspace(0,5,5);
u0 = 10^(-6);
k = 10^(-9);
dn = 2.*k.*sqrt(t);
e2 = erf( x.*(dn).^(-1) );
u = u0.*(1 - e2);
surf(x,t,u)
title('Complementary Error function from 0 to 10^(-6)')
xlabel('Distance x')
ylabel('Time t')
I'm trying to get the x between 0 to in increments of and t in increments of .
How do you fix this?

 Accepted Answer

Add:
[X,T] = ndgrid(x,t);
and it works:
x = linspace(0,10^(-6),20);
t = linspace(0,5,5);
[X,T] = ndgrid(x,t);
u0 = 10^(-6);
k = 10^(-9);
dn = 2.*k.*sqrt(T);
e2 = erf( X.*(dn).^(-1) );
u = u0.*(1 - e2);
surf(X,T,u)
title('Complementary Error function from 0 to 10^(-6)')
xlabel('Distance x')
ylabel('Time t')
although you may want to revise the code a bit.

4 Comments

The surf (I used surfc here) plot dedfinitely does show it with the new ranges of ‘x’ and ‘t’:
x = (0:0.01:1)*1E-7;
t = logspace(log10(50), log10(300), 10);
[X,T] = meshgrid(x,t);
u0 = 1E-6;
k = 1E-9;
dn = 2.*k.*sqrt(T);
e2 = erf( X./dn );
u = u0.*(1 - e2);
figure
surfc(X,T,u)
title('Complementary Error function from 0 to 10^(-6)')
xlabel('Distance x')
ylabel('Time t')
I also used logspace to define ‘t’ to provide a more gradual transition, and with this minor modification:
x = (0:0.01:1)*1E-7;
t = logspace(log10(50), log10(300), 10);
[X,T] = meshgrid(x,t);
u0 = 1E-6;
k = 1E-9;
dn = 2.*k.*sqrt(T);
e2 = erf( X./dn );
u = u0.*(1 - e2);
figure
surfc(X,T,u)
set(gca, 'YScale','log')
title('Complementary Error function from 0 to 10^(-6)')
xlabel('Distance x')
ylabel('Time t')
it actually looks better.
Just want to point out that the erfc function can be used directly, and it might be appropriate to use for this problem because u is getting quite small but shouldn't be identically zero. I guess it depends on what, if anything, is to be done with u down stream.
Thank you StarStrider and Paul for your explanations.
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!