Using exponential functions to find half capacity

3 次查看(过去 30 天)
How long does it take for the population to reach one half of the carrying capacity? Compare with theoretical results.
This is what I have so far

采纳的回答

Walter Roberson
Walter Roberson 2021-2-25
you need to find the first place that P is 150 or higher. Once you have the location then use it to index the time

更多回答(1 个)

Johnny B
Johnny B 2021-2-25
First of all, "how can I answer this question" is a really bad name for the topic.
The syntax 150(t) doesn't make any sense; the value in parentheses is the index of the variable whose name precedes it, so you're asking for the t-th element of 150.
Your code is creating a vector of values of t from 0 to 20 and then calculating a P value for each value of t. So what you need is to find the P value closest to 150 and return the t value that corresponds to it. There's very little chance that you have a value of P in your array that is exactly 150, so testing for P==150 isn't going to work. One way to find the closest value is to take advantage of the second, optional, output of the min function:
[ ~, ix ] = min(abs(P - 150));
t_half = t(ix)
Then minimum of the absolute value of P-150 will, of course, occur where P is closest to 150. The min function will return this minimum value and optionally the index where it occurs. The tilde (~) tells MATLAB that we don't care about the actual minimum, just the index. Since t and P are the same size and have corresponding values (e.g., the 3rd value of P corresponds to the 3rd value of t), you just need t(ix).
Another approach is to use the interp1 function to find the value of t when P is 150. Although the function is written so that P is a function of t, you can think of them the other way around -- pretend that t is a function of P -- and interpolate:
t_half = interp1(P, t, 150)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by