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?

Risposte (1)

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

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by