MATLABMATLAB · Chapterبەش 4 · Lectureوانە 4.5

Matrix Operations vs Element-by-Element Operationsکارەکانی ماتریکس بەرامبەر کارەکانی توخم بە توخم

Add and subtract arrays of the same size, multiply matrices with * (columns of A = rows of B), use the dotted operators .* ./ .\ .^ to pair up elements (same or compatible sizes), tell the matrix power A^2 from A.^2, see why formulas on vectors need the dot, and solve Ax=bAx = b with A\b.

هەمان قەبارە کۆ بکەرەوە و لێدەربکە، بە * لێک بدە (ستوونەکانی A = ڕیزەکانی B)، .* ./ .\ .^ بۆ جووتکردنی بەکار بهێنە (قەبارەی یەکسان یان گونجاو)، A^2 لە A.^2 جیا بکەرەوە، ببینە بۆچی لەسەر پێویستیان بە خاڵە و Ax=bAx = b بە A\b چارەسەر بکە.

15 min read17 خولەک خوێندنەوە · 15 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Add, subtract and scale arrays and explain the same-size rule.
  • Multiply matrices with * and predict the size of the result or the error.
  • Use .*, ./, .\ and .^ on arrays of the same or compatible sizes.
  • Tell A^2 (matrix power) from A.^2 and write formulas on vectors with the dot.
  • Solve a system of linear equations with A\b.
  • کۆ بکەیتەوە، لێدەربکەیت و لە ژمارە بدەیت و یاسای هەمان قەبارە ڕوون بکەیتەوە.
  • بە * لێک بدەیت و قەبارەی ئەنجامەکە یان پێشبینی بکەیت.
  • .*، ./، .\ و .^ لەسەر قەبارەی یەکسان یان گونجاو بەکار بهێنیت.
  • A^2 ( ) لە A.^2 جیا بکەیتەوە و لەسەر بە خاڵ بنووسیت.
  • سیستەمێکی بە A\b چارەسەر بکەیت.

Adding and subtracting arraysکۆکردنەوە و لێدەرکردنی ڕیزەکەکان

+ and - work element by element: the first element with the first, the second with the second, and so on. So both arrays must have the same size — exactly the rule of matrix addition in maths (the same-size rule). Every example in this lesson also runs in GNU Octave and in the free version of MATLAB Online.

+ و - توخم بە توخم کار دەکەن: یەکەم لەگەڵ یەکەم، دووەم لەگەڵ دووەم و هتد. بۆیە هەردوو دەبێت هەمان قەبارەیان هەبێت — ڕێک یاسای کۆکردنەوەی لە ماتماتیکدا (یاسای هەمان قەبارە). هەموو نموونەیەکی ئەم وانەیە لە ⁦GNU Octave⁩ و لە وەشانی بەخۆڕایی ⁦MATLAB Online⁩ـیشدا کار دەکات.

