Question about a Logistic Equation
4 次查看(过去 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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!