现有三个复数,表示如下:
A(a1,b1)
B(a2,b2)
C(a3,b3)
求A/B=C中的C=?
1、显然,有A=BC,于是得:
(a1,b1)=(a2,b2)*(a3,b3)
2、将右式展开得到:
(a1,b1)=(a2a3-b2b3,a2b3+a3b2)
3、由待定系数法:
a3=(a1+b2b3)/a2 b3=(b1-b2a3)/a2
4、带入2式,得:
a3=(a1a2+b1b2)/(a2a2+b2b2) b3=(a2b1-a1b2)/(a2a2+b2b2)
算法检验:
(1) a2=0,b2=0时,可以通过弹窗显示“零不能作除数”
(2) a2=0,b2!=0时,由待定系数法,a3=b1/b2,b3=-a1/b2,与4式一致
public static Complex operator /(Complex dividend, Complex divisor) { if (divisor.real==0 && divisor.imaginary==0) { System.Windows.Forms.MessageBox.Show("零不能作除数", "数学域错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1); return dividend; } double newR = (dividend.real * divisor.real + dividend.imaginary * divisor.imaginary) / (divisor.real * divisor.real + divisor.imaginary * divisor.imaginary); double newI = (divisor.real * dividend.imaginary - dividend.real * divisor.imaginary) / (divisor.real * divisor.real + divisor.imaginary * divisor.imaginary); return new Complex(newR, newI); }
原文:http://blog.csdn.net/xiaoy_h/article/details/24145007