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 comentario

Jakub Bialek
Jakub Bialek el 18 de Nov. de 2016
Tiki did you manage to produce similar graphs for your AS solution? I mean for different Dp... How do oyu specify Dp?

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 19 de Nov. de 2015

1 voto

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 comentarios

Tiki
Tiki el 19 de Nov. de 2015
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
Star Strider
Star Strider el 19 de Nov. de 2015
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 (%)')
Tiki
Tiki el 19 de Nov. de 2015
Perfect. Thank you so much for your help!
Star Strider
Star Strider el 19 de Nov. de 2015
Thank you. My pleasure!
Nur Fabien Idrissa
Nur Fabien Idrissa el 5 de Dic. de 2018
Editada: Nur Fabien Idrissa el 5 de Dic. de 2018
can you show the equation presented in the above solution.
thanks.
is it like this?Screenshot_4.png
Rik
Rik el 5 de Dic. de 2018
@Nur, please don't use flags for comments. You should only flag an answer/comment if it requires attention from staff members.
Star Strider
Star Strider el 5 de Dic. de 2018
@Nur Fabien Idrissa — I have no idea. Look at it to see if it matches.
@Rik — Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Nov. de 2015

Comentada:

el 5 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by