Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting orbits

Subject: Plotting orbits

From: Sanaa

Date: 30 Jun, 2012 18:06:09

Message: 1 of 4

Hi,
I am having a problem in plotting the orbit of the equation

x(t)=x_n + (t-n)*ru*x_n*(1-x_n), t/in [n,n+1), n-0,1,2,3,...
using the code

clear all; close all;
n = 50;
Nit = 10;
ru=1.5;
     x_previous = ones(1,n);
     for i = 1: Nit
      time = linspace(i,(i+1),n);
        x_next = x_previous+(time(i)-i)*ru*x_previous.*(1-x_previous);
        x_previous = x_next;
        plot(time,x_next,'linewidth',3)
     end
fsize=15;
xlabel('t','Fontsize',fsize)
ylabel('x','Fontsize',fsize)
%axis([1 Nit 0 10]);

but I don't get the expected graph! what went wrong please?
Thanks a lot for help.
Sanaa Moussa

Subject: Plotting orbits

From: Nasser M. Abbasi

Date: 30 Jun, 2012 18:17:52

Message: 2 of 4

On 6/30/2012 1:06 PM, Sanaa wrote:
> Hi,
> I am having a problem in plotting the orbit of the equation
>
> x(t)=x_n + (t-n)*ru*x_n*(1-x_n), t/in [n,n+1), n-0,1,2,3,...
> using the code
>
> clear all; close all;
> n = 50;
> Nit = 10;
> ru=1.5;
> x_previous = ones(1,n);
> for i = 1: Nit
> time = linspace(i,(i+1),n);
> x_next = x_previous+(time(i)-i)*ru*x_previous.*(1-x_previous);
> x_previous = x_next;
> plot(time,x_next,'linewidth',3)
> end
> fsize=15;
> xlabel('t','Fontsize',fsize)
> ylabel('x','Fontsize',fsize)
> %axis([1 Nit 0 10]);
>
> but I don't get the expected graph! what went wrong please?
> Thanks a lot for help.
> Sanaa Moussa
>

Your (time(i)-i) always zero. For all loops. Need
to fix that part.

Also you might want to use hold on in the loop if you want to
see the plot change as the loop runs. (may be add a small pause
also).

I could not understand the algorithm, but this is what I noticed
(your x_previous does not change).

ps. use a debugger and step in the code. You'll see what
the problem is. Simplify the code.

--Nasser

Subject: Plotting orbits

From: Sanaa

Date: 30 Jun, 2012 19:23:10

Message: 3 of 4

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jsnfsf$74e$1@speranza.aioe.org>...
> On 6/30/2012 1:06 PM, Sanaa wrote:
> > Hi,
> > I am having a problem in plotting the orbit of the equation
> >
> > x(t)=x_n + (t-n)*ru*x_n*(1-x_n), t/in [n,n+1), n-0,1,2,3,...
> > using the code
> >
> > clear all; close all;
> > n = 50;
> > Nit = 10;
> > ru=1.5;
> > x_previous = ones(1,n);
> > for i = 1: Nit
> > time = linspace(i,(i+1),n);
> > x_next = x_previous+(time(i)-i)*ru*x_previous.*(1-x_previous);
> > x_previous = x_next;
> > plot(time,x_next,'linewidth',3)
> > end
> > fsize=15;
> > xlabel('t','Fontsize',fsize)
> > ylabel('x','Fontsize',fsize)
> > %axis([1 Nit 0 10]);
> >
> > but I don't get the expected graph! what went wrong please?
> > Thanks a lot for help.
> > Sanaa Moussa
> >
>
> Your (time(i)-i) always zero. For all loops. Need
> to fix that part.
>

Yes, I have tried to fix it but still having the same problem because in the map the term (t-n) appears explicitly. So, do u have any idea to fix this problem?
Thanks a lot in advance.

Subject: Plotting orbits

From: Nasser M. Abbasi

Date: 30 Jun, 2012 20:29:52

Message: 4 of 4

On 6/30/2012 2:23 PM, Sanaa wrote:

> Yes, I have tried to fix it but still having the same
>problem because in the map the term (t-n) appears explicitly.
>So, do u have any idea to fix this problem?
> Thanks a lot in advance.
>

I can't read your equation, so I don't understand what you
are trying to do. You wrote

>I am having a problem in plotting the orbit of the equation
>x(t)=x_n + (t-n)*ru*x_n*(1-x_n), t/in [n,n+1), n-0,1,2,3,...

I am not sure what you mean by 'orbit'.

Also, you have x as function of t on one side, and x as
function of n on the other end.

i.e. you wrote x(t)=x(n) something. So, I do not know
what this mean.

It will help if you post a link to the actual mathematical
problem itself, so one can see it. If it is from a book,
post the problem as given in the text book (scan it,
post an image). If it is from a web page, give a link there.

Other than that, hopefully someone will understand it
better than I could.

good luck,
--Nasser

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us