For loop and plotting trouble
1 次查看(过去 30 天)
显示 更早的评论
I need to plot the results of a physics function called the Kohler equation... I tried setting up a loop for a given range of the variable r as such:
m=10^-15;
for r=0.1:100;
S(r)=(exp((2*s)/(n*k*T*r))*((1+((a*m*Mw)/(Ms*(4/3)*pi*(r^3))*p-m)))^-1);
end
SS(S)=100*(S-1);
semilogr (SS)
xlim([0.1 100])
ylim([-1.5 0.5])
> So, the first issue I run into is an error in the function itself:
Attempted to access (0.1); index must be a positive integer or logical.
I seem to remember that there's a simple fix for this, like adding a period somewhere, but I'm not sure where.
> The second issue is that I need to plot this for 5 different values of m: 10^-15, 10^-16, 10^-17, 10^-18, and 10^-19. Would it be practical to set up an additional loop for this? The intervals are different for each value, so I wasn't sure how to do this.
> And then the final issue is that I need to plot r on the x-axis, scaled logarithmically, vs. SS on the y axis, with a linear scale. I'm not sure if I have that set up right...
I'm relatively inexperienced (and also out of practice) with Matlab, so I apologize if some of my questions seem elementary.
0 个评论
回答(4 个)
Image Analyst
2011-11-27
If you want to iterate over r, then you'll need a counter as the index for S, like this
sIndex = 1;
for r=0.1:100;
S(sIndex )=(exp((2*s)/(n*k*T*r))*((1+((a*m*Mw)/(Ms*(4/3)*pi*(r^3))*p-m)))^-1);
sIndex = sIndex + 1;
end
For the second issue, you could have a second, outer loop to loop over the various values of m. You'd want to plot S before the "end" of this outer m loop, unless you want to make S a 2D array.
For the third issue, you can plot r vs. S and it should look right.
plot(0.1:100, S, 'b-');
0 个评论
Mike
2011-11-27
4 个评论
Image Analyst
2011-11-27
So you don't want to make it easy for us to help you by posting typical values for n, k, T, etc. like I asked? Strange. It would be quicker if you helped.
Define what you mean by "output" - does that mean plot, like your call to semilogx() doesn't do anything whatsoever??? If you set a breakpoint right after the loop, are S and Su there?
Nur Fabien Idrissa
2018-12-5
hello Mike!
how did you solve the question. may you share with me the process.
thanks!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!