plot from while loop

2 views (last 30 days)
Dam
Dam on 23 Sep 2012
Hi, to be general, suppose i have written the following code
s=0
figure
while s<10
s=s+0.05
n= (µ-s)./nthroot((µ<s).*(s-µ),3)
plot (s,n)
end
when running, this code is giving me the values of n as points that corresponds to each value of s However, I want to get all the values of n in an array and then to plot them
Thank you to tell me how to modefy the previous code to do this
BEST REGARDS
[EDITED, Jan, code formatted]

Answers (2)

Jan
Jan on 23 Sep 2012
figure
s = 0:0.05:10;
n = zeros(1, length(s));
for ii = 1:length(s)
n(ii) = (my - s(ii)) ./ nthroot((my < s(ii)) .* (s(ii) - my), 3);
end
plot(s,n);

Azzi Abdelmalek
Azzi Abdelmalek on 23 Sep 2012
Edited: Azzi Abdelmalek on 23 Sep 2012
close all
s=0;mu=0.5
figure
set(gca,'xlim',[0.5 10],'ylim',[-5 0])
while s<10
s=s+0.05
n= (mu-s)./nthroot((mu<s).*(s-mu),3)
hold on;plot (s,n,'*r');pause(0.05)
end

Community Treasure Hunt

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

Start Hunting!