What's wrong with this code?

I am getting this error msg. Please find me the mistakes here.
In an assignment A(I) = B, the number of elements in B and I must be the same.
r=[2.0 3.1 3.5 3.65 3.84 3.95];
x=[];
x(1)=0.35;
f=@(x) r*x*(1-x);
N=40;
for t=1:N-1;
x(t+1)=f(x(t));
end
hold on
plot(x,'r-')

Antworten (2)

Joseph Cheng
Joseph Cheng am 21 Mär. 2014

1 Stimme

yes thats because you are including information that is not here and in your other posting that was flagged. but looks like you have it so we're all set?

3 Kommentare

Sam
Sam am 21 Mär. 2014
Bearbeitet: Sam am 21 Mär. 2014
Sorry I can't use that. My friend just sent me to see what he did. So, if I use that, I will be cheating. That's why I am exhausting myself here. But, thanks for all your help. Atleast, you're not making any rude comments.
Joseph Cheng
Joseph Cheng am 21 Mär. 2014
only rude comment from me would be that posting on a forum for assignment questions involving things besides what type of functions to use, function errors, random matlab issues, and approaches to handling data is cheating. The Teaching Assistant or office hours should be where assignment related questions be asked.
Star Strider
Star Strider am 21 Mär. 2014
And it’s not cheating to have MATLAB Answers do your homework for you?
Joseph Cheng
Joseph Cheng am 21 Mär. 2014
Bearbeitet: Joseph Cheng am 21 Mär. 2014

0 Stimmen

Were you attempting to do this?
r=[2.0 3.1 3.5 3.65 3.84 3.95];
x=[];
x(1,:)=0.35*ones(size(r));
f=@(x) r*x*(1-x);
N=40;
for t=1:N-1;
x(t+1,:)=f(x(t));
end
hold on
plot(x)
legend('r = 2.0','r = 3.1', 'r = 3.65')
Where the first value of x is 0.35? or you can re-write it such that the function
f=@(x,r) r*x*(1-x);
such that you write a for loop to cycle in the r you need.

8 Kommentare

Sam
Sam am 21 Mär. 2014
Bearbeitet: Sam am 21 Mär. 2014
I am not sure what exactly the meaning of this: x(1,:)=0.35*ones(size®) and x=0.35 is the only value or initial value in this case.
Joseph Cheng
Joseph Cheng am 21 Mär. 2014
x(1,:)=0.35 *ones(size®) initializes x for each instance of r
Star Strider
Star Strider am 21 Mär. 2014
Thanks for finding that, Joseph.
A parallel thread and I’m outahere!
Sam
Sam am 21 Mär. 2014
No this is completely different. The question here asks for: Plot x as a function of time, and f(x) as a function of x, for r =2.0, 3.1, 3.5, 3.65, 3.84, 3.95.
Joseph Cheng
Joseph Cheng am 21 Mär. 2014
Bearbeitet: Joseph Cheng am 21 Mär. 2014
and for the information given so far i've shown you how to get each f(x) as a function of x for each of the r's. and we've explained the error.
Sam
Sam am 21 Mär. 2014
Yes, but the graph I am getting for each individual r is completely different from when I use all the r values together if that make any sense to you.
Joseph Cheng
Joseph Cheng am 21 Mär. 2014
no it doesn't make sense. how do they look different? shape? amplitude?

Diese Frage ist geschlossen.

Tags

Noch keine Tags eingegeben.

Gefragt:

Sam
am 21 Mär. 2014

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by