It was suggested to me to use matlab for a term project for my ODE class, I'd like to take a look at several bio models, mostly population growth. The problem is that I have no idea how matlab works.

For instance, I'd like to plot the first X terms of the solutions to an equation, such as $x_{n+1}=rx_n(1-x_n)$, $x_0=0.1$, where $r = 0.9, 1.5, 3, 4$ and then draw cobweb maps of each case.

Any pointers on how to code this or if there are any quick and easy sources on how to figure out how to do this, it would be greatly appreciated. I took one look at the program and couldn't figure anything out, and it being so early in the semester, I haven't had any experience with this program, I'm not sure if we'll even be using it, but I wanted to get a head start in figuring out the program.


This is the code to generate your $x_n$ estimates in a matrix x, the $n^{th}$ row corresponds to the value of $x_{n-1}$ for a different value of $r$, specified by the column index of $x$. I just plotted a normal plot so you can see the evolution.

X = 100 % first X terms
R = [0.9,1.5,3,4]; % these are the r values
x = zeros(X,length(R)); % initialise x to all zeros
x(1,:) = 0.1 % this is x0
k=1; % set a counter to 1
for r=R
for n = 1:X
    x(n+1,k) = r*x(n)*(1-x(n));% for each r and n update x
plot(x)% plot them all

You should be able to see this

enter image description here

For a cobweb plot, you need to generate a subplot for each $r$, i.e.

for k = 1:length(R)
for n = 1:(X-1)
    hold on
title(['Cobweb for r = ', num2str(R(k))])

Now, you should see this: enter image description here

This shows you that for all gives $r$ values, you're going to $x_n \rightarrow 0$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.