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:
out of memory error

Subject: out of memory error

From: Sanaa

Date: 25 Apr, 2012 23:27:26

Message: 1 of 7


Hi,
I always get the error: out of memory even if i try to reduce the size of my parameters!
clear
itermax=100;
finalits=30;finits=itermax-(finalits-1);
for ru=0:0.005:2;
for a=0.01:0.005:1;
    x=zeros(1,itermax);
    x0=0.2;x1= 0.25;
    x(1)=x0;x(2)=x1;
    for i=2:itermax
        x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
    end
    plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)
    hold on
end
end
fsize=15;
set(gca,'XTick',0.1:0.5:4,'FontSize',fsize)
set(gca,'YTick',0:0.2:1)
xlabel('{a}','FontSize',fsize)
ylabel('x','FontSize',fsize)
title('ru= 3.5')
hold off

Any help will be appreciated.

Subject: out of memory error

From: edward kabanyas

Date: 26 Apr, 2012 04:03:23

Message: 2 of 7

Please check the following link: http://www.mathworks.com/support/tech-notes/1100/1107.html, it is very useful to overcome such out of memory problem.

Edward

"Sanaa" wrote in message <jna18u$6al$1@newscl01ah.mathworks.com>...
>
> Hi,
> I always get the error: out of memory even if i try to reduce the size of my parameters!
> clear
> itermax=100;
> finalits=30;finits=itermax-(finalits-1);
> for ru=0:0.005:2;
> for a=0.01:0.005:1;
> x=zeros(1,itermax);
> x0=0.2;x1= 0.25;
> x(1)=x0;x(2)=x1;
> for i=2:itermax
> x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
> end
> plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)
> hold on
> end
> end
> fsize=15;
> set(gca,'XTick',0.1:0.5:4,'FontSize',fsize)
> set(gca,'YTick',0:0.2:1)
> xlabel('{a}','FontSize',fsize)
> ylabel('x','FontSize',fsize)
> title('ru= 3.5')
> hold off
>
> Any help will be appreciated.

Subject: out of memory error

From: Steven_Lord

Date: 26 Apr, 2012 13:47:26

Message: 3 of 7



"Sanaa " <findingsanaa@yahoo.com> wrote in message
news:jna18u$6al$1@newscl01ah.mathworks.com...
>
> Hi,
> I always get the error: out of memory even if i try to reduce the size of
> my parameters!
> clear
> itermax=100;
> finalits=30;finits=itermax-(finalits-1);
> for ru=0:0.005:2;
> for a=0.01:0.005:1;
> x=zeros(1,itermax);
> x0=0.2;x1= 0.25;
> x(1)=x0;x(2)=x1;
> for i=2:itermax
> x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
> end
>
> plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)

You're plotting almost 80,000 lines due to the double nested FOR loops over
ru and a. Your monitor doesn't have enough pixels to show all the points on
all those lines, but each line requires two 71-by-71 matrices and a
71-element vector. Now 71-by-71 matrices may sound small, and they generally
are, but a large number of small matrices still chew up memory pretty
quickly. There's an old saying that captures what you're experiencing:
"death by a thousand paper cuts."

You can reduce the amount of memory you're using a _little_ by calling ONES
with two inputs to create a _vector_ rather than a _matrix_:

a*ones(1, finalits)

or by calling REPMAT:

repmat(a, 1, finalits)

But a bigger win would be to find a way to avoid creating tens of thousands
of lines.

*snip*

> title('ru= 3.5')

This doesn't look correct, given the limits on your first FOR loop.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: out of memory error

From: Sanaa

Date: 27 Apr, 2012 19:38:07

Message: 4 of 7

Thanks a lot for your respond. I tried the command you wrote and I also tried to fix my code. First I got the error: Warning: axis limits too large
I fixed the error but I don't get a 3-d picture! I only get dots...

clear
itermax=300;
finalits=30;finits=itermax-(finalits-1);
for ru=1:0.05:3;
for a=0.01:0.05:1;
    x=zeros(1,itermax);
    x0=0.2;x1= 0.4;
    x(1)=x0;x(2)=x1;
    for i=2:itermax
        x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
    end
    plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)
    hold on
