复数除法类
Complex Number Division class
本文关键字:除法 更新时间:2023-10-16
我正试图重载运算符来划分两个复数
使用3+2i/4-3i 进行测试
complex g(3, 2);
complex f(4,-3);
cout << g / f << endl;
我们走后我添加了* -1.0
数学中的(4*4)+(3*-3)i^2是25
((3*4)+(3*-3)*-1)是我的意图
测试我得到-0.545455 - 1.72727i
而在我添加*1.0之前,我得到了
0.24 +0.76i
这与非常接近
0.24 + 0.68i
答案
complex complex :: operator/ (complex& x) {
complex conjugate = x.conj();
double j = (real * conjugate.real) + (imag * conjugate.imag); // real
double u = (real * conjugate.imag) + (imag * conjugate.real); // imag
double h = (((conjugate.imag * imag)* -1.0) + (real * conjugate.real)) + ( (real*conjugate.imag) + (imag * conjugate.real));
return complex(j/h,u/h);
}
这是错误的:
double j = (real * conjugate.real) + (imag * conjugate.imag); // real
应该是-
,而不是+
。
这是正确的:
double u = (real * conjugate.imag) + (imag * conjugate.real); // imag
虽然CCD_ 5和CCD_。
这是怎么回事?
double h = (((conjugate.imag * imag)* -1.0) + (real * conjugate.real)) + ( (real*conjugate.imag) + (imag * conjugate.real));
分母只是x*conjugate
,它是:
double denom = x.real * x.real + x.imag * x.imag;
附带说明,您希望通过引用const来获取您的论点。
相关文章:
- 在除法中不需要四舍五入
- 在TFHE(完全快速同态加密)上执行除法
- 使用 int 表示浮点除法 C++
- 而循环:简单的除法程序输出零,不明白为什么
- 余数除法和不允许除以零 (c++) 时遇到问题
- 如何确定涉及 C++ 中除法的算术表达式的数据类型
- 如何使用除法和for_each?
- C++:奇怪的除法输出
- 分配给浮点数的积分文字除法 - 为什么结果是错误的?
- 除法函数返回错误的值
- 检查向量是否使用除法和阻抗算法进行排序
- 不使用算术运算符的除法
- C++编译器能在编译时计算出文字的除法结果吗
- 浮点 由于除法语句而导致的 c++ 异常
- 特征矩阵向量除法
- 在早期的 C 和 C++ 编译器中,手动位移位与乘法和除法的相关性如何?
- 用除法反转向量的元素
- 按运行时常量值重复整数除法
- 将 int 128 除法提升为浮点数
- 用于 3D 矢量的高效除法运算符