在java中隔离复数中的实数
我需要在我的应用程序中使用一个公式: 这里
部分 Sqrt(5-25) ,可以是正数或负数,当然,当负数时,我们得到了 java 无法处理的虚数部分。
我四处寻找一个复杂的类来处理这个问题,但只发现了基本操作(+-*/)。
我怎样才能在java中解决这个问题,知道我只需要得到实数部分?(虚数并不重要)
我精确地说,我在android平台上开发
(我在堆栈上发布,因为它涉及java中的应用程序,但如果它属于数学。瑟,告诉我)
There is a formula i need to use for my app : here
the part Sqrt(5-25) , can be positive or negative , and of course when negative we got a imaginary part that java cant handle.
i've searched around to find a complex class to handle that , but found only basic operation (+-*/).
how can i solve this in java knowing i only need to get the real part ?(imaginary have no importance)
i precise that i develop on android platform
(i post on stack because it's concerning application in java , but if its belong to math.se , tell me)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以简单地计算之前的所有内容:
从 0 到 38 绘制 25-20+((2Pi0.3²)/(Pi10²)Sqrt[2*980(1+(Pi10²)/(Pi10²))]t)²
或
绘制 25- 20+((2*0.3²)/(10²)Sqrt[2*980(1+1)]t)² 从 0 到38
或
25 - 20 + 4 * 0.0000081 * 3920*t^2 从 0 到 38 (我有一些错误的因素,但你明白了)
只需将基本数学应用于常数并在应用后删除中间(虚部)第二个二项公式。
与复数无关。
You can simply compute verything before:
plot 25-20+((2Pi0.3²)/(Pi10²)Sqrt[2*980(1+(Pi10²)/(Pi10²))]t)² from 0 to 38
or
plot 25-20+((2*0.3²)/(10²)Sqrt[2*980(1+1)]t)² from 0 to 38
or
25 - 20 + 4 * 0.0000081 * 3920*t^2 from 0 to 38 (I have some factor wrong, but you get the idea)
just apply basic math to the constants and remove the middle (imaginary part) after applying the 2nd binomic formula.
There is nothing to do with complex numbers.
可以通过实数的基本算术运算(加上实数的平方根)来完成一般复数的平方根:http://www.mathpropress.com/stan/bibliography/complexSquareRoot.pdf(一种技术是利用德莫弗定理:任意复数 a + bi 可以写成
r(cos θ + i sin θ)
其中更新:公式
r(cos θ + i sin θ)< /code> 最初是由欧拉提出的,而德莫弗定理是
Taking the Square root of a general complex number can be done with the basic arithmetic operations on real numbers (plus taking square root of reals): http://www.mathpropress.com/stan/bibliography/complexSquareRoot.pdf (one technique is to utilise De Moivre's theorem: Any complex number a + bi can be written as
r(cos θ + i sin θ)
whereUpdate: the formula
r(cos θ + i sin θ)
is originaly due to Euler, whereas De Moivre's theorem is你对数学感到困惑。 -25 的平方根是 25*(-1) 的平方根,即 25 * -1 的平方根的平方根,即 5i。该数字的实部是 0。
如果您想要 5,只需检查该数字的符号是否为“根”,如果为负则更改它。
You are confused about the math. Square root of -25 is square root of 25*(-1) and that is square root of 25 * square root of -1 and that is 5i. Real part of that number is 0.
If you want the 5, just check for the sign of the number to be "rooted" and change it if it is negative.
说“Java搞不定”是不对的。任何从平方根返回双精度值的语言都无法处理它,但如果您有一个
Complex
类,那么这不是问题。 Python 有一个内置的;用 Java 编写一个很容易。It's not right to say that "Java can't handle it". No language that returns a double from a square root can handle it, but if you have a
Complex
class it's not an issue. Python has one built in; it's easy to write one in Java.整数的平方根将是实部为零的整数或复数。负整数的平方根的实部为零。总是。
所以 ...
我希望是这样! (丢弃虚部的想法对我来说没有多大意义......但我认为您有充分的理由这样做。)
真正的答案是找到一个可以执行复杂算术的 Java 库。我从来不需要使用它,但第一个要检查的应该是 Apache Commons Maths 库。
The square root of an integer is going to be an integer or a complex number whose real part is zero. The real part of the square root of a negative integer is zero. Always.
So ...
I expect that's so! (The idea of discarding the imaginary part didn't make much sense to me ... but I assumed you had a sound reason to do this.)
The real answer is to find a Java library that will do complex arithmetic. I've never needed to use it, but the first one to examine should be the Apache Commons Maths library.