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

Creating Matricesدروستکردنی ماتریکسەکان

Type matrices row by row with spaces and semicolons, use expressions and ranges as elements and rows, join matrices side by side or one under another, build ready-made matrices with zeros, ones, eye, rand and randi, and transpose them with ' (and .' for complex numbers).

ڕیز بە ڕیز بە و بنووسە، و زنجیرە وەک و ڕیز بەکار بهێنە، لە تەنیشت یەک یان لە ژێر یەک پێکەوە بلکێنە، ئامادەکراو بە zeros، ones، eye، rand و randi دروست بکە و بە ' بکە (بە .' بۆ ).

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

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

  • Type a matrix row by row and explain why every row needs the same number of elements.
  • Use expressions, variables and ranges inside a matrix.
  • Join matrices with [A B] and [A; B] and predict when a join fails.
  • Build matrices with zeros, ones, eye, rand and randi.
  • Transpose a matrix with ' and choose .' for complex data.
  • ڕیز بە ڕیز بنووسیت و ڕوونی بکەیتەوە بۆچی هەموو ڕیزێک پێویستی بە هەمان ژمارە هەیە.
  • ، و زنجیرە لەناو بەکار بهێنیت.
  • بە ⁦[A B]⁩ و ⁦[A; B]⁩ پێکەوە بلکێنیت و پێشبینی بکەیت کەی سەرناکەوێت.
  • بە zeros، ones، eye، rand و randi دروست بکەیت.
  • بە ' بکەیت و بۆ ئاوێتە .' هەڵبژێریت.

A matrix: a table of numbersماتریکس: خشتەیەکی ژمارە

A is a table of numbers arranged in rows (across) and columns (down). Its size is written rows × columns, rows first: a matrix with 3 rows and 4 columns is a 3×43 \times 4 matrix. Matrices hold table-like data — the marks of a class, a shop's sales for each day, the pixels of a photo — and they are the main tool of , which science and engineering use everywhere. In MATLAB a matrix is simply a two-dimensional .

خشتەیەکی ژمارەیە کە لە ڕیز (بە ئاسۆیی) و ستوون (لە سەرەوە بۆ خوارەوە) ڕێکخراوە. قەبارەکەی بەم شێوەیە دەنووسرێت: ڕیز × ستوون، ڕیز یەکەم: بە 3 ڕیز و 4 ستوون 3×43 \times 4ـە. خشتەیی هەڵدەگرن — نمرەکانی پۆلێک، فرۆشی ڕۆژانەی دووکانێک، وێنەیەک — و ئامرازی سەرەکیی کە زانست و ئەندازیاری لە هەموو شوێنێک بەکاری دەهێنن. لە MATLABـدا تەنها دووڕەهەندە.

[518274936][6013294117151]\begin{bmatrix} 5 & 1 & 8 \\ 2 & 7 & 4 \\ 9 & 3 & 6 \end{bmatrix} \qquad \begin{bmatrix} 6 & 0 & 13 & 2 & 9 \\ 4 & 11 & 7 & 15 & 1 \end{bmatrix}

Left: a (3×33 \times 3: as many rows as columns). Right: a 2×52 \times 5 matrix — the number of rows and the number of columns can differ.

چەپ: (3×33 \times 3: ژمارەی ڕیز و ستوون یەکسانە). ڕاست: 2×52 \times 5 — ژمارەی ڕیز و ژمارەی ستوون دەتوانن جیاواز بن.

Quick checkپشکنینی خێراA matrix has 2 rows and 5 columns. How do you write its size? 2 ڕیز و 5 ستوونی هەیە. قەبارەکەی چۆن دەنووسیت؟

A matrix: a table of numbersماتریکس: خشتەیەکی ژمارە

Like an egg trayوەک کارتۆنی هێلکە

An egg trayکارتۆنی هێلکە

An egg tray at the bazaar has rows and columns of places, and every row has the same number of places. You name a tray by its shape — “5 by 6” — and you find an egg by its row and its column. A matrix is that tray filled with numbers.

کارتۆنێکی هێلکە لە بازاڕ ڕیز و ستوونی شوێنی هەیە و هەموو ڕیزێک هەمان ژمارە شوێنی هەیە. کارتۆنەکە بە شێوەکەی ناو دەبەیت — «5 لە 6» — و هێلکەیەک بە ڕیز و ستوونەکەی دەدۆزیتەوە. ئەو کارتۆنەیە کە بە ژمارە پڕ کراوە.

Where the analogy stops workingسنووری ئەم نموونەیە

A tray can have an empty place. A matrix cannot: every place holds a number (MATLAB uses NaN when a value is missing).

کارتۆن دەتوانێت شوێنی بەتاڵی هەبێت. ناتوانێت: هەموو شوێنێک ژمارەیەک هەڵدەگرێت (MATLAB بۆ ونبوو NaN بەکار دەهێنێت).

The maths of matrices — the names of the entries, the special matrices, the operations — is taught in the maths lessons: linear algebra and matrices, types of matrices and matrix notation and special matrices. This lesson shows how to type and build matrices in MATLAB.

ماتماتیکی — ناوی ژمارەکانی ناوی، ، ئەو کارانەی لەسەریان دەکرێن — لە وانەکانی ماتماتیکدا دەگوترێتەوە: جەبری هێڵی و ماتریکسەکان، جۆرەکانی ماتریکس و نیشانەکردن و ماتریکسە تایبەتەکان. ئەم وانەیە پیشان دەدات چۆن لە MATLABـدا بنووسیت و دروست بکەیت.

