Question about a Logistic Equation

조회 수: 4 (최근 30일)
Beau Ng
Beau Ng 2016년 11월 29일
댓글: John D'Errico 2016년 11월 30일
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

채택된 답변

John D'Errico
John D'Errico 2016년 11월 29일
편집: John D'Errico 2016년 11월 29일
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
Beau Ng
Beau Ng 2016년 11월 30일
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 2016년 11월 30일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by