end
end
fsize=15;
set(gca,'XTick',1:0.5:2,'FontSize',fsize)
set(gca,'YTick',0:0.2:1)
set(gca,'ZTick',0:0.2:1)
xlabel('ru','FontSize',fsize)
ylabel('a','FontSize',fsize)
zlabel('x','FontSize',fsize)
hold off
Any idea please?
Thanks a lot and sorry for bothering you.

Subject: out of memory error

From: Steven_Lord

Date: 27 Apr, 2012 20:35:09

Message: 5 of 7



"Sanaa " <findingsanaa@yahoo.com> wrote in message
news:jnesiu$81o$1@newscl01ah.mathworks.com...
> Thanks a lot for your respond. I tried the command you wrote and I also
> tried to fix my code. First I got the error: Warning: axis limits too
> large
> I fixed the error but I don't get a 3-d picture! I only get dots...
>
> clear
> itermax=300;
> finalits=30;finits=itermax-(finalits-1);
> for ru=1:0.05:3;
> for a=0.01:0.05:1;

Now you're only running the body of this nested loop 820 times.

> x=zeros(1,itermax);
> x0=0.2;x1= 0.4;
> x(1)=x0;x(2)=x1;
> for i=2:itermax
> x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
> end
>
> plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)

You're now creating 271-by-271 matrices, though. If none of the points
overlapped, you'd still be trying to plot about 60 million points.

[BTW, the reason you're not seeing lines drawn is because you changed '-' to
'.' on this line. Doing this doesn't _really_ have a significant impact on
how much you're plotting; sure, it means PLOT won't need to display the
points between your individual (a, ru) pairs, but you're still plotting the
pairs themselves.]

Take a step back from the code. What EXACTLY are you trying to do here? When
you explain, try to do so without using ANY code or ANY numbers. Finish this
sentence: "I want to use this plot to ..."

Perhaps knowing what you're trying to do with this graphic will help figure
out the right approach to display just what you need without plotting lots
of extraneous information.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: out of memory error

From: Sanaa

Date: 27 Apr, 2012 20:54:12

Message: 6 of 7


Thanks once again. I want to use this plot to create a 3-d graph for the bifurcation diagram of the map '' some forms of logistic map''
 x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
Actually, I was able to create the bifurcation for the above map when varying ru only and it was fine. Now I want to see what will happen when I vary both ru and a together. My professor told me that I should get a nice bifurcation diagram!
So please I need your help and I really appreciate it.
Thanks a lot in advance.

Subject: out of memory error

From: Roger Stafford

Date: 27 Apr, 2012 21:19:07

Message: 7 of 7

"Sanaa" wrote in message <jnesiu$81o$1@newscl01ah.mathworks.com>...
> Thanks a lot for your respond. I tried the command you wrote and I also tried to fix my code. First I got the error: Warning: axis limits too large
> I fixed the error but I don't get a 3-d picture! I only get dots...
>
> clear
> itermax=300;
> finalits=30;finits=itermax-(finalits-1);
> for ru=1:0.05:3;
> for a=0.01:0.05:1;
> x=zeros(1,itermax);
> x0=0.2;x1= 0.4;
> x(1)=x0;x(2)=x1;
> for i=2:itermax
> x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
> end
> plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)
> hold on
> end
> end
> fsize=15;
> set(gca,'XTick',1:0.5:2,'FontSize',fsize)
> set(gca,'YTick',0:0.2:1)
> set(gca,'ZTick',0:0.2:1)
> xlabel('ru','FontSize',fsize)
> ylabel('a','FontSize',fsize)
> zlabel('x','FontSize',fsize)
> hold off
> Any idea please?
> Thanks a lot and sorry for bothering you.
- - - - - - - - - - -
  Based on your previous threads, Sanaa, you are apparently trying to get bifurcation diagrams for another mapping, this one with two parameters, a and ru. You are trying to illustrate this using 'plot3' to create a three dimensional picture of this bifurcation in which both a and ru are varied, but in my opinion this is a mistake. Even if you had no troubles with memory, all you would see is a bewildering mass of points which would be extremely difficult to interpret.

  My suggestion is to set one of the parameters, perhaps a, to a constant and make a 2D diagram as ru varies. Also be sure to use dots for your plot points, not lines. Then repeat this for a series of diagrams as you vary a through some range of values. This is the only way you are ever going to produce plot images that are capable of being interpreted properly.

Roger Stafford

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