Quick checkپشکنینی خێراAn egg tray can have an empty place. What does a MATLAB matrix use for a value that is missing?کارتۆنی هێلکە دەتوانێت شوێنی بەتاڵی هەبێت. لە MATLABـدا چی بۆ بەکار دەهێنێت کە ونبووە؟

Typing a matrixنووسینی ماتریکسێک

Type a matrix the way you read it, row by row, inside square brackets [ ]. Separate the elements of a row with spaces or commas. End each row with a semicolon ; — or press Enter — to start the next row. This is the same idea as row and column vectors (vectors), now with several rows.

بەو شێوەیە بنووسە کە دەیخوێنیتەوە، ڕیز بە ڕیز، لەناو کەوانەی چوارگۆشە [ ]ـدا. ڕیزێک بە یان کۆما لێک جیا بکەرەوە. کۆتایی هەر ڕیزێک بە ; بهێنە — یان Enter دابگرە — بۆ دەستپێکردنی ڕیزی دواتر. ئەمە هەمان بیرۆکەی ڕیز و ستوونە (ئاڕاستەبڕەکان)، ئێستا بە چەند ڕیزێک.

The command M = [5 1 8; 2 7 4; 9 3 6] with arrows to a 3 × 3 grid. The spaces between 5, 1 and 8 move to the next column; each semicolon starts a new row, so 5 1 8 is row 1, 2 7 4 is row 2 and 9 3 6 is row 3.فەرمانی M = [5 1 8; 2 7 4; 9 3 6] بە تیر بۆ تۆڕێکی 3 × 3. بۆشاییەکان نێوان 5، 1 و 8 دەچنە ستوونی دواتر؛ هەر خاڵبۆرێک ڕیزێکی نوێ دەست پێدەکات، بۆیە 5 1 8 ڕیزی 1ـە، 2 7 4 ڕیزی 2 و 9 3 6 ڕیزی 3.
How MATLAB reads your typing: a space moves right, ; starts a new rowMATLAB چۆن نووسینەکەت دەخوێنێتەوە: دەچێتە ڕاست، ; ڕیزێکی نوێ دەست پێدەکاتCêIT
Two matrices (new data)دوو ماتریکس (بە دراوەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
sales = [42 18 25 30; 37 22 19 28; 51 26 33 35]
r = [6 0 13 2 9
     4 11 7 15 1]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Karwan's tea house in Sulaymaniyah: glasses of tea, coffee, juice and water sold on three days. Three rows (days), four columns (drinks): a 3×43 \times 4 matrix.

چایخانەی کاروان لە سلێمانی: پەرداخی چا، قاوە، شەربەت و ئاو کە لە سێ ڕۆژدا فرۆشراون. سێ ڕیز (ڕۆژەکان)، چوار ستوون (خواردنەوەکان): 3×43 \times 4.

Lineدێڕی 2-3

Pressing Enter instead of ; also starts a new row. MATLAB waits for the closing ]; the extra spaces at the start of line 3 only make it easier to read.

داگرتنی Enter لە جیاتی ; ـیش ڕیزێکی نوێ دەست پێدەکات. MATLAB چاوەڕێی ]ـی داخستن دەکات؛ زیادەی سەرەتای دێڕی 3 تەنها خوێندنەوەکەی ئاسانتر دەکەن.

Quick checkپشکنینی خێراWhat does [1 2 3; 4 5 6] create?[1 2 3; 4 5 6] چی دروست دەکات؟

