Help! Negative number problem

Hello everyone! I'm currently trying to get a (one) negative number in a matrix to power to 'S' so for example (-5)^4. I thought brackets would help me, but nevertheless the output is still -1. The code is beneath and everything works, but the -1 stays a negative number. Can somebody help me?
for u = 1:1:m
for k = 2:1:m
f(u,k) = (f(u,k))^S
a = f(u,k)
h = S
end
S = S + 1
end
The input (matrix f) is as follows:
1 1 1 1
-1 0 3 5
-1 0 3 5
-1 0 3 5
And the output that i get (output from the code above, so the new matrix f):
1 1 1 1
-1 0 9 25
-1 0 27 125
-1 0 81 624
as you can see the rest output of the rest is going good, but when it comes to the negative it isnt. Does anybody know what the problem is?

回答 (1 件)

Timothy Singowikromo
Timothy Singowikromo 2018 年 3 月 24 日

0 投票

Ahh! I have found my problem haha... the parameters where wrong
for u = 2:1:m
for k = 1:1:m
f(u,k) = (f(u,k))^S
a = f(u,k)
h = S
end
S = S + 1
end

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2018 年 3 月 24 日

回答済み:

2018 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by