Which is faster, a row vector or a column vector? Can anyone answer me please?

77 ビュー (過去 30 日間)
Avan Al-Saffar
Avan Al-Saffar 2015 年 5 月 13 日
編集済み: Stephen23 2015 年 5 月 15 日
I am trying to do some integration so I am defining the output as a matrix, my question is which definition will give me faster results to define my matrix :
A = zeros(1,n) or A = zeros(n,1)?
Regards

採用された回答

Stephen23
Stephen23 2015 年 5 月 13 日
編集済み: Stephen23 2015 年 5 月 15 日
Perhaps the column, as MATLAB uses column-major memory storage of arrays. But really it is unlikely to make a big difference.
Just try it and use timeit or tic and toc to compare the times.
Another very fast way to define a matrix of zeros is this:
A(n) = 0;
Or if speed really is that critical, you might like to check out some of the submissions on MATLAB File Exchange:
  7 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 14 日
My checking shows that if you use 5 for r, and leave s symbolic, then there is a closed-form integral for the expression -- something that could be evaluated once per t rather than having to do the time-consuming numeric integration.
In the case of r held at 5, the integral for turns complex if s becomes larger than about 10.3 or if s is negative (but might become positive again below -10.3).
When you are varying r and s for your 16 runs, what are the values you are testing with?
Avan Al-Saffar
Avan Al-Saffar 2015 年 5 月 15 日
編集済み: Avan Al-Saffar 2015 年 5 月 15 日
r = 1,2.5,5,10
s = 1,3,5,10

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 5 月 13 日
For any of the arithmetic operations, a row vector is exactly the same speed as a column vector. However, extracting a column vector from a matrix is faster than extracting a row vector. Also, library functions often are defined as returning column vectors and their logic is sometimes marginally faster on column vectors.

カテゴリ

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