Question about a Logistic Equation

3 Ansichten (letzte 30 Tage)
Beau Ng
Beau Ng am 29 Nov. 2016
Kommentiert: John D'Errico am 30 Nov. 2016
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

Akzeptierte Antwort

John D'Errico
John D'Errico am 29 Nov. 2016
Bearbeitet: John D'Errico am 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 Kommentare
Beau Ng
Beau Ng am 30 Nov. 2016
Thank you! I do agree, I need to work on my dot operators. Thank you for the tips as well! I did however know about the ";". I just chose not to use it so I can double check my script periodically.
John D'Errico
John D'Errico am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by