在 Scheme 中将两个复数相乘
Multiplying two complex numbers in Scheme
我有复数的数据表示,但我不知道如何将两个复数相乘。也许,有人可以帮助我吗?
(define (complex-num a b)
(cons a b))
(define (real x)
(car x))
(define (imag x)
(cdr x))
w=10=sh
w=13=will,g:w=12=sh
w=11=sh
让我们尝试将两个复数相乘
(a + bi) * (c + di) = (a + bi) * c + (a + bi) * di
= ac + bci + adi + bdii
= ac + bci + adi - bd (here we use that i*i = -1)
= ac-bd + (bc+ad)i
如果我们输入 z1=a+bi
和 z2=c+di
那么我们可以将其转换为方案:
(define (multiply z1 z2)
(let ([a (real z1)]
[b (imag z1)]
[c (real z2)]
[d (imag z2)])
(complex-num ..compute ac-bd.. ..compute bc+ad.. )))
我有复数的数据表示,但我不知道如何将两个复数相乘。也许,有人可以帮助我吗?
(define (complex-num a b)
(cons a b))
(define (real x)
(car x))
(define (imag x)
(cdr x))
让我们尝试将两个复数相乘
(a + bi) * (c + di) = (a + bi) * c + (a + bi) * di
= ac + bci + adi + bdii
= ac + bci + adi - bd (here we use that i*i = -1)
= ac-bd + (bc+ad)i
如果我们输入 z1=a+bi
和 z2=c+di
那么我们可以将其转换为方案:
(define (multiply z1 z2)
(let ([a (real z1)]
[b (imag z1)]
[c (real z2)]
[d (imag z2)])
(complex-num ..compute ac-bd.. ..compute bc+ad.. )))