Plotting curves using loops?

I'm trying to figure out a simple code to plot supersaturation values against the size of a particle. I have everything I need, just having trouble plotting multiple values for the radius. I'm using a loop as it seems the most logical when plotting so many values.
T = 293;
k = 1.38*10^-23;
o = 75.64*10^-3;
n = 3.348*10^28;
Ms = .13214;
Mw = .018;
p = 1769;
i = 3;
m=10^-16;
EIndex = 1
for r = 0.01:100
E(EIndex) = (exp((2*o)/(n*k*T*r)))*((1+((i*m*Mw)/(Ms*(((4/3)*pi*(r^3)*p)-m))))^-1)
EIndex = EIndex + 1
S(EIndex)=100*E - 100;
end
semilogx(S)
xlim([0.01 100])
ylim([-1.5 0.5])
I've tried various setups and get error such as "indices need to be positive" or the current "In an assignment A(:) = B, the number of elements in A and B must be the same."
Simply put I want to
  1. plot values for r (radius) on the x axis logarithmic from .01 - 100
  2. plot values for S (supersaturation) on the y axis linearly from 80-100.5%
The end result should look like a Kohler curve similar to below
Any help would be greatly appreciated!

1 Comment

Tiki did you manage to produce similar graphs for your AS solution? I mean for different Dp... How do oyu specify Dp?

Sign in to comment.

 Accepted Answer

This eliminates the loop but doesn’t produce the plot you want. (The plot actually looks as though it’s inverted.) What equation are you coding?
T = 293;
k = 1.38E-23;
o = 75.64E-3;
n = 3.348E28;
Ms = .13214;
Mw = .018;
p = 1769;
i = 3;
m=1E-16;
r = linspace(1E-6, 1E-4, 1000);
E = 1./(exp((2*o)./(n*k*T*r))).*((1+((i.*m.*Mw)./(Ms.*(((4/3)*pi*(r.^3).*p)-m)))));
S = 100*E - 100;
figure(1)
semilogx(r, S)

7 Comments

Here is the equation.
E = [exp(2o/nkTr)] * [1 + (imMw)/Ms{(4/3)(pi)(r^3)(p)-m}]^-1]
Sorry just realized I left out the ^-1 at the end. That actually puts the curve right side up.
Thank you for eliminating the loop, I tried that to start and couldn't even get a curve to appear.
Now I'm just looking to have the x axis be values scaled logarithmic-ally from .01-100 and the y axis values in percent from 80 - 100.5
Yoyu didn’t leave it out, I miscounted parentheses and put the division in the wrong place. The ‘E’ assignment should be:
E = (exp((2*o)./(n*k*T*r))).*(1./(1+((i.*m.*Mw)./(Ms.*(((4/3)*pi*(r.^3).*p)-m)))));
The entire code seems to produce the sort of plot you want:
T = 293;
k = 1.38E-23;
o = 75.64E-3;
n = 3.348E28;
Ms = .13214;
Mw = .018;
p = 1769;
i = 3;
m=1E-16;
r = linspace(9E-7, 1E-4, 1000);
E = (exp((2*o)./(n*k*T*r))).*(1./(1+((i.*m.*Mw)./(Ms.*(((4/3)*pi*(r.^3).*p)-m)))));
S = 100*E - 100;
figure(1)
semilogx(r, S)
xlim([0.1 100]*1E-6)
ylim([-0.5 0.5])
xtk = get(gca, 'XTick');
set(gca, 'Xtick',[xtk xtk(end)*10], 'XTickLabel',[xtk xtk(end)*10]*1E+6)
xlabel('Wet Diameter (\mum)')
ylabel('Supersaturation (%)')
Perfect. Thank you so much for your help!
Thank you. My pleasure!
can you show the equation presented in the above solution.
thanks.
is it like this?Screenshot_4.png
@Nur, please don't use flags for comments. You should only flag an answer/comment if it requires attention from staff members.
@Nur Fabien Idrissa — I have no idea. Look at it to see if it matches.
@Rik — Thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 19 Nov 2015

Commented:

on 5 Dec 2018

Community Treasure Hunt

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

Start Hunting!