Computing powers in matlab
5 次查看(过去 30 天)
显示 更早的评论
find A whose ith element is A = ( 2.^i ) X ./ Y .... where X and Y are vectors of equal length
without looping. ie. X = [1 2 3] Y = [4 5 6].
I know how to do X ./ Y but the ith element of (2.^i) is confusing me and I do not know how to do it without looping. Thanks
Edit. Thank you 2.^(1:length(x)) worked. What if it was -2 instead of 2??? I tried fooling around with it but I had no luck
0 个评论
回答(3 个)
Mischa Kim
2014-1-16
编辑:Mischa Kim
2014-1-16
Does this do it?
X = [1 2 3]; Y = [4 5 6];
A = (2.^sort(randperm(length(X)))).*X./Y
A =
0.5000 1.6000 4.0000
Walter Roberson
2014-1-16
2.^(1:3)
4 个评论
Mischa Kim
2014-1-16
Ok, I understand. For the vector size portion, I have to admit, I tried to come up with a challenge for myself.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!