- #1
Poirot
- 94
- 2
I have a Do loop running which, for some values will become complex, and I want to make it so for these situations, we take the negative root and for others the positive root. In this scenario, I've simplified what I actually have and chose to look at the case where I need it to take the negative root
I can't seem to get the syntax right here, and if I print a table with the results it's as if the If is just being ignored.
Ideally, this would be the best approach for my problem as my actual code is quite complex and values in the Do loops are called upon, so I fear any other method will cause grief elsewhere.
Thanks for any help!
Code:
Do[e[o] = 0.5 + o, {o, 0, 10}]
Do[If[Element[x[n, o] = (e[o] - n)^(1/2), Complexes], -[x[n, o]],
x[n, o]], {n, -10, 10}, {o, -10, 10}]
I can't seem to get the syntax right here, and if I print a table with the results it's as if the If is just being ignored.
Ideally, this would be the best approach for my problem as my actual code is quite complex and values in the Do loops are called upon, so I fear any other method will cause grief elsewhere.
Thanks for any help!