Question about a Logistic Equation
4 views (last 30 days)
Show older comments
Hi,
I would like to start off by saying thank you for taking your time to help me with the problem. I am new to MATLAB so my script might like a little off.
%Population of Rabbits when N(0) = 200
t = .01:.01:1095;
p = 200;
%Principle Value of Rabbits / N(0)
a = .04
%R_0,prey; Rprey
Rprey = .04
%R_0,prey
s = .0005
%Death Rate Constant; y
h = .2
Nrab = p * exp(Rprey * t);
%Number of Rabbits
Res = (s * Nrab) / (1 + (s * h * Nrab))
%Number of Rabbits
I am trying to get Res but I am unable to. I think the problem is that I have 2 matrices in one; this is from combining Nrab in the same equation
0 Comments
Accepted Answer
John D'Errico
on 29 Nov 2016
Edited: John D'Errico
on 29 Nov 2016
You are correct that Nrab is the problem. You need to learn about the element-wise operations, {.* ./ .^} , all designed to handle your problem.
See that the only significant change I made was to add a single . to your line. I did add a semi-colon at the end too.
Res = (s * Nrab) ./ (1 + (s * h * Nrab));
So also learn about using ; at the end of your lines, to prevent dumping huge messes of crap to the command window. :)
2 Comments
John D'Errico
on 30 Nov 2016
Yes, that is a very good idea. Always verify that your code produces what you expect in the intermediate steps. Then you will not be surprised at the end. Too often, I see people who write a big bag of code, then only test it out at the very end. They are then surprised why it does not work. This is a virtue of modular code. Break it apart into functions. Then test each function separately, and put it all together. The nice thing is, if you are thoughtful about how you write those functions, some of those functions will be useful to you on other problems as they are. Then your next problem gets done in a far shorter time.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!