Two vectors and two 2×32 \times 3 matrices (new numbers)دوو ئاڕاستەبڕ و دوو ماتریکسی 2×32 \times 3 (بە ژمارەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
a = [6 2 9];
b = [4 7 1];
a + b
a - b
P = [4 -2 7; 3 6 -1];
Q = [1 5 -3; 8 -4 2];
P + Q
P - Q
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

6+46 + 4, 2+72 + 7, 9+19 + 1.

6+46 + 4، 2+72 + 7، 9+19 + 1.

Lineدێڕی 8

Position by position: 4−1=34 - 1 = 3, −2−5=−7-2 - 5 = -7, 7−(−3)=107 - (-3) = 10, …

شوێن بە شوێن: 4−1=34 - 1 = 3، −2−5=−7-2 - 5 = -7، 7−(−3)=107 - (-3) = 10، …

Quick checkپشکنینی خێرا[1 2 3] + [4 5] gives …[1 2 3] + [4 5] چی دەدات؟

Adding and subtracting arraysکۆکردنەوە و لێدەرکردنی ڕیزەکەکان

A number with an arrayژمارەیەک لەگەڵ ڕیزەکێک

A single number (a ) is different: it goes to every element. P + 10 adds 10 to all six elements, 2*P doubles them and P/2 halves them. No dot is needed for these (multiplying a matrix by a number).

تەنها یەک ژمارە () جیاوازە: دەچێتە سەر هەموو . P + 10 ⁦10⁩ بۆ هەر شەش زیاد دەکات، 2*P دووجایان دەکات و P/2 نیوەیان دەکات. بۆ ئەمانە خاڵ پێویست نییە (لێکدانی ماتریکسێک لە ژمارەیەک).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
P + 10
2*P
P/2
Quick checkپشکنینی خێراv = [3 6 9]. What is v/3 - 1?v = [3 6 9]. v/3 - 1 چییە؟

Matrix multiplication: *لێکدانی ماتریکسەکان: *

* between two matrices is matrix multiplication from : each entry of the answer is a row of the first matrix times a column of the second — multiply in pairs, then add (row times column, one entry). So the number of columns of A must equal the number of rows of B, and the answer has the rows of A and the columns of B: a 4×34 \times 3 times a 3×23 \times 2 gives a 4×24 \times 2.

* لە نێوان دوو لێکدانی لە : هەر ژمارەیەکی وەڵامەکە ڕیزێکی یەکەم جارانی ستوونێکی دووەمە — جووت جووت لێکیان بدە، پاشان کۆیان بکەرەوە (ڕیز جارانی ستوون، یەک ژمارە). بۆیە ژمارەی ستوونەکانی A دەبێت یەکسان بێت بە ژمارەی ڕیزەکانی B و وەڵامەکە ڕیزەکانی A و ستوونەکانی Bـی هەیە: 4×34 \times 3 جارانی 3×23 \times 2 دەکاتە 4×24 \times 2.

Animation: A = [2 1 3; 0 4 1; 5 2 2] times B = [1 3; 2 0; 4 1]. In each frame one row of A and one column of B are highlighted and one entry of the 3 × 2 answer is written: 2·1 + 1·2 + 3·4 = 16, then 9, 12, 1, 17 and 17. The last frame shows C = [16 9; 12 1; 17 17].
Animation: A = [2 1 3; 0 4 1; 5 2 2] times B = [1 3; 2 0; 4 1]. In each frame one row of A and one column of B are highlighted and one entry of the 3 × 2 answer is written: 2·1 + 1·2 + 3·4 = 16, then 9, 12, 1, 17 and 17. The last frame shows C = [16 9; 12 1; 17 17].
A 3×33 \times 3 times a 3×23 \times 2, filled cell by cell: row of A times column of B3×33 \times 3 جارانی 3×23 \times 2، خانە بە خانە پڕ دەکرێتەوە: ڕیزی A جارانی ستوونی BCêIT
The product in the animation, and a 4×34 \times 3 times a 3×23 \times 2 (new numbers)لێکدانی ناو ئەنیمەیشنەکە، هەروەها 4×34 \times 3 جارانی 3×23 \times 2 (بە ژمارەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
A = [2 1 3; 0 4 1; 5 2 2];
B = [1 3; 2 0; 4 1];
C = A*B
F = [2 0 1; 1 3 2; 4 1 0; 0 2 5];
G = [3 1; 2 4; 1 0];
F*G
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

3×33 \times 3 times 3×23 \times 2: the inner sizes (3 and 3) agree, the answer is 3×23 \times 2. Entry (1,1): 2⋅1+1⋅2+3⋅4=162 \cdot 1 + 1 \cdot 2 + 3 \cdot 4 = 16.

3×33 \times 3 جارانی 3×23 \times 2: قەبارە ناوەکییەکان (⁦3⁩ و ⁦3⁩) یەک دەگرنەوە، وەڵامەکە 3×23 \times 2ـە. ژمارەی ⁦(1,1)⁩: 2⋅1+1⋅2+3⋅4=162 \cdot 1 + 1 \cdot 2 + 3 \cdot 4 = 16.

Lineدێڕی 6

4×34 \times 3 times 3×23 \times 2 gives 4×24 \times 2. Entry (2,2): 1⋅1+3⋅4+2⋅0=131 \cdot 1 + 3 \cdot 4 + 2 \cdot 0 = 13.

4×34 \times 3 جارانی 3×23 \times 2 دەکاتە 4×24 \times 2. ژمارەی ⁦(2,2)⁩: 1⋅1+3⋅4+2⋅0=131 \cdot 1 + 3 \cdot 4 + 2 \cdot 0 = 13.

Quick checkپشکنینی خێراH is 2×52 \times 5 and K is 5×35 \times 3. What is the size of H*K?H 2×52 \times 5ـە و K 5×35 \times 3. قەبارەی H*K چەندە؟

Matrix multiplication: *لێکدانی ماتریکسەکان: *

When * fails, and why order mattersکەی * سەرناکەوێت و بۆچی ڕیزبەندی گرنگە

Swap the two matrices above and the inner sizes no longer agree: G*F is a 3×23 \times 2 times a 4×34 \times 3, and 2≠42 \ne 4. MATLAB stops with an about incorrect dimensions for matrix multiplication (older releases, like the ones in the course notes, said “Inner matrix dimensions must agree.”). Even when both orders work, the answers usually differ: matrix multiplication is not commutative (AB and BA).

ئەگەر دوو سەرەوە بگۆڕیتەوە، قەبارە ناوەکییەکان ئیتر یەک ناگرنەوە: G*F 3×23 \times 2 جارانی 4×34 \times 3ـە و 2≠42 \ne 4. MATLAB بە دەربارەی ڕەهەندی هەڵە بۆ لێکدانی دەوەستێت (وەشانە کۆنەکان، وەک ئەوانەی تێبینییەکانی وانەکە، دەیانگوت «⁦Inner matrix dimensions must agree⁩.»). تەنانەت کاتێک هەردوو ڕیزبەندییەکە کار دەکەن، وەڵامەکان زۆربەی جار جیاوازن: لێکدانی گۆڕینەوەیی نییە، واتە ڕیزبەندی گرنگە (AB و BA).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
G*F
U = [2 1; 0 3];
V = [1 4; 2 1];
U*V
V*U
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

An error: 2 columns of G against 4 rows of F. No answer is printed.

: 2 ستوونی G بەرامبەر 4 ڕیزی F. هیچ وەڵامێک نانووسرێت.

Lineدێڕی 4-5

Both orders exist for 2×22 \times 2 matrices, but UV≠VUUV \ne VU.

بۆ 2×22 \times 2 هەردوو ڕیزبەندی هەن، بەڵام UV≠VUUV \ne VU.

Quick checkپشکنینی خێراA is 3×23 \times 2 and B is 2×32 \times 3. Which is true?A 3×23 \times 2ـە و B 2×32 \times 3. کامیان ڕاستە؟

MATLAB Crash Course for BeginnersfreeCodeCamp.org · Englishئینگلیزی · 1.7M viewsبینین · 37K likesلایک · Partبەشی 19:30–22:24 (ofلە 1:57:45)

A MATLAB beginner course by Phil Parisi: the Command Window, variables, vectors and matrices, indexing, scripts, sections and naming rules, each in short parts.

کۆرسێکی سەرەتایی MATLAB لەلایەن ⁦Phil Parisi: Command Window⁩، ، و ، ، ، بەشەکان و یاساکانی ناونان، هەر یەکەیان بە بەشێکی کورت.

Watch 19:30-22:24: a number goes to every element, AA fails because the inner sizes differ, A'A works, and x.^2 squares each element.

لە ⁦19:30⁩ تا ⁦22:24⁩ سەیر بکە: ژمارەیەک بۆ هەموو دەچێت، A*A سەرناکەوێت چونکە قەبارە ناوەکییەکان جیاوازن، A'*A کار دەکات و x.^2 هەر دووجا دەکات.

Matrix multiplication: *لێکدانی ماتریکسەکان: *

A row times a column: one numberڕیز جارانی ستوون: یەک ژمارە

A 1×n1 \times n row times an n×1n \times 1 column is a 1×11 \times 1 matrix — a single number. This is the of the two vectors, also given by dot. The other order, column times row, gives a whole n×nn \times n table.

ڕیزێکی 1×n1 \times n جارانی ستوونێکی n×1n \times 1 1×11 \times 1ـە — تەنها یەک ژمارە. ئەمە دوو کە dotـیش دەیدات. ڕیزبەندییەکەی تر، ستوون جارانی ڕیز، خشتەیەکی تەواوی n×nn \times n دەدات.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
r = [3 1 2];
c = [4; 5; 1];
r*c
dot(r, c)
c*r
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

3⋅4+1⋅5+2⋅1=193 \cdot 4 + 1 \cdot 5 + 2 \cdot 1 = 19.

یەک ژمارە: 3⋅4+1⋅5+2⋅1=193 \cdot 4 + 1 \cdot 5 + 2 \cdot 1 = 19.

Lineدێڕی 5

3×13 \times 1 times 1×31 \times 3: a 3×33 \times 3 table of all the products.

3×13 \times 1 جارانی 1×31 \times 3: خشتەیەکی 3×33 \times 3 لە هەموو لێکدانەکان.

Quick checkپشکنینی خێراWhat is [1 2 3] * [1; 1; 1]?[1 2 3] * [1; 1; 1] چییە؟

Element by element: .*, ./, .\ , .^توخم بە توخم: .*، ./، .\ ، .^

Often you do not want linear algebra at all — you just want to multiply each price by its own quantity. Put a dot before the operator and MATLAB pairs up the elements in the same position, like + does. This is an : A.*B multiplies, A./B divides (A over B), A.\B divides the other way (B over A) and A.^n raises every element to the power n.

زۆر جار پێویستت بە نییە — تەنها دەتەوێت هەر نرخێک لە بڕی خۆی بدەیت. خاڵێک بخە پێش و MATLAB لە هەمان شوێندا جووت دەکات، وەک +. ئەمە : A.*B لێک دەدات، A./B دابەش دەکات (A بەسەر B)، A.\B بە پێچەوانەوە دابەش دەکات (B بەسەر A) و A.^n هەموو بەرز دەکاتەوە بۆ n.

X = [2 1; 3 4] and Y = [5 0; 1 2] multiplied two ways. Left, XY: row 1 of X times column 1 of Y gives 2·5 + 1·1 = 11, and the answer is [11 2; 19 8]. Right, X.Y: matching cells are multiplied, 2·5 = 10, 1·0 = 0, 3·1 = 3, 4·2 = 8, giving [10 0; 3 8].X = [2 1; 3 4] و Y = [5 0; 1 2] بە دوو ڕێگە لێک دراون. چەپ، XY: ڕیزی 1ی X جارانی ستوونی 1ی Y دەکاتە 2·5 + 1·1 = 11 و وەڵامەکە [11 2; 19 8]ـە. ڕاست، X.Y: خانە هاوشوێنەکان لێک دەدرێن، 2·5 = 10، 1·0 = 0، 3·1 = 3، 4·2 = 8، کە [10 0; 3 8] دەدات.
Same two matrices, two different products: * (row × column) and .* (cell × cell)هەمان دوو ، دوو لێکدانی جیاواز: * (ڕیز × ستوون) و .* (خانە × خانە)CêIT
The course's example: dividing and multiplying element by elementنموونەی وانەکە: دابەشکردن و لێکدان توخم بە توخمMATLABType in a terminalلە تێرمیناڵدا بینووسە
A = [1 2 3; 4 5 6; 7 8 9];
B = [1 1 1; 2 2 2; 3 3 3];
A./B
A.*B
B.\A
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Each element of A over the element of B in the same place: 5/2=2.55/2 = 2.5, 7/3≈2.33337/3 \approx 2.3333, …

هەر A بەسەر B لە هەمان شوێن: 5/2=2.55/2 = 2.5، 7/3≈2.33337/3 \approx 2.3333، …

Lineدێڕی 4

Each pair multiplied: row 2 of A is doubled, row 3 tripled.

هەر جووتێک لێک دراوە: ڕیزی 2ی A دوو جار، ڕیزی 3 سێ جار.

Lineدێڕی 5

B.\A is “B under A”, the same as A./B.

B.\A واتە «B لە ژێر A»، هەمان A./B.

Quick checkپشکنینی خێراX = [2 1; 3 4], Y = [5 0; 1 2]. What is X.*Y?X = [2 1; 3 4]، Y = [5 0; 1 2]. X.*Y چییە؟

Element by element: .*, ./, .\ , .^توخم بە توخم: .*، ./، .\ ، .^

Compatible sizes: a row with a columnقەبارەی گونجاو: ڕیزێک لەگەڵ ستوونێک

Element-wise operators also accept arrays whose sizes are compatible: in each dimension the two sizes are equal, or one of them is 1. The size-1 array is then repeated to fit. A is the simplest case. The useful one is a column with a row: an n×1n \times 1 column and a 1×m1 \times m row give a whole n×mn \times m table. This rule is called (MATLAB R2016b and newer); Octave calls it broadcasting and does the same (its error for sizes that do not fit speaks of “nonconformant arguments”). Sizes that are not compatible stop with the message “Arrays have incompatible sizes for this operation.”

بە قەبارەی گونجاویش وەردەگرن: لە هەر ڕەهەندێکدا دوو قەبارەکە یەکسانن، یان یەکێکیان 1ـە. پاشان ئەو قەبارەکەی 1ـە دووبارە دەکرێتەوە تا جێ ببێتەوە. سادەترین بارە. بارە بەسوودەکە ستوونێکە لەگەڵ ڕیزێک: ستوونێکی n×1n \times 1 و ڕیزێکی 1×m1 \times m خشتەیەکی تەواوی n×mn \times m دەدەن. ئەم یاسایە پێی دەگوترێت (⁦MATLAB R2016b⁩ و نوێتر)؛ Octave پێی دەڵێت broadcasting و هەمان کار دەکات ( بۆ قەبارەی ناگونجاو باسی «⁦nonconformant arguments⁩» دەکات). قەبارەی ناگونجاو بەم دەوەستێت: «⁦Arrays have incompatible sizes for this operation⁩.»

The times table in one lineخشتەی لێکدان بە یەک دێڕMATLABType in a terminalلە تێرمیناڵدا بینووسە
t = (1:5)' .* (1:5)
[1 2 3] + [10 20]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

A 5×15 \times 1 column times a 1×51 \times 5 row, element by element: the 5×55 \times 5 times table of linear algebra and matrices.

ستوونێکی 5×15 \times 1 جارانی ڕیزێکی 1×51 \times 5، توخم بە توخم: خشتەی لێکدانی 5×55 \times 5ـی جەبری هێڵی و ماتریکسەکان.

Lineدێڕی 2

1×31 \times 3 and 1×21 \times 2: the second dimension is 3 against 2, neither is 1 — incompatible, so MATLAB stops with an error.

1×31 \times 3 و 1×21 \times 2: ڕەهەندی دووەم 3 بەرامبەر 2ـە، هیچیان 1 نییە — ناگونجاوە، بۆیە MATLAB بە دەوەستێت.

Quick checkپشکنینی خێراWhich pair of sizes is compatible for A + B?کام جووتە قەبارە بۆ A + B گونجاوە؟

A^2 or A.^2?A^2 یان A.^2؟

A^2 means A*A: the matrix power, built from row × column products, so A must be square (powers of a square matrix). A.^2 squares every element on its own. For the matrix A above they are very different: entry (1,1) of A^2 is row 1 of A times column 1 of A, 1⋅1+2⋅4+3⋅7=301 \cdot 1 + 2 \cdot 4 + 3 \cdot 7 = 30, while entry (1,1) of A.^2 is just 12=11^2 = 1.

A^2 واتە A*A: کە لە لێکدانی ڕیز × ستوون دروست دەبێت، بۆیە A دەبێت چوارگۆشەیی بێت (توانی ماتریکسێکی چوارگۆشەیی). A.^2 هەموو بە تەنها دووجا دەکات. بۆ Aـی سەرەوە زۆر جیاوازن: ژمارەی ⁦(1,1)⁩ی A^2 ڕیزی 1ی A جارانی ستوونی 1ی Aـیە، 1⋅1+2⋅4+3⋅7=301 \cdot 1 + 2 \cdot 4 + 3 \cdot 7 = 30، لە کاتێکدا ژمارەی ⁦(1,1)⁩ی A.^2 تەنها 12=11^2 = 1ـە.

A = [1 2 3; 4 5 6; 7 8 9] drawn twice side by side as A times A. Row 1 of the first copy (1, 2, 3) and column 1 of the second copy (1, 4, 7) are highlighted; below them the products 1·1, 2·4 and 3·7, that is 1, 8 and 21, add up to 30, the top-left entry of A^2 = [30 36 42; 66 81 96; 102 126 150].A = [1 2 3; 4 5 6; 7 8 9] دوو جار لە تەنیشت یەک وەک A جارانی A کێشراوە. ڕیزی 1ی یەکەمیان (1، 2، 3) و ستوونی 1ی دووەمیان (1، 4، 7) ڕووناک کراونەتەوە؛ لە خوارەوە لێکدانەکانی 1·1، 2·4 و 3·7، واتە 1، 8 و 21، کۆیان دەکاتە 30، ژمارەی سەرەوەی چەپی A^2 = [30 36 42; 66 81 96; 102 126 150].
Entry (1,1) of A^2: row 1 times column 1 = 30ژمارەی ⁦(1,1)⁩ی A^2: ڕیزی 1 جارانی ستوونی ⁦1 = 30⁩CêIT
MATLABType in a terminalلە تێرمیناڵدا بینووسە
A^2
A.^2
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

The matrix power, A*A.

، A*A.

Lineدێڕی 2

Every element squared.

هەموو دووجا کراوە.

Quick checkپشکنینی خێراN = [1 2; 3 4]. What is N^2?N = [1 2; 3 4]. N^2 چییە؟

Why the dot mattersبۆچی خاڵەکە گرنگە

In real programs you mostly use vectors of values — times, prices, radii — and want a formula applied to each value. Then the dot is essential. To compute y=x2y = x^2 for x=0,0.5,1,1.5,2x = 0, 0.5, 1, 1.5, 2 you write x.^2. Without the dot, x^2 asks for the matrix power of a 1×51 \times 5 row, which is not square, so MATLAB stops with an error; x*y for two rows fails the same way (1×51 \times 5 times 1×51 \times 5).

لە بەرنامەی ڕاستەقینەدا زۆرتر ژمارە بەکار دەهێنیت — کات، نرخ، نیوەتیرە — و دەتەوێت لەسەر هەر جێبەجێ بکرێت. ئەو کاتە خاڵەکە پێویستە. بۆ هەژمارکردنی y=x2y = x^2 بۆ x=0,0.5,1,1.5,2x = 0, 0.5, 1, 1.5, 2 دەنووسیت x.^2. بێ خاڵ، x^2 داوای ڕیزێکی 1×51 \times 5 دەکات کە چوارگۆشەیی نییە، بۆیە MATLAB بە دەوەستێت؛ x*y بۆ دوو ڕیز بە هەمان شێوە سەرناکەوێت (1×51 \times 5 جارانی 1×51 \times 5).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
x = 0:0.5:2;
y = x.^2
r = [1 2 3];
area = pi*r.^2
x^2
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Each x squared.

هەر x دووجا کراوە.

Lineدێڕی 4

Areas of three circles: pi* needs no dot (a number), r.^2 does.

ڕووبەری سێ بازنە: pi* خاڵی پێویست نییە (ژمارەیە)، r.^2 پێویستی هەیە.

Lineدێڕی 5

An error: ^ needs a square matrix. Use .^ for the power of each element.

: ^ پێویستی بە هەیە. بۆ هەر .^ بەکار بهێنە.

Matrix operator (linear algebra) ()Element-wise operator توخم بە توخمNeedsپێویستی بە
A*BA.*B*: columns of A = rows of B; .*: same or compatible sizes*: ستوونەکانی A = ڕیزەکانی B؛ .*: هەمان قەبارە یان قەبارەی گونجاو
A/B, A\BA./B, A.\B/ \ solve equations (next screen); ./ .\ divide pair by pair/ \ چارەسەر دەکەن (شاشەی دواتر)؛ ./ .\ جووت بە جووت دابەش دەکەن
A^nA.^n^: square A; .^: any A^: Aـی چوارگۆشەیی؛ .^: هەر A
A'A.'both swap rows and columns; ' also conjugates complex numbers (the transpose)هەردووکیان ڕیز و ستوون دەگۆڕنەوە؛ ' بۆ وەردەگرێت (جێگۆڕکێی ماتریکس)
A+B, A-Bthe sameهەمان شتalready element by element; no dot exists or is neededخۆیان توخم بە توخمن؛ خاڵ نییە و پێویستیش نییە
2*A, A/22.*A, A./2with a single number both forms give the same answerلەگەڵ تەنها یەک ژمارە هەردوو شێوەکە هەمان وەڵام دەدەن
Quick checkپشکنینی خێراYou want the volume 43πr3\frac{4}{3}\pi r^3 of balls with radii r = [1 2 3]. Which line is right?قەبارەی تۆپ 43πr3\frac{4}{3}\pi r^3ت دەوێت بۆ نیوەتیرەکانی r = [1 2 3]. کام دێڕ ڕاستە؟

Left division solves equations: A\bدابەشکردنی چەپ هاوکێشەکان چارەسەر دەکات: A\b

You met \ on numbers: 5\3 means 3 divided by 5 (the arithmetic operators). On matrices, x = A\b solves the system of Ax=bAx = b: it finds the column x that A turns into b. In maths the answer is x=A−1bx = A^{-1}b (solving AX=BAX = B with the inverse), and inv(A)*b gives the same numbers — but MathWorks recommends A\b: it solves by row operations without building the , so it is faster and more accurate.

پێشتر \ ـت لەسەر ژمارە بینی: 5\3 واتە 3 دابەش بە 5 (کارپێکەرە ژمێرەییەکان). لەسەر ، x = A\b سیستەمی Ax=bAx = b چارەسەر دەکات: ئەو ستوونە x دەدۆزێتەوە کە A دەیکات بە b. لە ماتماتیکدا وەڵامەکە x=A−1bx = A^{-1}bـە (چارەسەرکردنی AX=BAX = B بە پێچەوانەی ماتریکس)، inv(A)*bـیش هەمان ژمارەکان دەدات — بەڵام MathWorks A\b پێشنیار دەکات: بە چارەسەر دەکات بێ دروستکردنی ، بۆیە خێراتر و وردترە.

4x+2y=2500x+3y=2500⟹[4213][xy]=[25002500]\begin{aligned} 4x + 2y &= 2500 \\ x + 3y &= 2500 \end{aligned} \qquad\Longrightarrow\qquad \begin{bmatrix} 4 & 2 \\ 1 & 3 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 2500 \\ 2500 \end{bmatrix}

At a tea house Aram pays 2500 IQD for 4 teas and 2 sandwiches; Shilan pays 2500 IQD for 1 tea and 3 sandwiches. x is the price of a tea, y the price of a sandwich.

لە چایخانەیەک ئارام ⁦2500⁩ دینار دەدات بۆ 4 چا و 2 ساندویچ؛ شیلان ⁦2500⁩ دینار دەدات بۆ 1 چا و 3 ساندویچ. x نرخی چایەکە، y نرخی ساندویچێک.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
A = [4 2; 1 3];
b = [2500; 2500];
x = A\b
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

A tea costs 250 IQD and a sandwich 750 IQD. Check: A*x gives back b. inv(A)*b gives the same answer here.

چایەک ⁦250⁩ دینار و ساندویچێک ⁦750⁩ دینار. پشکنین: A*x b دەگەڕێنێتەوە. inv(A)*bـیش لێرەدا هەمان وەڵام دەدات.

If A is a (no inverse), the system has no single answer and MATLAB warns (a determinant that should be 0). For more than two equations nothing changes: A is n×nn \times n and b has n rows.

ئەگەر A بێت (پێچەوانەی نەبێت)، سیستەمەکە یەک وەڵامی نییە و MATLAB ئاگادار دەکاتەوە (دیتەرمینانتێک کە دەبوو 0 بێت). بۆ زیاتر لە دوو هیچ ناگۆڕێت: ⁦A n × n⁩ـە و ⁦b n⁩ ڕیزی هەیە.

Quick checkپشکنینی خێراWhich command solves Ax=bAx = b the way MathWorks recommends?کام Ax=bAx = b بەو شێوەیە چارەسەر دەکات کە MathWorks پێشنیاری دەکات؟

The Complete MATLAB Course: Beginner to Advanced!Joseph Delgadillo · Englishئینگلیزی · 2.9M viewsبینین · 57K likesلایک · Partبەشی 42:20–47:06 (ofلە 4:22:09)

How a system of linear equations becomes A*x = b, and how Ab solves it in one step.

چۆن چەند پێکەوە بە شێوەی A*x = b دەنووسرێنەوە و چۆن A\b بە یەک هەنگاو چارەسەریان دەکات.

Watch 42:20-47:06: a system of three equations from Wikipedia written as A and b, solved first with inv(A)*b and then with Ab; both give 1, -2, -2.

لە ⁦42:20⁩ تا ⁦47:06⁩ سەیر بکە: سێ لە Wikipediaـەوە کە وەک A و b دەنووسرێن، سەرەتا بە inv(A)*b و پاشان بە A\b چارەسەر دەکرێن؛ هەردووکیان 1, -2, -2 دەدەن.

Mixed practiceڕاهێنانی تێکەڵ

The Kurdish guide in the course material practises all of these operations on small matrices. Here is the same kind of practice with new matrices. Work out each answer on paper first, then check in MATLAB.

ڕێبەرە کوردییەکەی ناو کەرەستەکانی وانەکە هەموو ئەم کارانە لەسەر بچووک ڕاهێنان پێ دەکات. ئەمە هەمان جۆری ڕاهێنانە بە نوێ. سەرەتا وەڵامی هەر یەکێک لەسەر کاغەز دەربهێنە، پاشان لە MATLABـدا بیپشکنە.

ExerciseڕاهێنانSix operations on two matricesشەش کار لەسەر دوو ماتریکس

Let C = [2 4; 6 8] and D = [1 3; 5 7]. Find C.*D, C*D, C/2, C.^2, C^2 and C./D.

با C = [2 4; 6 8] و D = [1 3; 5 7] بن. C.*D، C*D، C/2، C.^2، C^2 و C./D بدۆزەرەوە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
C = [2 4; 6 8];
D = [1 3; 5 7];
C.*D
C*D
C/2
C.^2
C^2
C./D
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

Element-wise: 2⋅12 \cdot 1, 4⋅34 \cdot 3, 6⋅56 \cdot 5, 8⋅78 \cdot 7. Matrix product: entry (1,1) is 2⋅1+4⋅5=222 \cdot 1 + 4 \cdot 5 = 22.

توخم بە توخم: 2⋅12 \cdot 1، 4⋅34 \cdot 3، 6⋅56 \cdot 5، 8⋅78 \cdot 7. لێکدانی : ژمارەی ⁦(1,1)⁩: 2⋅1+4⋅5=222 \cdot 1 + 4 \cdot 5 = 22.

Lineدێڕی 6-7

Each element squared, against C*C: entry (1,1) is 2⋅2+4⋅6=282 \cdot 2 + 4 \cdot 6 = 28.

هەر دووجا کراوە، بەرامبەر C*C: ژمارەی ⁦(1,1)⁩: 2⋅2+4⋅6=282 \cdot 2 + 4 \cdot 6 = 28.

Adding and deleting rows and columns, which the guide practises on the same pages, is in indexing.

زیادکردن و سڕینەوەی ڕیز و ستوون، کە ڕێبەرەکە لە هەمان پەڕەکاندا ڕاهێنانی پێ دەکات، لە ئیندێکسەکاندایە.

Common mistakesهەڵە باوەکان

MistakeهەڵەWhat happensچی ڕوودەداتFixچارەسەر
Forgetting the dot: x^2, x*y, x/y on two vectorsلەبیرچوونی خاڵ: x^2، x*y، x/y لەسەر دوو Errors — and x/y even gives one strange number with no error — x/y تەنانەت یەک ژمارەی سەیر بێ هیچ دەداتx.^2, x.*y, x./yx.^2، x.*y، x./y
Using .* when the maths needs a matrix productبەکارهێنانی .* کاتێک ماتماتیکەکە لێکدانی دەوێتA wrong answer with no error (for equal sizes)وەڵامێکی هەڵە بێ (بۆ قەبارەی یەکسان)Ask “row times column, or cell times cell?” before you type.پێش نووسین بپرسە: «ڕیز جارانی ستوون، یان خانە جارانی خانە؟»
Expecting A^2 to square each elementچاوەڕوانیی ئەوەی A^2 هەموو دووجا بکاتYou get A*AA*A وەردەگریتA.^2A.^2
Expecting A*B to equal B*Aچاوەڕوانیی ئەوەی A*B یەکسان بێت بە B*ADifferent answers, or an error for one orderوەڵامی جیاواز، یان بۆ یەکێک لە ڕیزبەندییەکانKeep the order of the maths.ڕیزبەندیی ماتماتیکەکە بپارێزە.
Adding arrays of different sizes: [1 2 3] + [4 5]کۆکردنەوەی قەبارە جیاواز: [1 2 3] + [4 5]“Arrays have incompatible sizes for this operation.”ئەم : «⁦Arrays have incompatible sizes for this operation⁩.»Same size, or a row with a column on purpose.هەمان قەبارە، یان بە ئەنقەست ڕیزێک لەگەڵ ستوونێک.
inv(A)*b to solve equationsinv(A)*b بۆ چارەسەرکردنی Works, but slower and less accurateکار دەکات، بەڵام هێواشتر و کەمتر وردA\bA\b
Copying >>> or capital names (Ans, Sum) from old screenshotsکۆپیکردنی >>> یان ناوی بە پیتی گەورە (Ans، Sum) لە وێنە کۆنەکان>>> is Python's prompt; capitals are different names>>> هی Pythonـە؛ پیتی گەورە ناوی جیاوازنMATLAB's prompt is >>; write ans, sum.لە MATLABـدا >>ـە؛ بنووسە ans، sum.

If you know Python: [1, 2] * 2 there repeats the list to [1, 2, 1, 2] instead of doubling the numbers (repeating a list). In MATLAB [1 2]*2 is [2 4].

ئەگەر Python دەزانیت: لەوێ [1, 2] * 2 لیستەکە دووبارە دەکاتەوە بۆ [1, 2, 1, 2] لە جیاتی دووجاکردنی ژمارەکان (دووبارەکردنەوەی لیست). لە MATLABـدا [1 2]*2 دەکاتە [2 4].

Practiceڕاهێنان

ExerciseڕاهێنانA tea-house billپسوولەی چایخانە

Dilan orders 2 teas, 1 coffee and 3 juices. Prices are 250, 750 and 1000 IQD. Store the quantities as a row q and the prices as a column p, and get the total with one multiplication.

دیلان 2 چا، 1 قاوە و 3 شەربەت داوا دەکات. نرخەکان ⁦250⁩، ⁦750⁩ و ⁦1000⁩ دینارن. بڕەکان وەک ڕیزی q و نرخەکان وەک ستوونی p هەڵبگرە و کۆی گشتی بە یەک لێکدان وەربگرە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
q = [2 1 3];
p = [250; 750; 1000];
total = q*p
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Row times column: 2⋅250+1⋅750+3⋅1000=42502 \cdot 250 + 1 \cdot 750 + 3 \cdot 1000 = 4250 IQD (a shopping bill in IQD).

ڕیز جارانی ستوون: 2⋅250+1⋅750+3⋅1000=42502 \cdot 250 + 1 \cdot 750 + 3 \cdot 1000 = 4250 دینار (پسوولەی کڕین بە دینار).

ExerciseڕاهێنانSpot the mistakeهەڵەکە بدۆزەرەوە

Soran wants y=x2+3xy = x^2 + 3x for x=0,1,2,3,4x = 0, 1, 2, 3, 4 and types x = 0:4; y = x^2 + 3*x. What goes wrong, and what is the fix?

سۆران y=x2+3xy = x^2 + 3xـی دەوێت بۆ x=0,1,2,3,4x = 0, 1, 2, 3, 4 و دەنووسێت x = 0:4; y = x^2 + 3*x. چی هەڵە دەبێت و چارەسەرەکە چییە؟

Show answerوەڵامەکە پیشان بدە

x^2 asks for the matrix power of a 1×51 \times 5 row, which is not square: an error. 3*x is fine (a number times a vector).

x^2 داوای ڕیزێکی 1×51 \times 5 دەکات کە چوارگۆشەیی نییە: . 3*x باشە (ژمارەیەک جارانی ).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
x = 0:4;
y = x.^2 + 3*x
ExerciseڕاهێنانPredict the size — or the errorقەبارەکە پێشبینی بکە — یان هەڵەکە

Predict the size of each result, or say that it is an error: (a) ones(2,3)*ones(3,4) (b) ones(2,3).*ones(2,3) (c) ones(2,3)*ones(2,3) (d) ones(3,1).*ones(1,4) (e) ones(1,5)*ones(5,1)

قەبارەی هەر ئەنجامێک پێشبینی بکە، یان بڵێ : (أ) ones(2,3)*ones(3,4) (ب) ones(2,3).*ones(2,3) (ج) ones(2,3)*ones(2,3) (د) ones(3,1).*ones(1,4) (هـ) ones(1,5)*ones(5,1)

Show answerوەڵامەکە پیشان بدە
  • (a) 2×42 \times 4 — inner sizes 3 and 3 agree.
  • (b) 2×32 \times 3 — same size, element by element.
  • (c) An error — inner sizes 3 and 2 differ.
  • (d) 3×43 \times 4 — a column with a row: compatible sizes.
  • (e) 1×11 \times 1 — the number 5 (row times column).
  • (أ) 2×42 \times 4 — قەبارە ناوەکییەکان 3 و 3 یەک دەگرنەوە.
  • (ب) 2×32 \times 3 — هەمان قەبارە، توخم بە توخم.
  • (ج) — قەبارە ناوەکییەکان 3 و 2 جیاوازن.
  • (د) 3×43 \times 4 — ستوونێک لەگەڵ ڕیزێک: قەبارەی گونجاو.
  • (هـ) 1×11 \times 1 — ژمارە 5 (ڕیز جارانی ستوون).
ExerciseڕاهێنانSolve with backslashبە \ چارەسەری بکە

Solve 2x+y=72x + y = 7 and x−y=−1x - y = -1 with \ and check the answer.

2x+y=72x + y = 7 و x−y=−1x - y = -1 بە \ چارەسەر بکە و وەڵامەکە بپشکنە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
A = [2 1; 1 -1];
b = [7; -1];
x = A\b
A*x
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Putting the answer back gives b again: x=2, y=3x = 2,\ y = 3 is right.

دانانەوەی وەڵامەکە b دەگەڕێنێتەوە: x=2, y=3x = 2,\ y = 3 ڕاستە.

ExerciseڕاهێنانWhen ^ and .^ agreeکەی ^ و .^ یەک دەگرنەوە

For N = [2 0; 0 3], compare N^2 and N.^2. Why are they equal here, but not for most matrices?

بۆ N = [2 0; 0 3]، N^2 و N.^2 بەراورد بکە. بۆچی لێرەدا یەکسانن، بەڵام بۆ زۆربەی نا؟

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
N = [2 0; 0 3];
N^2
N.^2

N is a diagonal matrix: in each row × column product only one pair is not zero, so the matrix power squares the diagonal entries too. As soon as a matrix has nonzero entries off the diagonal, the two answers differ.

N تیرەییە: لە هەر لێکدانێکی ڕیز × ستووندا تەنها یەک جووت سفر نییە، بۆیە ژمارەکانی سەر تیرەکە دووجا دەکات. هەر کە ژمارەی ناسفری لە دەرەوەی تیرەکە هەبێت، دوو وەڵامەکە جیاواز دەبن.

Summaryپوختە

  • + and - work element by element on arrays of the same size; a single number goes to every element.
  • A*B is matrix multiplication: columns of A = rows of B; the result is rows(A) × columns(B); in general A*B is not equal to B*A; a row times a column is one number.
  • .*, ./, .\ , .^ pair up the elements; the sizes must be the same or compatible (a row with a column gives a table).
  • A^2 = A*A (square A only); A.^2 squares each element. Formulas on vectors need the dots: x.^2.
  • x = A\b solves Ax=bAx = b; prefer it to inv(A)*b.
  • + و - توخم بە توخم لەسەر هەمان قەبارە کار دەکەن؛ تەنها یەک ژمارە دەچێتە سەر هەموو .
  • A*B لێکدانی : ستوونەکانی A = ڕیزەکانی B؛ ئەنجامەکە ڕیزەکانی A × ستوونەکانی Bـیە؛ بە گشتی A*B یەکسان نییە بە B*A؛ ڕیز جارانی ستوون یەک ژمارەیە.
  • .*، ./، .\ ، .^ جووت دەکەن؛ قەبارەکان دەبێت یەکسان یان گونجاو بن (ڕیزێک لەگەڵ ستوونێک خشتەیەک دەدات).
  • A^2 = A*A (تەنها Aـی چوارگۆشەیی)؛ A.^2 هەر دووجا دەکات. لەسەر پێویستیان بە خاڵەکانە: x.^2.
  • x = A\b Ax=bAx = b چارەسەر دەکات؛ لە inv(A)*b باشترە.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between A*B and A.*B?جیاوازیی نێوان A*B و A.*B چییە؟

A*B multiplies rows by columns (linear algebra); A.*B multiplies elements in the same place.

A*B ڕیزەکان لە ستوونەکان دەدات ()؛ A.*B هەمان شوێن لێک دەدات.

Why does x^2 fail for x = 1:5?بۆچی x^2 بۆ x = 1:5 سەرناکەوێت؟

^ is the matrix power and needs a square matrix; use x.^2.

^ و پێویستی بە هەیە؛ x.^2 بەکار بهێنە.

Which sizes can be combined element by element?کام قەبارانە دەتوانن توخم بە توخم تێکەڵ بکرێن؟

Equal sizes, or sizes where each dimension is equal or 1 (a scalar, or a row with a column).

قەبارەی یەکسان، یان قەبارەیەک کە هەر ڕەهەندێکی یەکسان یان 1 بێت (، یان ڕیزێک لەگەڵ ستوونێک).

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

Working with Matrices in MatlabChristopher Lum · Englishئینگلیزی · 146K viewsبینین · 2.3K likesلایک · Partبەشی 6:59–13:08 (ofلە 31:02)

Matrices in MATLAB with clear examples: typing a matrix, matrix versus element-wise multiplication, submatrices, transpose, joining, zeros/ones/eye/rand, linspace and size.

لە MATLABـدا بە نموونە: نووسینی ، لێکدانی بەرامبەر ، بەشێک لە ، ، ، zeros/ones/eye/rand، linspace و size.

Watch 6:59-13:08: AB as matrix multiplication (inner sizes must match), then . ./ and .^ for element-by-element work: time times speed gives distance, distance ./ time gives speed back.

لە ⁦6:59⁩ تا ⁦13:08⁩ سەیر بکە: A*B وەک لێکدانی (قەبارە ناوەکییەکان دەبێت وەک یەک بن)، پاشان .*، ./ و .^ بۆ : لێکدانی کات و خێرایی دووری دەدات و دووری بە کات (بە ./) خێرایی دەداتەوە.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Script Files, input, disp and fprintfفایلەکانی دەسنووس، input، disp و fprintf

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.