Water Filtration Problem for a class

3 views (last 30 days)
Troy Brown
Troy Brown on 18 Jul 2019
Edited: Troy Brown on 19 Jul 2019
I need to find the minimum number of stages that are needed to remove 99% of the initial impurity level of water.
I have a FOR loop set up to due the filtration like so:
for n = 1:21
n_stage(n) = n-1:
y(n) = (1/3)^(n-1);
if (y(n) <= 0.01) Here's where my issues start.
n_1p(n) = n_stage(n);
y_1p(n) = y(n);
end
end
fprintf('Minimum number of stage for 99%% filtration = %d, impurity level = %f\n',n_1p,y_1p);
#1: I'm getting two many answers because I'm not sure how to get the IF statement to stop.
#2: When it prints, it doesn't print the filtration stage (n_1p) nor the impurity level (y_1p) as would expect.
My programming skills are kinda lackluster. This is for a class I'm taking to help with said skills. Any help would be greatly appreciated.
  6 Comments
Walter Roberson
Walter Roberson on 19 Jul 2019
Note: the syntax for counting down would be 21:-1:1
Troy Brown
Troy Brown on 19 Jul 2019
Edited: Troy Brown on 19 Jul 2019
Thanks for the help folks. In the end, one of you said something that sparked some recollection back to the lecture notes. I ended up using "find".
ind = find(y <= 0.01);
n_1p = ind(1,1)-1;
I then altered my "fprintf" line a bit and everything worked like a charm.
Thanks again!!

Sign in to comment.

Answers (0)

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!