Need help with homework
이전 댓글 표시
Asks the user to enter the initial concentration of microorganisms, the time at which they would like to calculate the microorganism concentration, and whether they would like to determine the concentration using a zero, first, or second order equation. Your program should work no matter whether they enter “Zero” or “zero” or “ZERO” or “zErO”, etc.
Computes the concentration of organisms using the appropriate equation:
Zero Order: N(t)= N0-21.8*t
First Order: N(t)=N0*e^(-0.125*t)
Second Order: 1/(N(t))=1/N0 +0.00349*t
Where the INPUTS are the following: Initial number of organisms per liter of water (N0) Time in minutes (t) Which equation they would like to use (zero order, first order, or second order)
And the OUTPUT is the following: Concentration of organisms N at time t
Displays an output message with the answer (concentration) and the appropriate units.
This is what I have so far
%Get user inputs
%Get the intital amount of organisms per liter of water
N0 = input('Enter the intial amount of organisms per liter of water: ');
%Get the input for time
T = input('Enter the time in minutes: ');
%Get the equation they want to use
order = input('Enter the order you would like to use: zero, first, or second:','s');
답변 (1개)
James Tursa
2017년 4월 11일
You could use a "switch" statement along with the "upper" function to handle case. E.g., an outline:
switch upper(order)
case 'ZERO'
% put code here for the zero case
case 'FIRST'
% put code here for the first case
:
etc
end
You should put in an "otherwise" case also to handle inputs that don't match any of your expected cases (i.e., maybe output an error message). See the following:
doc switch
doc upper
doc error
댓글 수: 3
Paul
2017년 4월 11일
James Tursa
2017년 4월 12일
편집: James Tursa
2017년 4월 12일
The upper(order) forces the string used for comparison to be UPPER CASE. So all of your strings in your case statements need to be UPPER CASE as well. I.e., your 'Second' needs to be 'SECOND'.
For the parse error, you can't have 1/N(T) on the left hand side of an assignment. It needs to be N(T) = something just like the others. So I think your professor intended for you to solve that equation for N(t) and then use that derived result for your equation.
Finally, even though the expression N(T) is used in the formulas, this syntax in MATLAB means the T is used as an index, which is not really what you want. So I would advise changing all of your
N(T) = etc.
to
Nt = etc.
Paul
2017년 4월 12일
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!