我正在尝试找出如何将两个复数相乘,但是我知道它与普通的复数乘法完全不同。我这样做是为了将两个复数相加,有人可以帮我做乘法吗?
%%Z1=X1+Y1 and Z2=X2+Y2.
add(a(X1,X2), a(Y1,Y2), a(Z1,Z2)) :-
Z1 is X1 + Y1,
Z2 is X2 + Y2.
答案 0 :(得分:0)
与其说是数学问题,不如说是序言问题:
(x1 + ix2) x (y1 + iy2) = x1(y1 + iy2) + ix2(y1+iy2)
= x1y1 + ix1y2 + ix2y1 - x2y2
= (x1y1-x2y2) + i(x1y2+x2y1)
因此,规则:
%%Z1=x1y1-x2y2 and Z2=x1y2+x2y1.
multiply(a(X1,X2), a(Y1,Y2), a(Z1,Z2)) :-
Z1 is X1 * Y1 - X2 * Y2,
Z2 is X1* Y2 + X2 * Y1.