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

Vectors and Rangesئاڕاستەبڕەکان و زنجیرەکان

Store a list of numbers under one name: row and column vectors in square brackets, equally spaced ranges with the colon m:q:n (which include the end, unlike Python's range), linspace for a fixed number of points, elements written as expressions, the transpose ' from row to column, and a step mistake to spot.

لیستێکی ژمارە لەژێر یەک ناودا هەڵبگرە: ڕیز و ستوون لەناو کەوانەی چوارگۆشەدا، زنجیرەی بە هەنگاوی یەکسان بە دوو خاڵ m:q:n (کە بە پێچەوانەی rangeـی Python سەری کۆتایی دەگرێتەوە)، linspace بۆ ژمارەیەکی دیاریکراو خاڵ، کە وەک دەنووسرێن، ' لە ڕیزەوە بۆ ستوون، هەروەها هەڵەیەکی هەنگاو کە دەبێت بیدۆزیتەوە.

12 min read13 خولەک خوێندنەوە · 12 stepsهەنگاو

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

  • Create row vectors and column vectors with square brackets, spaces, commas and semicolons.
  • Build equally spaced vectors with m:q:n and predict their elements, including ranges that stop short or are empty.
  • Use linspace for a fixed number of points and explain when it is safer than the colon.
  • Write elements as expressions and read a common scale factor such as 1.0e+03 *.
  • Turn a row into a column with ' and find a wrong step in a range.
  • ڕیز و ستوون بە کەوانەی چوارگۆشە، ، کۆما و دروست بکەیت.
  • بە هەنگاوی یەکسان بە m:q:n دروست بکەیت و پێشبینی بکەیت، زنجیرەی کورتهاتوو و بەتاڵیشەوە.
  • linspace بۆ ژمارەیەکی دیاریکراو خاڵ بەکار بهێنیت و ڕوونی بکەیتەوە کەی لە دوو خاڵ سەلامەتترە.
  • وەک بنووسیت و هۆکاری پێوانەی هاوبەشی وەک 1.0e+03 * بخوێنیتەوە.
  • بە ' ڕیز بکەیت بە ستوون و هەنگاوێکی هەڵە لە زنجیرەیەکدا بدۆزیتەوە.

Why vectors?بۆچی ئاڕاستەبڕەکان؟

Seven temperatures for a week in Erbil, the marks of a class, the prices in a shop: real data comes in lists. Giving each number its own variable (t1, t2, …) would be slow and clumsy. A keeps the whole list under one name. In MATLAB a vector is simply an with one row or one column — a 1×n1 \times n or n×1n \times 1 (see linear algebra and matrices; the calculus lesson vectors and matrices shows row and column vectors at work in a shopping bill).

حەوت پلەی گەرمیی هەفتەیەک لە هەولێر، نمرەکانی پۆلێک، نرخەکانی دووکانێک: ڕاستەقینە وەک لیست دێن. دانانی جیا بۆ هەر ژمارەیەک (t1، t2، …) هێواش و ناڕێکە. هەموو لیستەکە لەژێر یەک ناودا هەڵدەگرێت. لە MATLABـدا تەنها بە یەک ڕیز یان یەک ستوون — 1×n1 \times n یان n×1n \times 1 (بڕوانە جەبری هێڵی و ماتریکسەکان؛ وانەی کالکولەسی ئاڕاستەبڕەکان و ماتریکسەکان ڕیز و ستوون لە پسوولەیەکی کڕیندا پیشان دەدات).

The spice shelfڕەفەی بەهارات

Think of a shelf in a spice shop in the bazaar. The shelf has one name, and the jars stand on it in order: first, second, third… A vector is that shelf: one name, many values in a fixed order.

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

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

On a real shelf the jars can be very different. In a numeric vector every element is a number of the same type, and you will learn to reach one jar by its position in the lesson on indexing.

لەسەر ڕەفەیەکی ڕاستەقینە دەفرەکان دەکرێت زۆر جیاواز بن. لە ژمارەییدا هەموو ژمارەیەکی هەمان جۆرە و لە وانەی ئیندێکسەکان فێر دەبیت چۆن بە شوێنەکەی بگەیتە یەک دەفر.

Quick checkپشکنینی خێراWhat is a vector in MATLAB? لە MATLABـدا چییە؟

Row vectors and column vectorsئاڕاستەبڕەکانی ڕیز و ستوون

Type the elements inside square brackets [ ]. Separate them with spaces or commas to get a row vector. Separate them with semicolons — or press Enter after each element — to get a column vector. All the vector commands of this lesson work the same in GNU Octave and in the free version of MATLAB Online.

لەناو کەوانەی چوارگۆشە [ ]ـدا بنووسە. بە یان کۆما لێکیان جیا بکەرەوە بۆ وەرگرتنی ڕیز. بە لێکیان جیا بکەرەوە — یان دوای هەر Enter دابگرە — بۆ وەرگرتنی ستوون. هەموو لەم وانەیەدا لە ⁦GNU Octave⁩ و وەشانی بێبەرانبەری ⁦MATLAB Online⁩ـیشدا بە هەمان شێوە کار دەکەن.

Four vectors (new data)چوار ئاڕاستەبڕ (بە دراوەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
temps = [21 24 19 27 30 28 25]
marks = [78; 85; 62; 91]
point = [3, -1, 4]
heights = [152
167
171]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

A week of temperatures in °C: a row, separated by spaces.

پلەی گەرمیی هەفتەیەک بە °C: ڕیزێک، بە جیاکراوەتەوە.

Lineدێڕی 2

Four marks: semicolons make a column.

چوار نمرە: ستوونێک دروست دەکەن.

Lineدێڕی 3

The coordinates of a point: commas also make a row.

پێکهاتەکانی خاڵێک: کۆماش ڕیز دروست دەکات.

Lineدێڕی 4-6

Pressing Enter after each element also makes a column; MATLAB waits for the closing ].

داگرتنی Enter دوای هەر ستوونیش دروست دەکات؛ MATLAB چاوەڕێی ]ـی داخستن دەکات.

