我们如何在matlab中处理大型矩阵(大于10000x10000)

发布于 2024-11-09 20:09:46 字数 2680 浏览 0 评论 0原文

在我的程序中,我面临一些大于 10000x10000 的矩阵。 我无法转置或反转它们,如何克服这个问题?

??? Error using ==> ctranspose
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname1 at 70
    B = cell2mat(C(:,:,s))'; 
Out of memory. Type HELP MEMORY for your options.
Example 1: Run the MEMORY command on a 32-bit Windows system:


    >> memory
    Maximum possible array:             677 MB (7.101e+008 bytes) *
    Memory available for all arrays:   1602 MB (1.680e+009 bytes) **
    Memory used by MATLAB:              327 MB (3.425e+008 bytes)
    Physical Memory (RAM):             3327 MB (3.489e+009 bytes)

    *  Limited by contiguous virtual address space available.
    ** Limited by virtual address space available.

Example 2: Run the MEMORY command on a 64-bit Windows system:

    >> memory
    Maximum possible array:               4577 MB (4.800e+009 bytes) *
    Memory available for all arrays:      4577 MB (4.800e+009 bytes) *
    Memory used by MATLAB:                 330 MB (3.458e+008 bytes)
    Physical Memory (RAM):                3503 MB (3.674e+009 bytes)

=================================================== ============================

 memory
% Maximum possible array:            1603 MB (1.681e+009 bytes) *
% Memory available for all arrays:   2237 MB (2.346e+009 bytes) **
% Memory used by MATLAB:              469 MB (4.917e+008 bytes)
% Physical Memory (RAM):             3002 MB (3.148e+009 bytes)


I have used sparse for C. 

B = cell2mat(C);
clear C       %#  to reduce the allocated RAM
P=B\b;

Name         Size                  Bytes  Class     Attributes     

  B         5697x5697            584165092  double    sparse, complex
  C         1899x1899            858213576  cell                     
  b         5697x1                   91152  double    complex        

==============================================================================
??? Error using ==> mldivide
Out of memory. Type HELP MEMORY for your options.

Error in ==> programname at 82
    P=B\b; 

==============================================================================

编辑:27.05.11

Name         Size                  Bytes  Class     Attributes

  C          997x997             131209188  cell   
  B            2991x2991             71568648  single    complex        
  Bdp          2991x2991            143137296  double    complex        
  Bsparse      2991x2991            156948988  double    sparse, complex

  Bdp=double(B);
  Bsparse=sparse(Bdp);

我使用单精度,女巫给出了与双精度相同的精度

更好,我说得对吗?

In my program I am faced with some matrices that are larger than 10000x10000.
I cannot transpose or inverse them, how can this problem be overcome?

??? Error using ==> ctranspose
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname1 at 70
    B = cell2mat(C(:,:,s))'; 
Out of memory. Type HELP MEMORY for your options.
Example 1: Run the MEMORY command on a 32-bit Windows system:


    >> memory
    Maximum possible array:             677 MB (7.101e+008 bytes) *
    Memory available for all arrays:   1602 MB (1.680e+009 bytes) **
    Memory used by MATLAB:              327 MB (3.425e+008 bytes)
    Physical Memory (RAM):             3327 MB (3.489e+009 bytes)

    *  Limited by contiguous virtual address space available.
    ** Limited by virtual address space available.

Example 2: Run the MEMORY command on a 64-bit Windows system:

    >> memory
    Maximum possible array:               4577 MB (4.800e+009 bytes) *
    Memory available for all arrays:      4577 MB (4.800e+009 bytes) *
    Memory used by MATLAB:                 330 MB (3.458e+008 bytes)
    Physical Memory (RAM):                3503 MB (3.674e+009 bytes)

==============================================================================

 memory
% Maximum possible array:            1603 MB (1.681e+009 bytes) *
% Memory available for all arrays:   2237 MB (2.346e+009 bytes) **
% Memory used by MATLAB:              469 MB (4.917e+008 bytes)
% Physical Memory (RAM):             3002 MB (3.148e+009 bytes)


