Reducing memory storage through matrix computation

2 ビュー (過去 30 日間)
mona
mona 2014 年 3 月 2 日
編集済み: Matt J 2014 年 3 月 2 日
I need to compute a matrix and the following code does exactly what I want. However, the operator creates O(n^2) storage but I want it to store the matrix linearly i.e., create O(n) storage (less storage space). I think this could be done using permutations but how could you modify the code in those terms:
ele=100;
x=(0:ele)'/2;
nlength= length(x);
p=ones(nlength,1);
for i=1:nlength-1
p=horzcat(p,x.^i);
end
g=p*x;
  2 件のコメント
Matt J
Matt J 2014 年 3 月 2 日
編集済み: Matt J 2014 年 3 月 2 日
FYI, you've largely reinvented the VANDER command.
mona
mona 2014 年 3 月 2 日
and I still trying to implement it in a different way so that it doesn't take much space. Any help?

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2014 年 3 月 2 日
編集済み: Matt J 2014 年 3 月 2 日
If you only intend to operate on vectors, by matrix-vector multiplication, you could use MatrixObj as below (or just use POLYVAL directly),
p=MatrixObj;
p.Ops.mtimes=@(~,y) polyval(flipud(y), x);
p.Ops.size=[nlength,nlength];
However, I don't see when it would ever be practical to use such a matrix for very large n. Expressions like x.^n are very numerically sensitive when n is large.
  2 件のコメント
mona
mona 2014 年 3 月 2 日
編集済み: mona 2014 年 3 月 2 日
Thanks Matt but I cannot seem to use polyval directly since y is coming from MatrixObj. I really don't prefer to use another function. Could this be done just by using the built-in functions within Matlab?
Matt J
Matt J 2014 年 3 月 2 日
編集済み: Matt J 2014 年 3 月 2 日
I didn't understand your comment. The code you've posted is equivalent to the single line,
g=polyval(flipud(x),x);
So, if you want to use built-in functions only, this would be the way.
The advantage of MatrixObj is that it allows you to do the same thing with the same matrix multiplication syntax as in your original code,
p=MatrixObj;
p.Ops.mtimes=@(~,y) polyval(flipud(y), x);
p.Ops.size=[nlength,nlength];
g=p*x;
which sounded like what you were looking for.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by