Quick checkپشکنینی خێراWhat does v = [5; 7; 9] create?v = [5; 7; 9] چی دروست دەکات؟

Equal steps with the colon: m:q:nهەنگاوی یەکسان بە دوو خاڵ: m:q:n

Many vectors go up or down in equal steps: 2, 5, 8, 11 … MATLAB builds them with the colon operator m:q:n:

زۆر بە هەنگاوی یەکسان بەرز یان نزم دەبنەوە: 2، 5، 8، ⁦11⁩ … MATLAB بە دوو خاڵ m:q:n دروستیان دەکات:

  • m is the first element;
  • q is the step (the spacing) — it may be negative or a fraction, and if you leave it out, it is 1;
  • n is the limit: the last element is the last value that does not pass n.
  • m یەکەم ؛
  • q هەنگاوەکەیە (دووریی نێوان دوو ) — دەکرێت سالب یان بێت و ئەگەر نەینووسیت، 1ـە؛
  • n سنوورەکەیە: دوایین دوایین کە لە n تێناپەڕێت.
A number line from 0 to 13 showing 1:3:12. Dots stand at 1, 4, 7 and 10, joined by arrows labelled +3. The first dot is labelled m = 1, the step q = 3, and a mark at 12 is labelled n = 12; the next step, 13, would pass n, so 10 is the last element.هێڵێکی ژمارەکان لە 0 تا 13 کە 1:3:12 پیشان دەدات. خاڵەکان لەسەر 1، 4، 7 و 10ن و بە تیری +3 بەیەکەوە بەستراون. یەکەم خاڵ m = 1ـە، هەنگاوەکە q = 3ـە و نیشانەیەک لەسەر 12 n = 12ـە؛ هەنگاوی دواتر، 13، لە n تێدەپەڕێت، بۆیە 10 دوایین توخمە.
The parts of m:q:n, shown with 1:3:12بەشەکانی m:q:n، بە 1:3:12 پیشان دراوەCêIT
Five ranges (new numbers)پێنج زنجیرە (بە ژمارەی نوێ)MATLABType in a terminalلە تێرمیناڵدا بینووسە
x = 2:3:20
y = 0.5:0.25:1.5
z = -4:3
w = 30:-5:5
k = 3:-0.5:1
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

From 2 in steps of 3; 20 is reached exactly.

لە 2ـەوە بە هەنگاوی 3؛ ⁦20⁩ ڕێک دەگیرێت.

Lineدێڕی 2

The step can be a fraction.

هەنگاوەکە دەکرێت بێت.

Lineدێڕی 3

No step written, so the step is 1.

هەنگاو نەنووسراوە، بۆیە هەنگاوەکە 1ـە.

Lineدێڕی 4-5

A negative step counts down. You may also write brackets, [30:-5:5]; they change nothing.

هەنگاوی سالب بەرەو خوار دەژمێرێت. دەتوانیت کەوانەش بنووسیت، [30:-5:5]؛ هیچ ناگۆڕن.

