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:
fractional loop

Subject: fractional loop

From: Sanaa

Date: 20 Mar, 2012 18:49:12

Message: 1 of 5

Greetings,
I am having a problem with the fraction iteration in Matlab. Actually, I have this code to plot the trajectory of the following map

x_n = -0.5 x_(n-1)+1, x0 = 0, n = 1,2,3,......
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
clear;
x0=0;
x(1) = x0;
itermax = 50;
for i = 1:itermax-1
    %x(1)= x0;
    x(i+1) = - 0.5*x(i)+1;
end
hold off;
plot(x,'r*');
hold on;
plot(x,'y');
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The problem????

Now I want to do the same for this problem
x_n = -0.5 x_(n-1/2) + 1, x0 = 0
n = 1/2, 1, 3/2, 2, ...

n here is a fraction!!!!

Any help will be appreciated.

Subject: fractional loop

From: Roger Stafford

Date: 20 Mar, 2012 20:55:16

Message: 2 of 5

"Sanaa" wrote in message <jkajf8$h28$1@newscl01ah.mathworks.com>...
> Greetings,
> I am having a problem with the fraction iteration in Matlab. Actually, I have this code to plot the trajectory of the following map
>
> x_n = -0.5 x_(n-1)+1, x0 = 0, n = 1,2,3,......
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> clear;
> x0=0;
> x(1) = x0;
> itermax = 50;
> for i = 1:itermax-1
> %x(1)= x0;
> x(i+1) = - 0.5*x(i)+1;
> end
> hold off;
> plot(x,'r*');
> hold on;
> plot(x,'y');
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> The problem????
>
> Now I want to do the same for this problem
> x_n = -0.5 x_(n-1/2) + 1, x0 = 0
> n = 1/2, 1, 3/2, 2, ...
>
> n here is a fraction!!!!
>
> Any help will be appreciated.
- - - - - - - - -
  This latter definition of x will give you the same sequence of values as the first one. Just define

 y(m) = x((m-1)/2) for m = 1, 2, 3, ...

Then y(1) = x(0) = 0 and y(m+1) = x(m/2) = -.5*x(m/2-1/2)+1 = -.5*y(m)+1 . This shows that y, the second x, and the previous x, all have the same sequence of values.

  Why is this a problem for you? As you must be aware, matlab will only accept arrays that are indexed by positive integers, so a revised definition like this from x to y is necessary to represent such a sequence as an array in matlab.

Roger Stafford

Subject: fractional loop

From: Sanaa

Date: 21 Mar, 2012 18:49:32

Message: 3 of 5

Dear Sir, Thanks a lot for your response. But I am a bit confused. What I understood from your answer that nothing new will be shown in the later plot. As you mentioned it's a matter of substitution after which I get the same previous values! I plotted the later code(which you explained) and I got the same as the first! What I was asked form my prof. that I should get a different one!
Any explanation?
Thank you very much in advance.

Subject: fractional loop

From: Roger Stafford

Date: 21 Mar, 2012 20:40:27

Message: 4 of 5

"Sanaa" wrote in message <jkd7rs$hjc$1@newscl01ah.mathworks.com>...
> Dear Sir, Thanks a lot for your response. But I am a bit confused. What I understood from your answer that nothing new will be shown in the later plot. As you mentioned it's a matter of substitution after which I get the same previous values! I plotted the later code(which you explained) and I got the same as the first! What I was asked form my prof. that I should get a different one!
> Any explanation?
> Thank you very much in advance.
- - - - - - - - -
  I didn't say the plots would be the same. It depends on what you are plotting against what. In the second kind of x variable if you plot x against n the plot would be different, but only because the n is different. The x values would all be the same as before, namely

 1/2, 3/4, 5/8, 11/16, etc.

The n values are different: 1/2, 2/2, 3/2, 4/2, 5/2, 6/2, ...
instead of 1, 2, 3, 4, 5, 6

Roger Stafford

Subject: fractional loop

From: someone

Date: 21 Mar, 2012 21:18:34

Message: 5 of 5

"Sanaa" wrote in message <jkd7rs$hjc$1@newscl01ah.mathworks.com>...
> Dear Sir, Thanks a lot for your response. But I am a bit confused. What I understood from your answer that nothing new will be shown in the later plot. As you mentioned it's a matter of substitution after which I get the same previous values! I plotted the later code(which you explained) and I got the same as the first! What I was asked form my prof. that I should get a different one!
> Any explanation?

Well, you are both right. Think of it this way:

Problem 1
x1(0) = 0 and
x1(n) = 1 - x1(n-1)/2, for n = 1, 2, 3, ...

Now since MATLAB vectors start with element 1,
we can rewrite Problem 1 as:
y(1) = x1(0) = 0 and
y(m) = x1(m-1) = 1 - x1(m-2)/2 = 1 - y(m-1)/2, for m = 2,3,4......

So,
y(1) = x1(0) = 0
y(2) = x1(1) = 1 - x1(0)/2 = 1 - y(1)/2 = 1
y(3) = x1(2) = 1 - x1(1)/2 = 1 - y(2)/2 = 1/2
y(4) = x1(3) = 1 - x1(2)/2 = 1 - y(3)/2 = 3/4 ...

Problem 2
x2(0) = 0 and
x2(n) = 1 - x2(n-1/2)/2, for n = 1/2, 1, 3/2, 2, ...

Now since MATLAB vectors start with element 1
and must be integers,
we can rewrite Problem 2 as:
z(1) = x2(0) = 0 and
z(m) = x2(m/2 - 1/2) = 1 - x2(m/2 - 1/2)/2 = 1 - z(m-1)/2, for m = 2,3,4......

So,
z(1) = x2(0) = 0
z(2) = x2(1/2) = 1 - x2(0)/2 = 1 - z(1)/2 = 1
z(3) = x2(1) = 1 - x2(1/2)/2 = 1 - z(2)/2 = 1/2
z(4) = x2(3/2) = 1 - x2(1)/2 = 1 - z(3)/2 = 3/4 ...

Now compare Problem 1 & 2
y = z but x1~=x2

x2 is simply a "time" compressed version of x1
y and z (and x2) are simply rescaled (and shifted, if you wish) versions of x1

Does that explain it?

> Thank you very much in advance.

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