Working with Matrices in MatlabChristopher Lum · Englishئینگلیزی · 146K viewsبینین · 2.3K likesلایک · Partبەشی 2:40–6:58 (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 2:40-6:58: [ ] starts a matrix, spaces or commas separate columns, ; or Enter starts a new row; the Workspace and Variable Editor show each size.

لە ⁦2:40⁩ تا ⁦6:58⁩ سەیر بکە: [ ] دەست پێدەکات، یان کۆما ستوونەکان جیا دەکەنەوە، ; یان Enter ڕیزێکی نوێ دەست پێدەکات؛ و ⁦Variable Editor⁩ قەبارەی هەر یەکێکیان پیشان دەدەن.

Typing a matrixنووسینی ماتریکسێک

Every row must have the same lengthهەموو ڕیزێک دەبێت هەمان درێژیی هەبێت

A matrix is a rectangle, so every row must have the same number of elements. If one row is shorter, MATLAB does not guess the missing number: it stops with a red saying that the dimensions of the arrays being joined are not consistent. (Typing ; really stacks one row under another — joining is explained below.)

لاکێشەیە، بۆیە هەموو ڕیزێک دەبێت هەمان ژمارە هەبێت. ئەگەر ڕیزێک کورتتر بێت، MATLAB ژمارە ونبووەکە پێشبینی ناکات: بە سوور دەوەستێت کە دەڵێت لە کاتی ڕەهەندەکان یەک ناگرنەوە. (نووسینی ; لە ڕاستیدا ڕیزێک دەخاتە ژێر ڕیزێکی ترەوە — لە خوارەوە ڕوون دەکرێتەوە.)

MATLABType in a terminalلە تێرمیناڵدا بینووسە
bad = [3 8 1; 6 2]
good = [3 8 1; 6 2 NaN]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Row 1 has three elements, row 2 only two: MATLAB stops with an error and bad is not created.

ڕیزی 1 سێ هەیە، ڕیزی 2 تەنها دوو: MATLAB بە دەوەستێت و bad دروست ناکرێت.

Lineدێڕی 2

Fill every place. If a measurement is really missing, NaN (“not a number”, see special values) keeps the shape.

هەموو شوێنێک پڕ بکەرەوە. ئەگەر پێوانەیەک بەڕاستی ونبووە، NaN («ژمارە نییە»، بڕوانە نرخەکان تایبەتەکان) شێوەکە دەپارێزێت.

Quick checkپشکنینی خێراWhich command gives an error?کام دەدات؟

Elements can be expressionsتوخمەکان دەتوانن دەربڕین بن

As in a vector (elements can be expressions), each element of a matrix can be any : a number, a , a calculation or a . MATLAB works out every element first, then builds the matrix.

وەک (توخمەکان دەتوانن دەربڕین بن)، هەر دەتوانێت هەر بێت: ژمارەیەک، ، هەژمارێک یان . MATLAB سەرەتا هەموو هەژمار دەکات، پاشان دروست دەکات.

Variables, sums and functions inside a matrix (new values)گۆڕاوەکان، هەژمار و کردارەکان لەناو ماتریکسێک (بە نرخی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
h = 2; k = 8; r = 5;
E = [h, r*k, sin(pi/6); r^2, sqrt(r*k/h), 11]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Three variables on one line; the semicolons hide their echo.

سێ لە یەک دێڕدا؛ پیشاندانیان دەشارنەوە.

Lineدێڕی 2

A 2×32 \times 3 matrix: r*k = 40, sin(pi/6) = 0.5, r^2 = 25, sqrt(40/2) = 4.4721. Because one element has decimals, MATLAB shows all of them with four decimals.

2×32 \times 3: r*k = ⁦40⁩، sin(pi/6) = ⁦0.5⁩، r^2 = ⁦25⁩، sqrt(40/2) = ⁦4.4721⁩. چونکە یەک ژمارەی دوای هەیە، MATLAB هەموویان بە چوار ژمارەی دوای پیشان دەدات.

Quick checkپشکنینی خێراAfter a = 3;, what is [a a^2; 2*a 1]?دوای a = 3;، [a a^2; 2*a 1] چییە؟

Elements can be expressionsتوخمەکان دەتوانن دەربڕین بن

Whole ranges as rowsزنجیرەی تەواو وەک ڕیز

A row can also be a whole range or a linspace vector (ranges, linspace). This is a fast way to build a table — as long as every range gives the same number of elements.

ڕیزێک دەتوانێت زنجیرەیەکی تەواو یان linspace بێت (زنجیرەکان، linspace). ئەمە ڕێگەیەکی خێرایە بۆ دروستکردنی خشتەیەک — بە مەرجێک هەموو زنجیرەیەک هەمان ژمارە بدات.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
T = [2:6; 20:-2.5:10; linspace(0, 1, 5)]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Three rows of five: 2 to 6 in steps of 1; 20 down to 10 in steps of −2.5-2.5; five points from 0 to 1. An exact 0 is shown without decimals.

سێ ڕیزی پێنجی: 2 تا 6 بە هەنگاوی 1؛ ⁦20⁩ بەرەو خوار تا ⁦10⁩ بە هەنگاوی −2.5-2.5؛ پێنج خاڵ لە 0 تا 1. سفری ڕێک بێ ژمارەی دوای پیشان دەدرێت.

Quick checkپشکنینی خێراWhy does [1:4; 1:5] give an error?بۆچی [1:4; 1:5] دەدات؟

Joining matrices: [A B] and [A; B]پێکەوەلکاندنی ماتریکسەکان: [A B] و [A; B]

Square brackets can also join whole matrices; this is called . The same two separators decide the direction:

کەوانەی چوارگۆشە دەتوانێت تەواویش پێکەوە بلکێنێت؛ ئەمە پێی دەگوترێت . هەمان دوو جیاکەرەوە ئاڕاستەکە دیاری دەکەن:

  • [A B] or [A, B] puts B to the right of A. Both need the same number of rows.
  • [A; B] puts B under A. Both need the same number of columns.
  • If the sizes do not fit, MATLAB stops with an about inconsistent dimensions — the result would not be a rectangle.
  • [A B] یان [A, B] B دەخاتە لای ڕاستی A. هەردووکیان پێویستیان بە هەمان ژمارەی ڕیز هەیە.
  • [A; B] B دەخاتە ژێر A. هەردووکیان پێویستیان بە هەمان ژمارەی ستوون هەیە.
  • ئەگەر قەبارەکان نەگونجێن، MATLAB بە دەربارەی ڕەهەندی ناڕێک دەوەستێت — ئەنجامەکە لاکێشە نابێت.
Three panels. [A B]: a 2 × 2 block A and a 2 × 3 block B side by side make a 2 × 5 matrix — same number of rows. [A; C]: the 2 × 2 block A with a 1 × 2 block C under it makes a 3 × 2 matrix — same number of columns. [A C] in red: a 2-row block next to a 1-row block leaves a gap, so MATLAB gives an error.سێ بەش. [A B]: پارچەی A بە قەبارەی 2 × 2 و پارچەی B بە قەبارەی 2 × 3 لە تەنیشت یەک ماتریکسێکی 2 × 5 دروست دەکەن — هەمان ژمارەی ڕیز. [A; C]: پارچەی A و پارچەی C بە قەبارەی 1 × 2 لە ژێریدا ماتریکسێکی 3 × 2 دروست دەکەن — هەمان ژمارەی ستوون. [A C] بە سوور: پارچەیەکی دوو ڕیزی لە تەنیشت پارچەیەکی یەک ڕیزی کەلێنێک بەجێ دەهێڵێت، بۆیە MATLAB هەڵەیەک دەدات.
Side by side needs equal rows; one under the other needs equal columnsلە تەنیشت یەک: ڕیزی یەکسان؛ لە ژێر یەک: ستوونی یەکسانCêIT
MATLABType in a terminalلە تێرمیناڵدا بینووسە
A = [1 2; 3 4];
B = [7 8 9; 5 6 0];
C = [0 10];
H = [A B]
V = [A; C]
W = [A C]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

A (2×22 \times 2) and B (2×32 \times 3) both have 2 rows, so they fit side by side: a 2×52 \times 5 matrix.

A (2×22 \times 2) و B (2×32 \times 3) هەردووکیان 2 ڕیزیان هەیە، بۆیە لە تەنیشت یەک جێ دەبنەوە: 2×52 \times 5.

Lineدێڕی 5

A and C both have 2 columns, so C fits underneath: a 3×23 \times 2 matrix.

A و C هەردووکیان 2 ستوونیان هەیە، بۆیە C لە ژێرەوە جێ دەبێتەوە: 3×23 \times 2.

Lineدێڕی 6

A has 2 rows, C only 1: they cannot stand side by side. MATLAB stops with an error and W is not created. [A; B] fails too (2 columns against 3).

A دوو ڕیزی هەیە، C تەنها یەک: ناتوانن لە تەنیشت یەک بوەستن. MATLAB بە دەوەستێت و W دروست ناکرێت. [A; B]ـیش سەرناکەوێت (⁦2⁩ ستوون بەرامبەر ⁦3⁩).

Quick checkپشکنینی خێراP is 3×23 \times 2 and Q is 3×43 \times 4. Which join works?P 3×23 \times 2ـە و Q 3×43 \times 4. کام کار دەکات؟

Working with Matrices in MatlabChristopher Lum · Englishئینگلیزی · 146K viewsبینین · 2.3K likesلایک · Partبەشی 19:11–21:56 (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 19:11-21:56: [row1; row2] stacks rows, [col1 col2] puts columns side by side: concatenation with the same square brackets.

لە ⁦19:11⁩ تا ⁦21:56⁩ سەیر بکە: [row1; row2] ڕیزەکان لە ژێر یەک دادەنێت، [col1 col2] ستوونەکان لە تەنیشت یەک دادەنێت: بە هەمان کەوانە چوارگۆشەکان.

Ready-made matrices: zeros, ones, eyeماتریکسە ئامادەکراوەکان: zeros، ones، eye

Typing every element is slow for a big matrix. MATLAB has that build common matrices from their size alone:

نووسینی هەموو بۆ گەورە هێواشە. MATLAB چەند هەیە کە تەنها لە قەبارەکەیانەوە دروست دەکەن:

CommandWhat you getچی وەردەگریت
zeros(m, n)an m×nm \times n matrix of 0s (a ) m×nm \times n پڕ لە 0 ()
ones(m, n)an m×nm \times n matrix of 1s m×nm \times n پڕ لە 1
eye(n)the n×nn \times n : 1s on the , 0s elsewhere (the name sounds like the letter I) بە قەبارەی n×nn \times n: 1 لەسەر و 0 لە شوێنەکانی تر (ناوەکە وەک پیتی I دەخوێنرێتەوە)
rand(m, n)an m×nm \times n matrix of between 0 and 1 (next screen) m×nm \times n پڕ لە لە نێوان 0 و 1 (شاشەی دواتر)
zeros(n)one number means a square n×nn \times n matrix — zeros(3) is 3×33 \times 3, not 1×31 \times 3یەک ژمارە واتە n×nn \times n — zeros(3) 3×33 \times 3ـە، نەک 1×31 \times 3
MATLABType in a terminalلە تێرمیناڵدا بینووسە
z = zeros(2,4)
w = ones(3,2)
I = eye(3)
zeros(3)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

Rows first, then columns, as always: zeros(2,4) has 2 rows and 4 columns. zeros(1,3) and ones(1,3) make row vectors.

وەک هەمیشە ڕیز یەکەمە، پاشان ستوون: zeros(2,4) 2 ڕیز و 4 ستوونی هەیە. zeros(1,3) و ones(1,3) ڕیز دروست دەکەن.

Lineدێڕی 3

The plays the part of 1 in matrix multiplication; its maths is in special matrices.

لە لێکدانی ڕۆڵی 1 دەبینێت؛ ماتماتیکەکەی لە ماتریکسە تایبەتەکاندایە.

Lineدێڕی 4

One gives a square matrix.

یەک دەدات.

A matrix of zeros is a good starting table: make it with the right size, then fill its places one by one (changing elements).

سفر خشتەیەکی دەستپێکی باشە: بە قەبارە دروستەکەی دروستی بکە، پاشان شوێنەکانی یەک بە یەک پڕ بکەرەوە (گۆڕینی توخمەکان).

Quick checkپشکنینی خێراWhat size is ones(4)?ones(4) چ قەبارەیەکی هەیە؟

Working with Matrices in MatlabChristopher Lum · Englishئینگلیزی · 146K viewsبینین · 2.3K likesلایک · Partبەشی 21:57–25:01 (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 21:57-25:01: zeros(4,6), ones, eye(5), diag([1 2 3 4 5]) and rand(3,4) with values between 0 and 1.

لە ⁦21:57⁩ تا ⁦25:01⁩ سەیر بکە: zeros(4,6)، ones، eye(5)، diag([1 2 3 4 5]) و rand(3,4) بە نێوان 0 و 1.

Ready-made matrices: zeros, ones, eyeماتریکسە ئامادەکراوەکان: zeros، ones، eye

Matrices of random numbersماتریکسی ژمارە هەڕەمەکییەکان

rand(m, n) fills an m×nm \times n matrix with drawn evenly from the interval (0,1)(0, 1): every value between 0 and 1 is equally likely, and 0 and 1 themselves never appear. Each call gives new numbers, which is useful for simulations, games and test data. For whole numbers use randi(imax, m, n): random integers from 1 to imax.

rand(m, n) m×nm \times n بە پڕ دەکاتەوە کە بە یەکسانی لە (0,1)(0, 1) هەڵدەبژێردرێن: هەموو لە نێوان 0 و 1 هەمان دەرفەتی هەیە و خودی 0 و 1 هەرگیز دەرناکەون. هەر بانگکردنێک ژمارەی نوێ دەدات، ئەمەش بۆ لاسایی‌کردنەوە، یاری و تاقیکردنەوە بەسوودە. بۆ randi(imax, m, n) بەکار بهێنە: لە 1 تا imax، بێ .

Random numbers (your numbers will be different)ژمارە هەڕەمەکییەکان (ژمارەکانی تۆ جیاواز دەبن)MATLABType in a terminalلە تێرمیناڵدا بینووسە
R = rand(2,3)
dice = randi(6, 1, 8)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

A 2×32 \times 3 matrix of random numbers between 0 and 1. rand(1,3) gives a row of three.

2×32 \times 3 لە لە نێوان 0 و 1. rand(1,3) ڕیزێکی سێیی دەدات.

Lineدێڕی 2

Eight throws of a dice: whole numbers from 1 to 6.

هەشت هەڵدانی زار: لە 1 تا 6.

Quick checkپشکنینی خێراWhich command gives a 3×33 \times 3 matrix of random numbers between 0 and 1?کام 3×33 \times 3 لە لە نێوان 0 و 1 دەدات؟

The transpose: 'جێگۆڕکێی ماتریکس: '

A single quote ' after a matrix gives its : row 1 becomes column 1, row 2 becomes column 2, and so on. An m×nm \times n matrix becomes n×mn \times m. You met ' on vectors (row to column); on a matrix it turns every row into a column. The maths is in the transpose — a transpose is a mirror across the , not a turn (a mirror, not a turn) — and its rules are in the transpose of sums and products.

کۆتەیشنێکی تاک ' لە دوای دەدات: ڕیزی 1 دەبێتە ستوونی 1، ڕیزی 2 دەبێتە ستوونی 2 و هتد. m×nm \times n دەبێتە n×mn \times m. پێشتر 'ـت لەسەر بینی (لە ڕیزەوە بۆ ستوون)؛ لەسەر هەموو ڕیزێک دەکات بە ستوون. ماتماتیکەکەی لە جێگۆڕکێی ماتریکسدایە — ئاوێنەیە بە درێژایی ، نەک سووڕانەوە (ئاوێنە، نەک سووڕانەوە) — و یاساکانی لە جێگۆڕکێی ماتریکس لە کۆ و لێکداندادان.

Animation: the 2 × 3 matrix A = [4 7 2; 9 1 6]. Row 1 (4 7 2) is highlighted, lifts and settles as column 1 of a new matrix; then row 2 (9 1 6) settles as column 2. The last frame shows A' = [4 9; 7 1; 2 6] with the sizes 2 × 3 and 3 × 2 labelled.
Animation: the 2 × 3 matrix A = [4 7 2; 9 1 6]. Row 1 (4 7 2) is highlighted, lifts and settles as column 1 of a new matrix; then row 2 (9 1 6) settles as column 2. The last frame shows A' = [4 9; 7 1; 2 6] with the sizes 2 × 3 and 3 × 2 labelled.
Each row becomes a column: 2×32 \times 3 turns into 3×23 \times 2هەر ڕیزێک دەبێتە ستوون: 2×32 \times 3 دەبێتە 3×23 \times 2CêIT
A 3×43 \times 4 matrix becomes 4×34 \times 3 (new numbers)ماتریکسێکی 3×43 \times 4 دەبێتە 4×34 \times 3 (بە ژمارەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
C = [3 10 7 1; 12 5 0 8; 4 9 6 2];
D = C'
col = [4 9 2]'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Row 1 of C (3 10 7 1) is now column 1 of D, and so on.

ڕیزی 1ی ⁦C (3 10 7 1)⁩ ئێستا ستوونی 1ی Dـیە و هتد.

Lineدێڕی 3

On a row vector the transpose gives a column vector.

لەسەر ڕیز، ستوون دەدات.

Quick checkپشکنینی خێراG is a 5×25 \times 2 matrix. What size is G'?G 5×25 \times 2ـە. G' چ قەبارەیەکی هەیە؟

The transpose: 'جێگۆڕکێی ماتریکس: '

' or .'? Complex numbers' یان .'؟ ژمارە ئاوێتەکان

For real numbers ' is the whole story. For it does one more thing: it also takes the of every element (x+iy→x−iyx + iy \to x - iy, see complex numbers). Its full name is the complex conjugate transpose. The plain transpose, which only swaps rows and columns, is written .' (dot, quote).

بۆ ' هەموو شتەکەیە. بۆ کارێکی تریش دەکات: هەموو وەردەگرێت (x+iy→x−iyx + iy \to x - iy، بڕوانە ژمارە ئاوێتەکان). ناوە تەواوەکەی بە ئینگلیزی ئەمەیە: complex conjugate transpose. ساکار، کە تەنها ڕیز و ستوون دەگۆڕێتەوە، بە .' (خاڵ، کۆتەیشن) دەنووسرێت.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
z = [1+2i, 3-1i];
z'
z.'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

': a column, and every imaginary part changed its sign.

': ستوونێک و هەموو بەشێکی خەیاڵی نیشانەکەی گۆڕا.

Lineدێڕی 3

.': the same column with the numbers unchanged.

.': هەمان ستوون و ژمارەکان نەگۆڕاون.

Quick checkپشکنینی خێراw = [2-5i 4]. What is the first element of w'?w = [2-5i 4]. یەکەم w' چییە؟

Vectors and numbers are matrices tooئاڕاستەبڕەکان و ژمارەکانیش ماتریکسن

For MATLAB a row vector is a 1×n1 \times n matrix, a column vector is an n×1n \times 1 matrix and a single number is a 1×11 \times 1 matrix (every value is an array). That is why the same brackets, ;, ' and joining rules work for all of them. To ask MATLAB for the size of any of them, use size (measuring arrays).

بۆ MATLAB ڕیز 1×n1 \times nـە، ستوون n×1n \times 1ـە و تەنها یەک ژمارە 1×11 \times 1ـە (هەموو نرخێک ڕیزەکێکە). لەبەر ئەوە هەمان کەوانە، ;، ' و یاساکانی بۆ هەموویان کار دەکەن. بۆ پرسیارکردن لە قەبارەی هەر یەکێکیان، size بەکار بهێنە (پێوانەکردنی ڕیزەکەکان).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
v = [5 8 1];
x = 7;
both = [v x]
stack = [v; 2 4 6]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

A 1×31 \times 3 vector and a 1×11 \times 1 number both have one row, so they join side by side.

1×31 \times 3 و ژمارەیەکی 1×11 \times 1 هەردووکیان یەک ڕیزیان هەیە، بۆیە لە تەنیشت یەک دەلکێن.

Lineدێڕی 4

A vector and a new row of the same length stack into a 2×32 \times 3 matrix.

و ڕیزێکی نوێی هەمان درێژی دەبنە 2×32 \times 3.

If you know Python: there a table is a list of lists, [[1, 2], [3, 4]] (a list of rows). Typed in MATLAB, [[1,2],[3,4]] only joins two rows side by side and gives the row 1 2 3 4 — write [1 2; 3 4] instead.

ئەگەر Python دەزانیت: لەوێ خشتە لیستێکە لە لیست، [[1, 2], [3, 4]] (لیستێک لە ڕیز). ئەگەر لە MATLABـدا بنووسرێت، [[1,2],[3,4]] تەنها دوو ڕیز لە تەنیشت یەک دەلکێنێت و ڕیزی 1 2 3 4 دەدات — لە جیاتی ئەوە بنووسە [1 2; 3 4].

Quick checkپشکنینی خێراWhat is the size of the number 7 for MATLAB?ژمارە 7 بۆ MATLAB چ قەبارەیەکی هەیە؟

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

MistakeهەڵەWhat happensچی ڕوودەداتFixچارەسەر
Rows of different lengths: [1 2 3; 4 5]ڕیزی جیاواز لە درێژیدا: [1 2 3; 4 5]An error; no matrix is made؛ هیچ دروست ناکرێتGive every row the same number of elements (use NaN for a missing value).هەمان ژمارە بدە بە هەموو ڕیزێک (بۆ ونبوو NaN بەکار بهێنە).
Joining blocks whose sizes do not fit: [A C] with 2 and 1 rows پارچەی ناگونجاو: [A C] بە 2 و 1 ڕیزAn error about inconsistent dimensions دەربارەی ڕەهەندی ناڕێکSide by side: equal rows. Stacked: equal columns.لە تەنیشت یەک: ڕیزی یەکسان. لە ژێر یەک: ستوونی یەکسان.
Expecting zeros(3) to be 1×31 \times 3چاوەڕوانیی ئەوەی zeros(3) 1×31 \times 3 بێتA 3×33 \times 3 matrix of zeros 3×33 \times 3 لە سفرzeros(1,3) for a row of threezeros(1,3) بۆ ڕیزێکی سێیی
Swapping the sizes: zeros(4,2) for “2 rows, 4 columns”گۆڕینەوەی قەبارەکان: zeros(4,2) بۆ «2 ڕیز، 4 ستوون»A 4×24 \times 2 matrix 4×24 \times 2Rows first: zeros(2,4).ڕیز یەکەمە: zeros(2,4).
Using ' on complex data when you only want to swap rows and columnsبەکارهێنانی ' لەسەر ئاوێتە کاتێک تەنها دەتەوێت ڕیز و ستوون بگۆڕیتەوەEvery imaginary part changes its signهەموو بەشێکی خەیاڵی نیشانەکەی دەگۆڕێتUse .'..' بەکار بهێنە.
Python-style rows: [[1,2],[3,4]]ڕیزی شێوەی Python: [[1,2],[3,4]]A single row 1 2 3 4, not a 2×22 \times 2 matrixیەک ڕیزی ⁦1 2 3 4⁩، نەک 2×22 \times 2[1 2; 3 4][1 2; 3 4]
Capital letters: Zeros(2), Eye(3)پیتی گەورە: Zeros(2)، Eye(3)An error: MATLAB is case-sensitive and knows only zeros, eye: MATLAB و تەنها zeros و eye دەناسێتWrite function names in lower case.ناوی بە پیتی بچووک بنووسە.

Practiceڕاهێنان

ExerciseڕاهێنانA marks tableخشتەی نمرە

Aram, Shilan and Dilan each have four marks: Aram 78, 85, 62, 90; Shilan 91, 74, 88, 69; Dilan 55, 80, 73, 95. Store them in a matrix marks with one row per student. What is its size?

ئارام، شیلان و دیلان هەر یەکەیان چوار نمرەیان هەیە: ئارام ⁦78⁩، ⁦85⁩، ⁦62⁩، ⁦90⁩؛ شیلان ⁦91⁩، ⁦74⁩، ⁦88⁩، ⁦69⁩؛ دیلان ⁦55⁩، ⁦80⁩، ⁦73⁩، ⁦95⁩. لە بە ناوی marksـدا هەڵیانبگرە، هەر قوتابییەک یەک ڕیز. قەبارەکەی چەندە؟

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
marks = [78 85 62 90; 91 74 88 69; 55 80 73 95]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Three students (rows) × four subjects (columns): a 3×43 \times 4 matrix.

سێ قوتابی (ڕیز) × چوار وانە (ستوون): 3×43 \times 4.

ExerciseڕاهێنانA table from rangesخشتەیەک لە زنجیرەکان

Build a 3×53 \times 5 matrix X in one command: row 1 is 1 to 5, row 2 the even numbers 2 to 10, row 3 counts down from 100 in steps of 20.

3×53 \times 5 بە ناوی X بە یەک دروست بکە: ڕیزی 1 لە 1 تا 5، ڕیزی 2 ژمارە جووتەکانی 2 تا ⁦10⁩، ڕیزی 3 لە ⁦100⁩ـەوە بە هەنگاوی ⁦20⁩ بەرەو خوار دەژمێرێت.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
X = [1:5; 2:2:10; 100:-20:20]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Each range has five elements, so the rows fit.

هەر زنجیرەیەک پێنج هەیە، بۆیە ڕیزەکان دەگونجێن.

ExerciseڕاهێنانJoin the blocksپارچەکان پێکەوە بلکێنە

Without typing every element, build J, a 2×52 \times 5 matrix whose first two columns are ones and last three columns are zeros, and K, the 2×22 \times 2 with the row 7 7 under it.

بێ نووسینی هەموو ، J دروست بکە، 2×52 \times 5 کە دوو ستوونی یەکەمی یەک بن و سێ ستوونی کۆتایی سفر، هەروەها K، بە قەبارەی 2×22 \times 2 و ڕیزی 7 7 لە ژێریدا.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
J = [ones(2) zeros(2,3)]
K = [eye(2); 7 7]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

2×22 \times 2 next to 2×32 \times 3: both have 2 rows.

2×22 \times 2 لە تەنیشت 2×32 \times 3: هەردووکیان 2 ڕیزیان هەیە.

Lineدێڕی 2

2×22 \times 2 over 1×21 \times 2: both have 2 columns.

2×22 \times 2 لە سەر 1×21 \times 2: هەردووکیان 2 ستوونیان هەیە.

ExerciseڕاهێنانPredict the sizesقەبارەکان پێشبینی بکە

Write the size of each result, or say that it gives an error: (a) zeros(2,5)' (b) [eye(3) ones(3,1)] (c) [ones(1,4); zeros(2,4)] (d) [eye(2); ones(2,3)].

قەبارەی هەر ئەنجامێک بنووسە، یان بڵێ دەدات: (أ) zeros(2,5)' (ب) [eye(3) ones(3,1)] (ج) [ones(1,4); zeros(2,4)] (د) [eye(2); ones(2,3)].

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

(a) 5×25 \times 2 — the transpose of a 2×52 \times 5. (b) 3×43 \times 4 — 3 rows each, 3+13 + 1 columns. (c) 3×43 \times 4 — 4 columns each, 1+21 + 2 rows. (d) An error: stacking needs equal columns, and 2≠32 \ne 3.

(أ) 5×25 \times 2 — 2×52 \times 5. (ب) 3×43 \times 4 — هەر یەکەیان 3 ڕیز، 3+13 + 1 ستوون. (ج) 3×43 \times 4 — هەر یەکەیان 4 ستوون، 1+21 + 2 ڕیز. (د) : خستنە ژێر یەک ستوونی یەکسانی پێویستە و 2≠32 \ne 3.

ExerciseڕاهێنانTranspose by handجێگۆڕکێی ماتریکس بە دەست

Write the transpose of [60381592]\begin{bmatrix} 6 & 0 & 3 & 8 \\ 1 & 5 & 9 & 2 \end{bmatrix} on paper, then check with ' in MATLAB.

[60381592]\begin{bmatrix} 6 & 0 & 3 & 8 \\ 1 & 5 & 9 & 2 \end{bmatrix} لەسەر کاغەز بنووسە، پاشان لە MATLABـدا بە ' بیپشکنە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
[6 0 3 8; 1 5 9 2]'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

2×42 \times 4 becomes 4×24 \times 2: row 1 (6 0 3 8) is now column 1.

2×42 \times 4 دەبێتە 4×24 \times 2: ڕیزی ⁦1 (6 0 3 8)⁩ ئێستا ستوونی 1ـە.

ExerciseڕاهێنانFix the commandsفەرمانەکان چاک بکەرەوە

Each line stops with an error. Find the mistake and correct it: T = [1 2 3; 4 5], Z = Zeros(2,3), U = [ones(2,2) zeros(3,2)].

هەر دێڕێک بە دەوەستێت. هەڵەکە بدۆزەرەوە و ڕاستی بکەرەوە: T = [1 2 3; 4 5]، Z = Zeros(2,3)، U = [ones(2,2) zeros(3,2)].

Show answerوەڵامەکە پیشان بدە
  • T: row 2 is short — e.g. T = [1 2 3; 4 5 6].
  • Z: lower case — Z = zeros(2,3).
  • U: 2 rows next to 3 rows — make the rows equal, e.g. U = [ones(2,2) zeros(2,2)], or stack them: [ones(2,2); zeros(3,2)] (both have 2 columns).
  • T: ڕیزی 2 کورتە — بۆ نموونە T = [1 2 3; 4 5 6].
  • Z: پیتی بچووک — Z = zeros(2,3).
  • U: 2 ڕیز لە تەنیشت 3 ڕیز — ڕیزەکان یەکسان بکە، بۆ نموونە U = [ones(2,2) zeros(2,2)]، یان بیانخە ژێر یەک: [ones(2,2); zeros(3,2)] (هەردووکیان 2 ستوونیان هەیە).

Summaryپوختە

  • A matrix is a table of numbers; its size is rows × columns (rows first).
  • Type it row by row in [ ]: spaces or commas between elements, ; or Enter between rows. Every row must have the same length.
  • Elements may be expressions, variables and function calls; rows may be ranges of equal length.
  • [A B] joins side by side (equal rows); [A; B] stacks (equal columns).
  • zeros(m,n), ones(m,n), eye(n), rand(m,n), randi(imax,m,n); one argument means a square matrix.
  • ' transposes (m×n→n×mm \times n \to n \times m) and also conjugates complex numbers; .' only transposes.
  • خشتەیەکی ژمارەیە؛ قەبارەکەی ڕیز × ستوونە (ڕیز یەکەم).
  • ڕیز بە ڕیز لەناو [ ] بینووسە: یان کۆما لە نێوان ، ; یان Enter لە نێوان ڕیزەکان. هەموو ڕیزێک دەبێت هەمان درێژیی هەبێت.
  • دەتوانن ، و بن؛ ڕیزەکان دەتوانن زنجیرەی هاودرێژ بن.
  • [A B] لە تەنیشت یەک دەلکێنێت (ڕیزی یەکسان)؛ [A; B] دەیانخاتە ژێر یەک (ستوونی یەکسان).
  • zeros(m,n)، ones(m,n)، eye(n)، rand(m,n)، randi(imax,m,n)؛ یەک واتە .
  • ' دەکات (m×n→n×mm \times n \to n \times m) و بۆ وەردەگرێت؛ .' تەنها دەکات.
Review questionsپرسیارەکانی پێداچوونەوە
How do you type a 2×32 \times 3 matrix with the rows 1 2 3 and 4 5 6?چۆن ماتریکسێکی 2×32 \times 3 بە ڕیزەکانی ⁦1 2 3⁩ و ⁦4 5 6⁩ دەنووسیت؟

[1 2 3; 4 5 6] (or with commas, or with Enter between the rows).

[1 2 3; 4 5 6] (یان بە کۆما، یان بە Enter لە نێوان ڕیزەکاندا).

When does [A; B] work?[A; B] کەی کار دەکات؟

When A and B have the same number of columns.

کاتێک A و B هەمان ژمارەی ستوونیان هەبێت.

What is the difference between ' and .'?جیاوازیی نێوان ' و .' چییە؟

Both swap rows and columns. ' also replaces every complex number by its conjugate; for real numbers they give the same result.

هەردووکیان ڕیز و ستوون دەگۆڕنەوە. ' هەروەها هەموو بە دەگۆڕێت؛ بۆ هەمان ئەنجام دەدەن.

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

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

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

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

Indexing, the Colon, Adding and Deleting Elementsئیندێکسەکان، دوو خاڵ، زیادکردن و سڕینەوەی توخمەکان

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

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