In an assignment A(I) = B, the number of elements in B and I must be the same.
Show older comments
I am working on this problem x(i+1)=rx(1-x) where the question says plot x as a function of r for 1<r<4.
Here is what I did:
r=1:0.01:4;
x=[];
x=0.35;
N=100;
for i=1:N;
x(i+1)=r*x(i)*(1-x(i));
end
but then this error message comes up. What's wrong with this code? How can I improve it?
Accepted Answer
More Answers (1)
Walter Roberson
on 19 Mar 2014
0 votes
x(i+1) can hold one element.
x(i) and (1-x(i)) are each one element, so x(i)*(1-x(i)) is one element.
r is 1:0.01:4 which is multiple elements. multiple elements multiplied by one element gives multiple elements. So the right hand side of the assignment has multiple elements and you are trying to save that into a single element.
Hint: you can make x into a two dimensional array and operate on rows at a time.
Categories
Find more on Whos 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!