I have used sparse for C. 

B = cell2mat(C);
clear C       %#  to reduce the allocated RAM
P=B\b;

Name         Size                  Bytes  Class     Attributes     

  B         5697x5697            584165092  double    sparse, complex
  C         1899x1899            858213576  cell                     
  b         5697x1                   91152  double    complex        

==============================================================================
??? Error using ==> mldivide
Out of memory. Type HELP MEMORY for your options.

Error in ==> programname at 82
    P=B\b; 

==============================================================================

Edit: 27.05.11

Name         Size                  Bytes  Class     Attributes

  C          997x997             131209188  cell   
  B            2991x2991             71568648  single    complex        
  Bdp          2991x2991            143137296  double    complex        
  Bsparse      2991x2991            156948988  double    sparse, complex

  Bdp=double(B);
  Bsparse=sparse(Bdp);

I used single precision, witch gave the same accuracy as in double precision

It's better, Am I right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热情消退 2024-11-16 20:09:46

一些建议:

  1. 如果可能,正如@yoda建议的那样,使用稀疏矩阵
  2. 你真的需要逆矩阵吗?如果您要求解线性系统 (Ax=b),则应使用 MATLAB 的 反斜杠运算符
  3. 如果您确实需要巨大的密集矩阵,您可以使用 分布式数组MATLAB 分布式计算服务器

A few suggestions:

  1. If possible, as @yoda suggested, use sparse matrices
  2. Do you really need the inverse? If you're solving a linear system (Ax=b), you should use MATLAB's backslash operator.
  3. If you really need huge dense matrices, you can harness the memory of several machines using distributed arrays and MATLAB distributed computing server.
最终幸福 2024-11-16 20:09:46

当您拥有的每个矩阵本身就有 600 MB 时,3GB 并不算多。如果您无法更改算法,则需要在 64 位操作系统上运行 64 位 matlab,并具有更多 RAM。这是获得大量内存的唯一方法。请注意,对于 3 GB,Matlab 只有 2.2 GB,最大的块是 1.5 GB - 这只是您的矩阵的 2 个。

3GB isn't alot when each matrix you have is 600 MB all by it's self. If you can't make the algorithmic changes, you need 64-bit matlab on a 64-bit OS, with alot more RAM. It's the only way to get alot of memory. Notice that with 3 GB, Matlab only has 2.2 GB, and the largest chunk is 1.5 GB - that's only 2 of your matricies.

十年九夏 2024-11-16 20:09:46

Matlab 有一种简单的方法来处理像 1000000*1000000 这样的巨大订单矩阵。
这些矩阵通常是稀疏矩阵,不需要为零值的矩阵元素分配 RAM 内存。
所以你应该使用这个命令:

A=sparse(1000000,1000000); “定义一个 1000000 x 1000000 的零矩阵。”

然后您可以通过“spdiags”等命令设置对角线非零元素。
请参阅此链接: http://www.mathworks.nl/help/matlab/ref /spdiags.html

请注意,您不能使用“inv”命令来反转矩阵 A,因为“inv”创建了一个普通矩阵并使用了大量 RAM 空间。(可能会出现“内存不足”错误)

到求解 A*X=B 等方程,可以使用 X=A\B。

Matlab has an easy way to handling huge matrices of orders like 1000000*1000000.
These matrices are usually sparse matrices and it's not necessary to allocate RAM memory for matrix elements of zero value.
So you should just use this command:

A=sparse(1000000,1000000); "Defining a 1000000 by 1000000 matrix of zeroes."

Then you can set the diagonal nonzero elements by commands like "spdiags".
See this Link : http://www.mathworks.nl/help/matlab/ref/spdiags.html

Note that you can not use "inv" command to invert matrix A, because "inv" made a normal matrix and uses a lot of space of the RAM.(probably with "out of memory" error)

To solve an equation like A*X=B, you can use X=A\B.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文