Brief question: faster to zero before direct computation?

Hello all, quick question,
in the simplest of examples,
x1a = linspace(-1,1,100);
y1a = zeros(1,100);
y1a = x1a.^3;
Is it a clear computational speed and economy advantage to declare y1a first with zeros, or not, in this simple case?
Is the cube operation one that does not require nor benefit from variable declaration?
Cheers

4 件のコメント

per isakson
per isakson 2014 年 12 月 18 日
編集済み: per isakson 2014 年 12 月 18 日
  • y1a = zeros(1,100); offers no advantage. It adds to the execution time.
  • "cube operation" is not affected by "variable declaration"
Miguel
Miguel 2014 年 12 月 18 日
this reply is a bit confusing, you are saying it offers no advantage, correct?
per isakson
per isakson 2014 年 12 月 18 日
編集済み: per isakson 2014 年 12 月 18 日
Not just confusing. It was wrong; a "no" was missing. I've edited the comment.
Miguel
Miguel 2014 年 12 月 18 日
Ok then, I reckon this answers it, I would like to know, however, if the statement y1a = x1a.^3 is something that builds the y1a variable one by one increasing its size after each value is computed, or, what I am suspecting is the case, applies the operation first to the x1a matrix, and then assigns this to variable y1a?

回答 (0 件)

この質問は閉じられています。

製品

タグ

質問済み:

2014 年 12 月 18 日

閉鎖済み:

2014 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by