zeros(n)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

zeros(n)

Ether Jones
Is this a known bug?

When I use this:
A=zeros(20000);
... I get a memory error.

But when I use this:
for i=1:20000
A(i)=0;
endfor;
... it works fine.


See log below:


GNU Octave, version 3.6.4
Copyright (C) 2013 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type `warranty'.

Octave was configured for "i686-pc-mingw32".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.

For information about changes from previous versions, type `news'.

 - Use `pkg list' to see a list of installed packages.
 - MSYS shell available (K:\OctaveVS\msys).
 - Graphics backend: gnuplot.

octave-3.6.4.exe:1> A=zeros(20000);
error: memory exhausted or requested size too large for range of Octave's index
type -- trying to return to prompt

octave-3.6.4.exe:1> for i=1:20000
> A(i)=0;
> endfor;

octave-3.6.4.exe:2>

Reply | Threaded
Open this post in threaded view
|

Re: zeros(n)

James Sherman
From the help file for zeros:

If invoked with a single scalar integer argument, return a square NxN matrix.

So, if you call the function as:
zeros(20000)
You're requesting a matrix of size 20000x20000

In your for loop, you're initializing a 1x20000 array.  If you want
zeros to do what your for loop is doing, you should call it as:
zeros(1, 20000)

Hope this helps.

James Sherman

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: zeros(n)

Doug Stewart-4
In reply to this post by Ether Jones


On Tue, Sep 16, 2014 at 9:52 PM, Ether Jones <[hidden email]> wrote:
Is this a known bug?

When I use this:
A=zeros(20000);
... I get a memory error.

But when I use this:
for i=1:20000
A(i)=0;
endfor;
... it works fine.


See log below:


GNU Octave, version 3.6.4
Copyright (C) 2013 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type `warranty'.

Octave was configured for "i686-pc-mingw32".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.

For information about changes from previous versions, type `news'.

 - Use `pkg list' to see a list of installed packages.
 - MSYS shell available (K:\OctaveVS\msys).
 - Graphics backend: gnuplot.

octave-3.6.4.exe:1> A=zeros(20000);
error: memory exhausted or requested size too large for range of Octave's
index
type -- trying to return to prompt

octave-3.6.4.exe:1> for i=1:20000
> A(i)=0;
> endfor;

octave-3.6.4.exe:2>





--
View this message in context: http://octave.1599824.n4.nabble.com/zeros-n-tp4666552.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



zeros(4)
ans =

   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0

>> zeros(4,1)
ans =

   0
   0
   0
   0

--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: zeros(n)

Ether Jones
In reply to this post by James Sherman

Thanks James and Doug.

In my haste I did not read the docs carefully.

It works great now.

Reply | Threaded
Open this post in threaded view
|

Re: zeros(n)

octaveUser2M
In reply to this post by Ether Jones
Suggest try:

a = zeros(2);

for i=1:2
b(i) = 0;
end

a
b

The difference between a and b will make it clear; no bug. Consider the size of zeros(N). Your first A would have 400e6 elements, if created.