Path: news.mathworks.com!not-for-mail
From: "Steven_Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: out of memory error
Date: Thu, 26 Apr 2012 09:47:26 -0400
Organization: MathWorks
Lines: 54
Message-ID: <jnbjle$khr$1@newscl01ah.mathworks.com>
References: <jna18u$6al$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: ah-slord.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="utf-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1335448046 21051 172.31.44.77 (26 Apr 2012 13:47:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Apr 2012 13:47:26 +0000 (UTC)
In-Reply-To: <jna18u$6al$1@newscl01ah.mathworks.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:766003



"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