Oleksii Trekhleb | Javascript algorithms (Complex number)

This is a series of books diving deep into the core mechanisms of the JavaScript language.

 · 5 phút đọc.

This is a series of books diving deep into the core mechanisms of the JavaScript language.

A complex number is a number that can be expressed in the form a + b i, where a and b are real numbers, and i is a solution of the equation x^2 = −1. Because no real number satisfies this equation, i is called an imaginary number. For the complex number a + b i, a is called the real part, and b is called the imaginary part.

Complex Number

A Complex Number is a combination of a Real Number and an Imaginary Number:

Complex Number

Geometrically, complex numbers extend the concept of the one-dimensional number line to the two-dimensional complex plane by using the horizontal axis for the real part and the vertical axis for the imaginary part. The complex number a + b i can be identified with the point (a, b) in the complex plane.

A complex number whose real part is zero is said to be purely imaginary; the points for these numbers lie on the vertical axis of the complex plane. A complex number whose imaginary part is zero can be viewed as a real number; its point lies on the horizontal axis of the complex plane.

Complex NumberReal PartImaginary Part
3 + 2i32
550Purely Real
−6i0-6Purely Imaginary

A complex number can be visually represented as a pair of numbers (a, b) forming a vector on a diagram called an Argand diagram, representing the complex plane. Re is the real axis, Im is the imaginary axis, and i satisfies i^2 = −1.

Complex Number

Complex does not mean complicated. It means the two types of numbers, real and imaginary, together form a complex, just like a building complex (buildings joined together).

Polar Form

An alternative way of defining a point P in the complex plane, other than using the x- and y-coordinates, is to use the distance of the point from O, the point whose coordinates are (0, 0) (the origin), together with the angle subtended between the positive real axis and the line segment OP in a counterclockwise direction. This idea leads to the polar form of complex numbers.

Polar Form

The absolute value (or modulus or magnitude) of a complex number z = x + yi is:

Radius

The argument of z (in many applications referred to as the phase) is the angle of the radius OP with the positive real axis, and is written as arg(z). As with the modulus, the argument can be found from the rectangular form x+yi:

Phase

Together, r and φ give another way of representing complex numbers, the polar form, as the combination of modulus and argument fully specify the position of a point on the plane. Recovering the original rectangular co-ordinates from the polar form is done by the formula called trigonometric form:

Polar Form

Using Euler’s formula this can be written as:

Euler's Form

Basic Operations

Adding

To add two complex numbers we add each part separately:

(a + b  i) + (c + d  i) = (a + c) + (b + d)  i

Example

(3 + 5i) + (4 − 3i) = (3 + 4) + (5 − 3)i = 7 + 2i

On complex plane the adding operation will look like the following:

Complex Addition

Subtracting

To subtract two complex numbers we subtract each part separately:

(a + b  i) - (c + d  i) = (a - c) + (b - d)  i

Example

(3 + 5i) - (4 − 3i) = (3 - 4) + (5 + 3)i = -1 + 8i

Multiplying

To multiply complex numbers each part of the first complex number gets multiplied by each part of the second complex number:

Just use FOIL, which stands for Firsts, Outers, Inners, Lasts ( see Binomial Multiplication for more details):

Complex Multiplication

  • Firsts: a × c
  • Outers: a × di
  • Inners: bi × c
  • Lasts: bi × di

In general it looks like this:

(a + bi)(c + di) = ac + adi + bci + bdi^2

But there is also a quicker way!

Use this rule:

(a + bi)(c + di) = (ac − bd) + (ad + bc)i

Example

(3 + 2i)(1 + 7i)
= 3×1 + 3×7i + 2i×1+ 2i×7i
= 3 + 21i + 2i + 14i^2
= 3 + 21i + 2i − 14   (because i^2 = −1)
= −11 + 23i
(3 + 2i)(1 + 7i) = (3×1 − 2×7) + (3×7 + 2×1)i = −11 + 23i

Conjugates

We will need to know about conjugates in a minute!

A conjugate is where we change the sign in the middle like this:

Complex Conjugate

A conjugate is often written with a bar over it:

______
5 − 3i   =   5 + 3i

On the complex plane the conjugate number will be mirrored against real axes.

Complex Conjugate

Dividing

The conjugate is used to help complex division.

The trick is to multiply both top and bottom by the conjugate of the bottom.

Example

2 + 3i
------
4 − 5i

Multiply top and bottom by the conjugate of 4 − 5i:

  (2 + 3i)  (4 + 5i)   8 + 10i + 12i + 15i^2
= ------------------- = ----------------------
  (4 − 5i)  (4 + 5i)   16 + 20i − 20i − 25i^2

Now remember that i^2 = −1, so:

  8 + 10i + 12i − 15    −7 + 22i   −7   22
= ------------------- = -------- = -- + --  i
  16 + 20i − 20i + 25      41      41   41

There is a faster way though.

In the previous example, what happened on the bottom was interesting:

(4 − 5i)(4 + 5i) = 16 + 20i − 20i − 25i

The middle terms (20i − 20i) cancel out! Also i^2 = −1 so we end up with this:

(4 − 5i)(4 + 5i) = 4^2 + 5^2

Which is really quite a simple result. The general rule is:

(a + bi)(a − bi) = a^2 + b^2
nhavantuonglai

Share:
Quay lại.

Có thể bạn chưa đọc

Xem tất cả »

Đăng ký nhận bảng tin hàng tuần

Liên lạc trao đổi

Liên lạc thông qua Instagram

Thông qua Instagram, bạn có thể trao đổi trực tiếp và tức thời, cũng như cập nhật những thông tin mới nhất từ nhavantuonglai.

Tức thời

Bạn có thể gửi và nhận tin nhắn nhanh chóng, trực tiếp, giúp những vấn đề cá nhân của bạn được giải quyết tức thời và hiệu quả hơn.

Thân thiện

Vì tính chất là kênh liên lạc nhanh, nên bạn có thể bỏ qua những nghi thức giao tiếp thông thường, chỉ cần lịch sự và tôn trọng thì sẽ nhận được sự phản hồi đầy thân thiện, thoải mái từ tác giả.

Trao đổi trên email

Thông qua email cá nhân, bạn có thể trao đổi thỏa thuận hợp tác, kết nối chuyên sâu và mang tính chuyên nghiệp.

Tin cậy

Trong một số trường hợp, email được dùng như một tài liệu pháp lý, chính vì vậy mà bạn có thể an tâm và tin cậy khi trao đổi với tác giả thông qua email.

Chuyên nghiệp

Cấu trúc của email đặt tính chuyên nghiệp lên hàng đầu, nên những thông tin, nội dung được viết trong email từ tác giả sẽ luôn đảm bảo điều này ở mức cao nhất.

nhavantuonglai · Ghiblis Music Piano Playlist