Eliminating Imaginary Numbers in an Array

8 ビュー (過去 30 日間)
Andrew
Andrew 2012 年 6 月 1 日
Let's say I have an array,
Array = -1/8:1/16:1/8; so the array should be [-1/8 -1/16 0 1/16 1/8]
and I want to find all the one third powers of all the elements in that array, in another array,
NewArray = Array.^(1/3);
the array should be [-0.5 -0.397 0 0.397 0.5] but matlab gives me imaginary numbers for the negative values. My only idea so far has been to have two seperate arrays, the one third power of all the numbers from 0 to 1/8 to get the positive numbers, and then negative one times the one third power of the double transpose of those same numbers to get the negative numbers. The code gets a little bit messy doing it that way because there is an equal chance that I will need both odd and even numbers at different times for the total number of elements in the negative to positive array. I'm looking for a better and simpler way to do this seemingly simple operation. Thanks!

採用された回答

Teja Muppirala
Teja Muppirala 2012 年 6 月 1 日
Array = [-1/8 -1/16 0 1/16 1/8];
NewArray = nthroot(Array,3)
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 1 日
see also realpow

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

その他の回答 (0 件)

カテゴリ

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