If you know Python: range(1, 10) there stops before 10, but 1:10 in MATLAB includes 10 (Python's range). Ranges can also fill the rows of a matrix, as in [1:4; 5:8] — that comes in the lesson on creating matrices.

ئەگەر Python دەزانیت: range(1, 10) لەوێ پێش ⁦10⁩ دەوەستێت، بەڵام 1:10 لە MATLABـدا ⁦10⁩ دەگرێتەوە (rangeـی Python). زنجیرەکان دەتوانن ڕیزەکانی پڕ بکەنەوە، وەک [1:4; 5:8] — ئەوە لە وانەی دروستکردنی ماتریکسەکان دێت.

Quick checkپشکنینی خێراWhat does 10:-2:3 give?10:-2:3 چی دەدات؟

Equal steps with the colon: m:q:nهەنگاوی یەکسان بە دوو خاڵ: m:q:n

Ranges that stop short, and empty rangesزنجیرەی کورتهاتوو و زنجیرەی بەتاڵ

The limit n is not always an element. 1:3:12 gives 1 4 7 10, because the next step, 13, would pass 12. And if the step goes the wrong way, there is nothing to list: 5:1 and 1:-1:5 are empty (no elements at all).

سنووری n هەمیشە نییە. 1:3:12 ئەمانە دەدات: ⁦1 4 7 10⁩، چونکە هەنگاوی دواتر، ⁦13⁩، لە ⁦12⁩ تێدەپەڕێت. هەروەها ئەگەر هەنگاوەکە بە ئاڕاستەی هەڵەدا بڕوات، هیچ شتێک نییە بۆ لیستکردن: 5:1 و 1:-1:5 بەتاڵن (هیچ نییە).

MATLABType in a terminalلە تێرمیناڵدا بینووسە
u = 1:3:12
e = 5:1
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

MATLAB reports an empty row vector (size 1×01 \times 0). Octave shows it as e = [](1x0).

MATLAB ڕیزی بەتاڵ ڕادەگەیەنێت (قەبارەی 1×01 \times 0). Octave وەک e = [](1x0) پیشانی دەدات.

You can count the elements before you type: a range m:q:n has

دەتوانیت پێش نووسین بژمێریت: زنجیرەی m:q:n ئەم ژمارەیە هەیە:

⌊n−mq⌋+1\left\lfloor \frac{n - m}{q} \right\rfloor + 1

For 1:3:12: ⌊11/3⌋+1=3+1=4\lfloor 11/3 \rfloor + 1 = 3 + 1 = 4 elements. (⌊x⌋\lfloor x \rfloor is the floor function: round down.) MATLAB can also count them for you: numel(1:3:12) gives 4 (measuring arrays).

بۆ 1:3:12: ⌊11/3⌋+1=3+1=4\lfloor 11/3 \rfloor + 1 = 3 + 1 = 4 . (⌊x⌋\lfloor x \rfloor .) MATLAB خۆی دەتوانێت بیانژمێرێت: numel(1:3:12) دەکاتە 4 (پێوانەکردنی ڕیزەکەکان).

Quick checkپشکنینی خێراHow many elements does 0:4:30 have?0:4:30 چەند هەیە؟

MATLAB Crash Course for BeginnersfreeCodeCamp.org · Englishئینگلیزی · 1.7M viewsبینین · 37K likesلایک · Partبەشی 24:06–24:50 (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 24:06-24:50: 1:2:10 counts 1 3 5 7 9 and stops at 9, because the next step would pass 10.

لە ⁦24:06⁩ تا ⁦24:50⁩ سەیر بکە: 1:2:10 دەژمێرێت 1 3 5 7 9 و لە 9 دەوەستێت، چونکە هەنگاوی دواتر لە ⁦10⁩ تێدەپەڕێت.

A fixed number of points: linspaceژمارەیەکی دیاریکراو خاڵ: linspace

linspace(a, b, n) makes a row vector of exactly n equally spaced points from a to b. Both ends are always included, and the spacing is b−an−1\frac{b - a}{n - 1}. Without n you get 100 points.

linspace(a, b, n) ڕیز دروست دەکات بە ڕێک n خاڵ بە دووریی یەکسان لە a تا b. هەردوو سەرەکە هەمیشە دەگیرێنەوە و دووریی نێوان دوو خاڵ b−an−1\frac{b - a}{n - 1}ـە. بێ n، ⁦100⁩ خاڵ وەردەگریت.

Colon or linspace?دوو خاڵ یان linspace؟MATLABType in a terminalلە تێرمیناڵدا بینووسە
linspace(0, 1, 5)
p = 0:0.5:2
q = linspace(0, 2, 5)
r = linspace(0, 2, 4)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Five points from 0 to 1: the spacing is (1−0)/4=0.25(1 - 0)/4 = 0.25.

پێنج خاڵ لە 0 تا 1: دووریی نێوانیان (1−0)/4=0.25(1 - 0)/4 = 0.25ـە.

Lineدێڕی 2-3

The same five values two ways: with the colon you choose the step, with linspace you choose how many points.

هەمان پێنج بە دوو ڕێگە: بە دوو خاڵ هەنگاوەکە هەڵدەبژێریت، بە linspace چەند خاڵ.

Lineدێڕی 4

Four points force a step of 2/32/3, which you would not want to type yourself. An exact 0 is shown as 0 without decimals.

چوار خاڵ هەنگاوی 2/32/3 دەسەپێنن، کە ناتەوێت خۆت بینووسیت. سفری ڕێک وەک 0 بێ ژمارەی دوای پیشان دەدرێت.

Three number lines from 0 to 2. The first shows 0:0.5:2 with five dots; the second shows linspace(0,2,5) with the same five dots; the third shows linspace(0,2,4) with four dots at 0, 0.6667, 1.3333 and 2.سێ هێڵی ژمارەکان لە 0 تا 2. یەکەم 0:0.5:2 بە پێنج خاڵ پیشان دەدات؛ دووەم linspace(0,2,5) بە هەمان پێنج خاڵ؛ سێیەم linspace(0,2,4) بە چوار خاڵ لەسەر 0، 0.6667، 1.3333 و 2.
Choose the step (colon) or the number of points (linspace)هەنگاو هەڵبژێرە (دوو خاڵ) یان ژمارەی خاڵەکان ⁦(linspace)⁩CêIT
Quick checkپشکنینی خێراYou need exactly 50 points between 0 and 2π2\pi for a graph. What do you write?بۆ ڕێک ⁦50⁩ خاڵت لە نێوان 0 و 2π2\pi پێویستە. چی دەنووسیت؟

Working with Matrices in MatlabChristopher Lum · Englishئینگلیزی · 146K viewsبینین · 2.3K likesلایک · Partبەشی 25:01–27:29 (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 25:01-27:29: 3:0.25:6 with a step, then linspace(3,6,5) and linspace(3,6,15): you give the number of points and MATLAB finds the spacing.

لە ⁦25:01⁩ تا ⁦27:29⁩ سەیر بکە: 3:0.25:6 بە هەنگاو، پاشان linspace(3,6,5) و linspace(3,6,15): تۆ ژمارەی خاڵەکان دەدەیت و MATLAB دووریی نێوانیان دەدۆزێتەوە.

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

An element does not have to be a plain number: any or is allowed. The course's problem sheet asks for vectors like the two below (here with new numbers), and the answers in the course use exactly this style.

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

ExerciseڕاهێنانA row vector of mixed elementsئاڕاستەبڕی ڕیز بە توخمی تێکەڵ

Create a row vector with the elements 9, 154\frac{15}{4}, 6×2.56 \times 2.5, 44, tan⁡70∘\tan 70^\circ, 38\sqrt{38} and 0.35.

ڕیز دروست بکە کە بریتی بن لە: 9، 154\frac{15}{4}، 6×2.56 \times 2.5، ⁦44⁩، tan⁡70∘\tan 70^\circ، 38\sqrt{38} و ⁦0.35⁩.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
a = [9 15/4 6*2.5 44 tand(70) sqrt(38) 0.35]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

tand because the angle is in degrees; sqrt for the root. Once one element has decimals, MATLAB shows all of them with four decimals.

tand چونکە گۆشەکە بە ؛ sqrt بۆ ڕەگەکە. هەر کە یەک ژمارەی دوای هەبێت، MATLAB هەموویان بە چوار ژمارەی دوای پیشان دەدات.

ExerciseڕاهێنانLarge and small togetherگەورە و بچووک پێکەوە

Create a row vector with 12×103\sqrt{12} \times 10^3, 3010−52\frac{30}{10 - 5^2}, ln⁡400.53\frac{\ln 40}{0.5^3}, sin⁡50∘cos⁡75∘\frac{\sin 50^\circ}{\cos 75^\circ}, 145 and cos⁡2π12\cos^2\frac{\pi}{12}.

ڕیز دروست بکە بەمانە: 12×103\sqrt{12} \times 10^3، 3010−52\frac{30}{10 - 5^2}، ln⁡400.53\frac{\ln 40}{0.5^3}، sin⁡50∘cos⁡75∘\frac{\sin 50^\circ}{\cos 75^\circ}، ⁦145⁩ و cos⁡2π12\cos^2\frac{\pi}{12}.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
c = cos(pi/12);
b = [sqrt(12)*10^3, 30/(10-5^2), log(40)/0.5^3, sind(50)/cosd(75), 145, c^2]
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

As in the course's own answer, the cosine is first stored in a helper variable, then squared inside the vector.

وەک وەڵامی ناو وانەکە، سەرەتا لە یارمەتیدەردا هەڵدەگیرێت، پاشان لەناو بەرز دەکرێتەوە بۆ دوو.

Lineدێڕی 2

10-5^2 needs its brackets in the denominator; log is ln⁡\ln; sind/cosd because the angles are in degrees.

10-5^2 لە خوارەوەی پێویستی بە کەوانەکەیەتی؛ log واتە ln⁡\ln؛ sind/cosd چونکە گۆشەکان بە .

Read the output carefully. 1.0e+03 * is a common scale factor: every number below it must be multiplied by 1000. So the elements are 3464.1, −2-2, 29.511, 2.9598, 145 and 0.93301 — but the small ones lose digits in this view (0.0009×10000.0009 \times 1000 hides 0.93301). Type format shortG to see each element with five significant digits, and format default to go back (display formats).

بە وردی بخوێنەوە. 1.0e+03 * هۆکارێکی پێوانەی هاوبەشە: هەموو ژمارەیەکی خوارەوەی دەبێت لە ⁦1000⁩ بدرێت. کەواتە بریتین لە ⁦3464.1⁩، −2-2، ⁦29.511⁩، ⁦2.9598⁩، ⁦145⁩ و ⁦0.93301⁩ — بەڵام بچووکەکان لەم پیشاندانەدا ژمارە لەدەست دەدەن (0.0009×10000.0009 \times 1000 ژمارەی ⁦0.93301⁩ دەشارێتەوە). format shortG بنووسە بۆ بینینی هەر بە پێنج ژمارەی گرنگ؛ format default بۆ گەڕانەوەیە (شێوەکانی پیشاندان).

Quick checkپشکنینی خێراAbove a vector MATLAB shows 1.0e+03 * and then 0.1450. What is the real value of that element?لە سەرووی MATLAB 1.0e+03 * پیشان دەدات و پاشان 0.1450. ڕاستەقینەی ئەو چییە؟

From row to column: 'لە ڕیزەوە بۆ ستوون: '

A single quote ' after a vector turns a row into a column (and a column into a row). This is the in its simplest form. It is handy when a long column is easier to build as a row first — for example from a range.

کۆتەیشنێکی تاک ' لە دوای ڕیز دەکات بە ستوون (و ستوون بە ڕیز). ئەمە ساکارترین شێوەی . بەسوودە کاتێک ستوونێکی درێژ ئاسانترە سەرەتا وەک ڕیز دروست بکرێت — بۆ نموونە لە زنجیرەیەکەوە.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
temps = [21 24 19 27 30 28 25];
temps'
col = (1:3)'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Put a range in round brackets before the ': 1:3' would transpose only the 3.

زنجیرەکە بخە ناو کەوانەی بازنەییەوە پێش ': 1:3' تەنها 3 دەگۆڕێت.

The full transpose of matrices, and why complex numbers need .' instead of ', come in the lesson on creating matrices. Reaching single elements, and a vector that grows when you assign past its end (v(5) = 7), come in the lesson on indexing.

جێگۆڕکێی ماتریکس بۆ هەموو ماتریکسێک، هەروەها ئەوەی بۆچی ژمارە ئاوێتەکان لە جیاتی ' پێویستیان بە .'ـە، لە وانەی دروستکردنی دێن. گەیشتن بە تاکە ، هەروەها کە گەورە دەبێت کاتێک لە دوای کۆتاییەکەی دادەنێیت (v(5) = 7)، لە وانەی ئیندێکسەکان دێن.

Quick checkپشکنینی خێراHow do you get the column 4, 8, 12, 16 with one short command?چۆن ستوونی 4، 8، ⁦12⁩، ⁦16⁩ بە یەک کورت وەردەگریت؟

Spot the mistakeهەڵەکە بدۆزەرەوە

A problem from the course: make a column vector whose first element is 26, which decreases in steps of 3.6, and whose last element is −10-10 (hint: make a row and transpose it). Here is an answer that was handed in. Read it and look for the mistake before you scroll on.

پرسیارێک لە وانەکە: ستوون دروست بکە کە یەکەم ⁦26⁩ بێت، بە هەنگاوی ⁦3.6⁩ کەم ببێتەوە و دوایین −10-10 بێت (ڕێنمایی: ڕیزێک دروست بکە و بکە). ئەمە وەڵامێکە کە پێشکەش کراوە. بیخوێنەوە و پێش ئەوەی بچیتە خوارەوە بە دوای هەڵەکەدا بگەڕێ.

The answer as handed inوەڵامەکە وەک خۆیMATLABType in a terminalلە تێرمیناڵدا بینووسە
format bank
a=[26:-3:-10;];
a'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

format bank only shows two decimals; it does not change any value.

format bank تەنها دوو ژمارەی دوای پیشان دەدات؛ هیچ ناگۆڕێت.

Lineدێڕی 2

The mistake: the step is -3, not -3.6. The ; before ] and the square brackets are harmless but unnecessary.

هەڵەکە: هەنگاوەکە -3ـە، نەک -3.6. ;ـی پێش ] و کەوانە چوارگۆشەکان زیانیان نییە، بەڵام پێویست نین.

Animation on a number line from −12 to 28: the dots of 26:-3.6:-10 appear one group at a time, eleven dots landing exactly on −10. Then the dots of 26:-3:-10 appear on a second row in another colour, thirteen dots. Same ends, different step.
Animation on a number line from −12 to 28: the dots of 26:-3.6:-10 appear one group at a time, eleven dots landing exactly on −10. Then the dots of 26:-3:-10 appear on a second row in another colour, thirteen dots. Same ends, different step.
Same ends, different step: 11 elements or 13هەمان سەرەکان، هەنگاوی جیاواز: ⁦11⁩ یان ⁦13⁩CêIT

With the right step, the column has 11 elements: −10−26−3.6+1=10+1=11\frac{-10 - 26}{-3.6} + 1 = 10 + 1 = 11. The answer above has −10−26−3+1=13\frac{-10 - 26}{-3} + 1 = 13 — same first and last element, but every value in between is wrong.

بە هەنگاوە ڕاستەکە، ستوونەکە ⁦11⁩ هەیە: −10−26−3.6+1=10+1=11\frac{-10 - 26}{-3.6} + 1 = 10 + 1 = 11. وەڵامەکەی سەرەوە −10−26−3+1=13\frac{-10 - 26}{-3} + 1 = 13ـی هەیە — هەمان یەکەم و دوایین ، بەڵام هەموو لە نێوانیاندا هەڵەیە.

The corrected answerوەڵامە ڕاستکراوەکەMATLABType in a terminalلە تێرمیناڵدا بینووسە
format default
a = (26:-3.6:-10)'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The range in round brackets, then '. It lands exactly on −10-10: (−10−26)/(−3.6)=10(-10 - 26)/(-3.6) = 10 steps.

زنجیرەکە لەناو کەوانەی بازنەییدا، پاشان '. ڕێک لەسەر −10-10 دەوەستێت: (−10−26)/(−3.6)=10(-10 - 26)/(-3.6) = 10 هەنگاو.

Quick checkپشکنینی خێراWhy did the handed-in answer give 13 elements instead of 11?بۆچی وەڵامە پێشکەشکراوەکە لە جیاتی ⁦11⁩، ⁦13⁩ دا؟

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

MistakeهەڵەWhat happensچی ڕوودەداتFixچارەسەر
Expecting 1:10 to stop at 9, as Python's range(1, 10) doesچاوەڕوانیی ئەوەی 1:10 لە 9 بوەستێت، وەک range(1, 10)ـی Python10 is included⁦10⁩ دەگیرێتەوەWrite 1:9 if you want to stop at 9.ئەگەر دەتەوێت لە 9 بوەستێت 1:9 بنووسە.
A negative step when the first value is smaller than the last: 1:-1:5هەنگاوی سالب کاتێک یەکەم بچووکترە لە دوایین: 1:-1:5An empty vector بەتاڵCount down from the bigger number: 5:-1:1.لە ژمارە گەورەکەوە بەرەو خوار بژمێرە: 5:-1:1.
Commas where semicolons were meant: [1, 2, 3] for a columnکۆما لە جیاتی : [1, 2, 3] بۆ ستوونA row, not a columnڕیز، نەک ستوون[1; 2; 3] or [1 2 3]'[1; 2; 3] یان [1 2 3]'
A space before a minus sign: [1 -2] vs [1 - 2] پێش نیشانەی کەم: [1 -2] بەرامبەر [1 - 2][1 -2] has two elements (1 and −2-2); [1 - 2] has one (−1-1)[1 -2] دوو هەیە (⁦1⁩ و −2-2)؛ [1 - 2] یەکێکی هەیە (−1-1)Use commas between elements when signs are involved: [1, -2].کاتێک نیشانە هەن، کۆما لە نێوان بەکار بهێنە: [1, -2].
Expecting the limit to be reached: 1:3:12چاوەڕوانیی گەیشتن بە سنوورەکە: 1:3:12It stops at 10لە ⁦10⁩ دەوەستێتCheck the count: ⌊(n−m)/q⌋+1\lfloor (n - m)/q \rfloor + 1.ژمارەکە بپشکنە: ⌊(n−m)/q⌋+1\lfloor (n - m)/q \rfloor + 1.
A fractional step where the end matters: 0:0.1:1هەنگاوی کاتێک سەری کۆتایی گرنگە: 0:0.1:1Round-off may decide whether the end is includedلەوانەیە بڕیار بدات سەری کۆتایی دەگیرێتەوە یان ناlinspace(0, 1, 11) or (0:10)/10linspace(0, 1, 11) یان (0:10)/10
1:3' for a column1:3' بۆ ستوونOnly the 3 is transposed: the result is still the row 1 2 3تەنها 3 دەگۆڕدرێت: ئەنجامەکە هەر ڕیزی ⁦1 2 3⁩ـە(1:3)'(1:3)'

Practiceڕاهێنان

ExerciseڕاهێنانShop pricesنرخەکانی دووکان

Lana writes down the price of bread in five bakeries in Duhok: 1000, 1250, 750, 1000 and 1500 IQD. Store them in a row vector, then in a column vector.

لانا نرخی نان لە پێنج نانەواخانەی دهۆک دەنووسێت: ⁦1000⁩، ⁦1250⁩، ⁦750⁩، ⁦1000⁩ و ⁦1500⁩ دینار. لە ڕیزدا هەڵیانبگرە، پاشان لە ستووندا.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
bread = [1000 1250 750 1000 1500];
bread_col = [1000; 1250; 750; 1000; 1500];

Spaces (or commas) give a row; semicolons give a column. bread' would also give the column.

(یان کۆما) ڕیز دەدات؛ ستوون دەدەن. bread'ـیش ستوونەکە دەدات.

ExerciseڕاهێنانPredict the rangesزنجیرەکان پێشبینی بکە

Write down the elements of each range and how many there are, then check in MATLAB: 5:4:30, 100:-15:0, 7:2.

هەر زنجیرەیەک و ژمارەیان بنووسە، پاشان لە MATLAB بیپشکنە: 5:4:30، 100:-15:0، 7:2.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
5:4:30
100:-15:0
7:2
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

7 elements: 33 would pass 30.

7 : ⁦33⁩ لە ⁦30⁩ تێدەپەڕێت.

Lineدێڕی 2

7 elements: the next value, −5-5, would pass 0.

7 : دواتر، −5-5، لە 0 تێدەپەڕێت.

Lineدێڕی 3

Empty: with step 1 you cannot go from 7 down to 2.

بەتاڵ: بە هەنگاوی 1 ناتوانیت لە 7ـەوە بۆ 2 دابەزیت.

ExerciseڕاهێنانSix pointsشەش خاڵ

Make six equally spaced points from 1 to 2 in two ways: with linspace and with the colon.

شەش خاڵی بە دووریی یەکسان لە 1 تا 2 بە دوو ڕێگە دروست بکە: بە linspace و بە دوو خاڵ.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
linspace(1, 2, 6)
1:0.2:2
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

Six points mean five gaps, so the step is (2−1)/5=0.2(2 - 1)/5 = 0.2. linspace is the safer choice because it always includes both ends.

شەش خاڵ واتە پێنج بۆشایی، بۆیە هەنگاوەکە (2−1)/5=0.2(2 - 1)/5 = 0.2ـە. linspace هەڵبژاردنی سەلامەتترە چونکە هەمیشە هەردوو سەرەکە دەگرێتەوە.

ExerciseڕاهێنانA falling columnستوونێکی دابەزیو

Make a column vector whose first element is 40, which decreases in steps of 4.5, and whose last element is 4. How many elements does it have?

ستوون دروست بکە کە یەکەم ⁦40⁩ بێت، بە هەنگاوی ⁦4.5⁩ کەم ببێتەوە و دوایین 4 بێت. چەند هەیە؟

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
v = (40:-4.5:4)'
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

(4−40)/(−4.5)+1=8+1=9(4 - 40)/(-4.5) + 1 = 8 + 1 = 9 elements. The step must be negative because the values fall.

(4−40)/(−4.5)+1=8+1=9(4 - 40)/(-4.5) + 1 = 8 + 1 = 9 . هەنگاوەکە دەبێت سالب بێت چونکە دادەبەزن.

ExerciseڕاهێنانExplain the outputدەرخستەکە ڕوون بکەرەوە

MATLAB shows 1.0e+03 * and then 2.5000 0.0040 0.0310 for a vector w. Write the three real values. Which command shows them without the common factor?

MATLAB بۆ بە ناوی w، 1.0e+03 * و پاشان 2.5000 0.0040 0.0310 پیشان دەدات. سێ ڕاستەقینەکە بنووسە. کام بێ هۆکارە هاوبەشەکە پیشانیان دەدات؟

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

2500, 4 and 31 (each number times 1000). format shortG (or format longG) shows each element on its own scale; format default goes back.

⁦2500⁩، 4 و ⁦31⁩ (هەر ژمارەیەک جارانی ⁦1000⁩). format shortG (یان format longG) هەر بە پێوانەی خۆی پیشان دەدات؛ format default دەیگەڕێنێتەوە.

Summaryپوختە

  • A vector is a 1×n1 \times n (row) or n×1n \times 1 (column) array: one name for a list of numbers.
  • Row: [a b c] or [a, b, c]. Column: [a; b; c] or Enter between elements, or a row followed by '.
  • m:q:n starts at m, steps by q (default 1) and stops at the last value that does not pass n — unlike Python's range, n itself is included when it is reached. A step in the wrong direction gives an empty vector.
  • linspace(a, b, n): exactly n points, both ends included (100 by default). Prefer it for fractional steps.
  • Elements can be expressions and function calls; 1.0e+03 * above a vector is a common scale factor.
  • The worked “spot the mistake”: 26:-3:-10 (13 elements) is not 26:-3.6:-10 (11 elements).
  • 1×n1 \times n (ڕیز) یان n×1n \times 1 (ستوون)ـە: یەک ناو بۆ لیستێکی ژمارە.
  • ڕیز: [a b c] یان [a, b, c]. ستوون: [a; b; c] یان Enter لە نێوان ، یان ڕیزێک و پاشان '.
  • m:q:n لە m دەست پێدەکات، بە q هەنگاو دەنێت (بنەڕەتی ⁦1⁩) و لە دوایین دەوەستێت کە لە n تێناپەڕێت — بە پێچەوانەی rangeـی Python، n خۆی دەگیرێتەوە کاتێک پێی دەگات. هەنگاو بە ئاڕاستەی هەڵەدا بەتاڵ دەدات.
  • linspace(a, b, n): ڕێک n خاڵ، هەردوو سەرەکە دەگیرێنەوە (بە شێوەی بنەڕەتی ⁦100⁩). بۆ هەنگاوی ئەوە باشترە.
  • دەتوانن و بن؛ 1.0e+03 * لە سەرووی هۆکارێکی پێوانەی هاوبەشە.
  • «هەڵەکە بدۆزەرەوە»: 26:-3:-10 (⁦13⁩ ) وەک 26:-3.6:-10 (⁦11⁩ ) نییە.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between [2 4 6] and [2; 4; 6]?جیاوازیی نێوان [2 4 6] و [2; 4; 6] چییە؟

The first is a row vector (1×31 \times 3), the second a column vector (3×13 \times 1).

یەکەمیان ڕیزە (1×31 \times 3)، دووەمیان ستوون (3×13 \times 1).

When do you use linspace instead of the colon?کەی linspace لە جیاتی دوو خاڵ بەکار دەهێنیت؟

When you know how many points you need, or when the step is a fraction and both ends must be included.

کاتێک دەزانیت چەند خاڵت پێویستە، یان کاتێک هەنگاوەکە کەرتە و دەبێت هەردوو سەرەکە بگیرێنەوە.

Why is 5:1 empty?بۆچی 5:1 بەتاڵە؟

The default step is +1, and you cannot go up from 5 to 1. Write 5:-1:1 to count down.

هەنگاوی بنەڕەتی ⁦+1⁩ـە و ناتوانیت لە 5ـەوە بەرەو سەرەوە بگەیتە 1. بۆ ژماردن بەرەو خوار بنووسە 5:-1:1.

Videoڤیدیۆ

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

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

MATLAB Crash Course for BeginnersfreeCodeCamp.org · Englishئینگلیزی · 1.7M viewsبینین · 37K likesلایک · Partبەشی 14:15–18:43 (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 14:15-18:43: x = 1:10, the transpose ' that turns a row into a column, linspace with 2 or 3 arguments (100 points by default) and vectors typed in [ ] with spaces or commas.

لە ⁦14:15⁩ تا ⁦18:43⁩ سەیر بکە: x = 1:10، بە ' کە ڕیز دەکات بە ستوون، linspace بە 2 یان 3 (بە شێوەی بنەڕەتی ⁦100⁩ خاڵ) و کە لەناو [ ] بە یان کۆما دەنووسرێن.

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

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

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

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

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

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

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