Home computickets How to make the result of a cubic root definite?

How to make the result of a cubic root definite?

Author

Date

Category

Why in matlab the result of a cubic root can be correct, but not unambiguous?
For example,

& gt; & gt; (-5-3) ^ (1/3)
ANS =.
  1.0000 + 1.7321i

And if immediately:

& gt; & gt; -8 ^ (1/3)
ANS =.
  -2.

It is clear that in both cases a cubic root is extracted from -8, but the answer is different, although the right one in both cases.

How can you control which result you need to get – integrated or valid?


Answer 1, Authority 100%

You can nthroot Use to calculate the real value of the root N-th degree.

Judging by Documentation Operator A. ^ b For negative A and fractional B module less 1 will always return the integrated value of the root.

If it happened, as you describe, then in the unary – priority is lower than y ^, do so (-8) ^ (1/3) – and get the expected comprehensive result.

Previous articleFloating menu
Next articleIs there an array … mats?

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions