Stopping a chart at a certain value.

%For example
%Lets say I made a program for finding radiation decay in a box of some sort. The half life for the radioactive element is every 3 days, and I have to track it until it reaches just before 1/10th of the given safe exposure value of .466.
%So, I simple create and while loop that halves the input, and adds 3 (days) to the output on the chart?
%The example given, with lets say a input value of 150:, It displays:
%Day | Radiation(Status)
%0 150(Unsafe)
%3 75(Unsafe)
%6 37.5(Unsafe)
%9 18.75(Unsafe)
%12 9.375(Unsafe)
%15 4.6875(Unsafe)
%18 2.3438(Unsafe)
%21 1.1719(Unsafe)
%24 0.58594(Unsafe)
%27 0.29297(Safe)
%30 0.14648(Safe)
%33 0.073242(Safe)
%How do I get my code to stop the chart when the radiation level reaches just BEFORE 1/10 of a value (.466) like in this case? My code only displays the ending value, and that is at 36 days, which is incorrect according to this example.
%What I have so far:
% 1. Prompt for Input Data
x=input('Enter ammount of radiation exposure:');
y=0;
while x>(.466/10)*2;
if x>=(.466/10);
x=x/2;
y=y+3;
a=('Unsafe')
m=x
n=y
end
end
a=('Safe')
disp(['Days ', num2str(n), ' Radiation Level = ', num2str(m) , num2str(a)])
%Do I need to create some kind of matrix instead to display and track the half life every 3 days?
%Sorry if I am being a bit unclear.

2 Comments

Note: the "if" statement within the "while" is not doing anything useful in that code. You know the condition is true or else the "while" would have stopped already.
Understood.

Sign in to comment.

 Accepted Answer

Thanks again for the help, I looked back at it and worked out all the kinks, and got it to display correctly now as well. Here is what I was going for:
x=input('Enter ammount of radiation exposure in millirem:');
y=0;
while x > (.466/10)*2;
if x>(.466/10);
x=x/2';
y=y+3';
end
if x>.466;
a=(' (Unsafe)');
else x<.466;
a=(' (Safe)');
end
disp(['Day: ', num2str(y), ' Radiation Level= ', num2str(x), num2str(a)])
end

More Answers (1)

Assuming you will be continuing with dividing by 2, change your condition to
while x > (.466/10)*2

1 Comment

Thank you! That solved the issue with it not stopping at the correct value.

Sign in to comment.

Tags

Asked:

Ben
on 1 Mar 2012

Community Treasure Hunt

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

Start Hunting!