MATLABMATLAB · Chapterبەش 3 · Lectureوانە 3.2

MATLAB as a Calculator: Operators, Variables and FormatsMATLAB وەک حاسیبە: کارپێکەرەکان، گۆڕاوەکان و شێوەکانی پیشاندان

Use the Command Window as a calculator: the six arithmetic operators, the order of precedence and its traps (8^1/3, -2^2, 2^3^2), long commands, variables and their names, special values such as pi, eps, Inf and NaN, display formats, data types and round-off, and the commands that manage your session.

⁦Command Window⁩ وەک بەکار بهێنە: شەش ، و تەڵەکانی (8^1/3، -2^2، 2^3^2)، درێژ، و ناوەکانیان، ناوە تایبەتەکانی وەک pi، eps، Inf و NaN، شێوەکانی پیشاندان، و ، هەروەها بەڕێوەبردنی دانیشتن.

21 min read23 خولەک خوێندنەوە · 21 stepsهەنگاو

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

  • Calculate with + - * / \ ^ and explain left division.
  • Predict results using MATLAB's order of precedence, including the power and unary-minus traps.
  • Create variables with valid names, and show or hide results with commas and semicolons.
  • Choose a display format and explain that it never changes the stored value.
  • Name MATLAB's main data types and explain round-off in doubles.
  • Manage the session with clc, clear, who, whos, exist and help.
  • بە + - * / \ ^ هەژمار بکەیت و چەپ ڕوون بکەیتەوە.
  • ئەنجامەکان بە پێی لە MATLABـدا پێشبینی بکەیت، تەڵەکانی و نیشانەی سالبیشەوە.
  • بە ناوی دروست دروست بکەیت و بە کۆما و ئەنجامەکان پیشان بدەیت یان بیانشاریتەوە.
  • شێوەیەکی پیشاندان هەڵبژێریت و ڕوونی بکەیتەوە کە هەرگیز هەڵگیراو ناگۆڕێت.
  • سەرەکی لە MATLABـدا ناو ببەیت و لە doubleـدا ڕوون بکەیتەوە.
  • دانیشتنەکە بە clc، clear، who، whos، exist و help بەڕێوە ببەیت.

The arithmetic operatorsکارپێکەرە ژمێرەییەکان

At the >> prompt MATLAB works like a scientific calculator — and so do GNU Octave and the free version of MATLAB Online, where every example of this lesson runs too. It has six :

لە دوای >>، MATLAB وەک زانستی کار دەکات؛ ⁦GNU Octave⁩ و وەشانی بێبەرانبەری ⁦MATLAB Online⁩ـیش بە هەمان شێوەن و هەموو نموونەکانی ئەم وانەیە لەوانیشدا کار دەکەن. شەش بەکار دەهێنێت:

The six arithmetic operators (new numbers)شەش (بە ژمارەی نوێ)
OperationکارSymbolهێماExampleنموونەResultئەنجام
Additionکۆکردنەوە+9 + 413
Subtractionلێدەرکردن-9 - 45
Multiplicationلێکدان*9 * 436
Right division (ئاسایی)/8 / 51.6000
Left division چەپ\5 \ 81.6000
Power^2 ^ 532

Two of them need a closer look. Left division a\b means b divided by a: the number on the side the backslash leans towards is divided into the other one. So 5\8 is 8÷58 \div 5. For single numbers you will rarely need it, but for matrices it solves systems of equations — that use comes in the lesson on matrix operations. Power is ^: 2^5 is 25=322^5 = 32.

دوانیان پێویستیان بە سەرنجی زیاترە. چەپ a\b واتە b دابەش بە a: ئەو ژمارەیەی هێڵە لارەکە بەرەو لای ئەو دەچەمێتەوە، دەبێتە دابەشکەر. کەواتە 5\8 واتە 8÷58 \div 5. بۆ ژمارەی تاک کەم پێویستت پێی دەبێت، بەڵام بۆ پێکەوە چارەسەر دەکات — ئەو بەکارهێنانە لە وانەی کارەکانی ماتریکس دێت. بە ^ دەنووسرێت: 2^5 دەکاتە 25=322^5 = 32.

Four operators at the promptچوار کارپێکەر لە دوای دەقی داواکردنەوەMATLABType in a terminalلە تێرمیناڵدا بینووسە
9 + 4
8 / 5
5 \ 8
2 ^ 5
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

8/5 and 5\8 give the same 1.6000: both divide 8 by 5.

8/5 و 5\8 هەمان ⁦1.6000⁩ دەدەن: هەردووکیان 8 بە 5 دابەش دەکەن.

Lineدێڕی 4

Whole-number answers are shown without decimals; others get four decimals (more about this in Display formats).

وەڵامی بێ ژمارەی دوای پیشان دەدرێت؛ ئەوانی تر چوار ژمارەی دوای وەردەگرن (زیاتر لە شێوەکانی پیشاندان).

Quick checkپشکنینی خێراWhat does 4\10 give?4\10 چی دەدات؟

وانەی ١: کردارە سەرەتاییەکانی ماتلابkakeshan وێبسایتی کاکێشان · Kurdish (Sorani)کوردی (سۆرانی) · 2.8K viewsبینین · 91 likesلایک · Partبەشی 0:00–5:40 (ofلە 11:30)

In Kurdish: using MATLAB as a calculator with + - * / ^ and ans, then radians versus degrees with sin, sind, cos and cosd.

بە کوردی: بەکارهێنانی MATLAB وەک بە + - * / ^ و ans، پاشان بەرامبەر بە sin، sind، cos و cosd.

Kurdish (Sorani). Watch 0:00-5:40: + - * / ^ and ans in the Command Window: 4-5, 2340745, ans300, ans+10, 3^67 (shown as 9.2709e+31) and 2/3.

ڤیدیۆیەکی کوردی (سۆرانی)، لە ⁦0:00⁩ تا ⁦5:40⁩ سەیر بکە: + - * / ^ و ans لە ⁦Command Window⁩: 4-5، 2340*745، ans*300، ans+10، 3^67 (کە وەک 9.2709e+31 پیشان دەدرێت) و 2/3.

The arithmetic operatorsکارپێکەرە ژمێرەییەکان

Working like a calculatorکارکردن وەک حاسیبە

Here are six calculations of the kind the course notes practise, with new numbers. Read each line and predict the answer before you look.

ئەمە شەش هەژمارکردنە لەو جۆرەی تێبینییەکانی وانەکە ڕاهێنانی پێدەکەن، بە ژمارەی نوێ. هەر دێڕێک بخوێنەوە و پێش سەیرکردن وەڵامەکە پێشبینی بکە.

Six calculationsشەش هەژمارکردنMATLABType in a terminalلە تێرمیناڵدا بینووسە
6 + 9/3
(6 + 9)/3
5 + 7/4 + 1
4^3/2
8^(1/3) + 81^0.25
8^1/3 + 81^0.25
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

Division goes before addition, unless brackets say otherwise: 6+3=96 + 3 = 9, but 15/3=515/3 = 5.

پێش کۆکردنەوە دەکرێت، مەگەر کەوانە شتێکی تر بڵێت: 6+3=96 + 3 = 9، بەڵام 15/3=515/3 = 5.

Lineدێڕی 3

7/4=1.757/4 = 1.75 first, then 5+1.75+1=7.755 + 1.75 + 1 = 7.75.

سەرەتا 7/4=1.757/4 = 1.75، پاشان 5+1.75+1=7.755 + 1.75 + 1 = 7.75.

Lineدێڕی 4

The power first: 43=644^3 = 64, then 64/2=3264/2 = 32.

سەرەتا : 43=644^3 = 64، پاشان 64/2=3264/2 = 32.

Lineدێڕی 5

8^(1/3) is the cube root of 8, which is 2; 81^0.25 is the fourth root of 81, which is 3.

8^(1/3) واتە 83=2\sqrt[3]{8} = 2 و 81^0.25 واتە 814=3\sqrt[4]{81} = 3.

Lineدێڕی 6

Without brackets: 81/3=2.66678^1/3 = 2.6667, then + 3+\,3. A very different answer!

بێ کەوانە: 81/3=2.66678^1/3 = 2.6667، پاشان + 3+\,3. وەڵامێکی زۆر جیاواز!

Quick checkپشکنینی خێراWhich line gives the cube root of 27?کام دێڕ 273\sqrt[3]{27} دەدات؟

Order of precedenceپێشینەیی کارپێکەرەکان

When a line has several operators, MATLAB does not simply go from left to right. It follows an order of precedence — the same idea as in school maths, with one detail to remember:

کاتێک دێڕێک چەند تێدایە، MATLAB تەنها لە چەپەوە بۆ ڕاست ناڕوات. ڕیزبەندیی دەگرێتە بەر — هەمان بیرۆکەی بیرکاریی قوتابخانە، بە یەک وردەکاری کە دەبێت لەبیرت بێت:

  1. Brackets ( ) first — the innermost pair first.
  2. Power ^.
  3. Unary minus — a minus sign in front of a number, as in -2.
  4. Multiplication and division * / \ .
  5. Addition and subtraction + -.
  1. کەوانە ( ) یەکەم — سەرەتا ناوەوەترین جووت.
  2. ، واتە ^.
  3. نیشانەی سالب — نیشانەی کەم لە پێش ژمارەیەک، وەک -2.
  4. لێکدان و * / \ .
  5. کۆکردنەوە و لێدەرکردن + -.

Operators on the same level are worked out from left to right. When you are not sure, add brackets: they cost nothing and make the meaning clear to every reader.

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

A ladder of five steps: brackets at the top, then power, then unary minus, then multiply and divide, then add and subtract at the bottom. Beside it, 8^1/3 is worked as (8^1)/3 = 2.6667 while 8^(1/3) is worked as the cube root, 2.پەیژەیەکی پێنج پلەیی: کەوانە لە سەرەوە، پاشان توان، پاشان نیشانەی سالب، پاشان لێکدان و دابەشکردن، پاشان کۆکردنەوە و لێدەرکردن لە خوارەوە. لە تەنیشتیەوە 8^1/3 وەک (8^1)/3 = 2.6667 ئەنجام دەدرێت، بەڵام 8^(1/3) وەک ڕەگی سێجا، واتە 2.
The precedence ladder: higher steps are done firstپەیژەی پێشینەیی: پلە بەرزترەکان یەکەم جار دەکرێنCêIT
Animation: the expression 4+6/3^2-1 is worked out one step at a time. First 3^2 becomes 9, then 6/9 becomes 0.6667, then 4+0.6667 becomes 4.6667, and finally 4.6667-1 gives 3.6667.
Animation: the expression 4+6/3^2-1 is worked out one step at a time. First 3^2 becomes 9, then 6/9 becomes 0.6667, then 4+0.6667 becomes 4.6667, and finally 4.6667-1 gives 3.6667.
One expression, worked out in precedence orderیەک ، بە پێی ڕیزبەندیی پێشینەیی ئەنجام دەدرێتCêIT
Quick checkپشکنینی خێراIn 4 + 6/3^2 - 1, which part does MATLAB work out first?لە 4 + 6/3^2 - 1ـدا MATLAB یەکەم جار کام بەش ئەنجام دەدات؟

Order of precedenceپێشینەیی کارپێکەرەکان

Three precedence trapsسێ تەڵەی پێشینەیی

Three results surprise almost every beginner. Each one follows from the ladder above.

سێ ئەنجام نزیکەی هەموو سەرەتاکارێک سەرسام دەکەن. هەریەکەیان لە پەیژەکەی سەرەوە دەردەچێت.

Brackets change the answerکەوانە وەڵامەکە دەگۆڕێتMATLABType in a terminalلە تێرمیناڵدا بینووسە
8^1/3
8^(1/3)
-2^2
(-2)^2
2^3^2
2^(3^2)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

Trap 1. The power comes before the division, so 8^1/3 is (8^1)/3. To take a root, put the fraction in brackets.

تەڵەی 1. پێش دەکرێت، بۆیە 8^1/3 واتە (8^1)/3. بۆ ڕەگ دەرهێنان، بخە ناو کەوانەوە.

Lineدێڕی 3-4

Trap 2. The power comes before the unary minus, so -2^2 is −(22)=−4-(2^2) = -4. Only (-2)^2 squares −2-2.

تەڵەی 2. پێش نیشانەی سالب دەکرێت، بۆیە -2^2 واتە −(22)=−4-(2^2) = -4. تەنها (-2)^2 ژمارە −2-2 بەرز دەکاتەوە بۆ 2.

Lineدێڕی 5-6

Trap 3. Two powers are worked from left to right in MATLAB: (23)2=64(2^3)^2 = 64. In maths books 2322^{3^2} means 29=5122^9 = 512 — write the brackets to get that.

تەڵەی 3. دوو لە MATLABـدا لە چەپەوە بۆ ڕاست ئەنجام دەدرێن: (23)2=64(2^3)^2 = 64. لە کتێبی بیرکاریدا 2322^{3^2} واتە 29=5122^9 = 512 — بۆ ئەوە کەوانەکە بنووسە.

If you know Python: Python writes the power as ** (Python's power operator), also puts it above the unary minus (-2**2 is −4-4 there too), but works 2**3**2 from the right and gets 512 (Python's precedence).

ئەگەر Python دەزانیت: Python بە ** دەنووسێت (کارپێکەری توان لە Python) و ئەویش لە سەرووی نیشانەی سالبەوە دایدەنێت (-2**2 لەوێش −4-4ـە)، بەڵام 2**3**2 لە ڕاستەوە ئەنجام دەدات و ⁦512⁩ دەدات (پێشینەیی کارپێکەرەکان لە Python).

Quick checkپشکنینی خێراWhat does MATLAB give for -3^2?MATLAB بۆ -3^2 چی دەدات؟

Long commands: ...فەرمانەکانی درێژ: ...

A command can be too long for one line. Type three dots ... at the end of the line, press Enter, and go on typing: MATLAB reads both lines as one command.

لەوانەیە بۆ یەک دێڕ زۆر درێژ بێت. سێ خاڵ ... لە کۆتایی دێڕەکەدا بنووسە، Enter دابگرە و بەردەوام بە لە نووسین: MATLAB هەردوو دێڕەکە وەک یەک دەخوێنێتەوە.

The course notes use this to add up the first four terms of a famous series for the sine. With a new angle, π6≈0.5236\frac{\pi}{6} \approx 0.5236 (that is 30∘30^\circ):

تێبینییەکانی وانەکە ئەمە بەکار دەهێنن بۆ کۆکردنەوەی چوار زاراوەی یەکەمی زنجیرەیەکی بەناوبانگ بۆ . بە گۆشەیەکی نوێ، π6≈0.5236\frac{\pi}{6} \approx 0.5236 (واتە 30∘30^\circ):

sin⁡x≈x−x33!+x55!−x77!\sin x \approx x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!}

The first four terms of the sine series (xx in radians).

چوار زاراوەی یەکەمی زنجیرەی (xx بە ).

A command on two linesفەرمانێک لە دوو دێڕداMATLABType in a terminalلە تێرمیناڵدا بینووسە
0.5236 - 0.5236^3/(1*2*3) + 0.5236^5/(1*2*3*4*5) ...
    - 0.5236^7/(1*2*3*4*5*6*7)
sin(pi/6)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

The ... joins the two lines. The factorials are written as products such as 1*2*3.

... دوو دێڕەکە پێکەوە دەلکێنێت. وەک لێکدان نووسراون، وەک 1*2*3.

Lineدێڕی 3

MATLAB's own sine function gives the same 0.5000 to four decimals. You will meet sin in Built-in maths functions.

خودی MATLAB هەمان ⁦0.5000⁩ تا چوار ژمارەی دوای دەدات. sin لە کردارە ئامادەکانی بیرکاری دەناسیت.

Quick checkپشکنینی خێراWhat do three dots ... at the end of a line do?سێ خاڵ ... لە کۆتایی دێڕێکدا چی دەکەن؟

Variables: giving a value a nameگۆڕاوەکان: ناو دان بە نرخێک

A is a name for a value kept in . You create one with name = expression. The = is the operator: it means “work out the right side, then store the result in the name on the left”. It is not an equation — see “=” in algebra and in programming. That is why x = x + 1 makes sense: take the old x, add 1, and store the result back in x.

ناوێکە بۆ کە لە هەڵدەگیرێت. بە name = expression دروستی دەکەیت. = : واتە «لای ڕاست ئەنجام بدە، پاشان ئەنجامەکە لەو ناوەدا هەڵبگرە کە لە لای چەپە». ئەمە نییە — بڕوانە «=» لە جەبر و لە بەرنامەسازیدا. بۆیە x = x + 1 واتای هەیە: xـی کۆن وەربگرە، 1ی بۆ زیاد بکە و ئەنجامەکە دیسان لە xـدا هەڵبگرە.

Storing and reusing valuesهەڵگرتن و دووبارە بەکارهێنانەوەی نرخەکانMATLABType in a terminalلە تێرمیناڵدا بینووسە
width = 4;
len = 5;
area = width*len
x = 5;
x = x + 1
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-3

A room 4 m wide and 5 m long has an area of 4×5=20 m24 \times 5 = 20\,\mathrm{m}^2. The names say what the numbers mean.

ژوورێک بە پانیی ⁦4 m⁩ و درێژیی ⁦5 m⁩ ڕووبەری 4×5=20 m24 \times 5 = 20\,\mathrm{m}^2ـە. ناوەکان دەڵێن ژمارەکان چ واتایەکیان هەیە.

Lineدێڕی 4-5

The right side x + 1 is 6; then 6 is stored in x, replacing 5.

لای ڕاست x + 1 دەکاتە 6؛ پاشان 6 لە xـدا هەڵدەگیرێت و جێگەی 5 دەگرێتەوە.

A variable must exist before you use it. If you type height*2 before giving height a value, MATLAB stops with an saying it does not recognise the name height.

دەبێت پێش بەکارهێنان هەبێت. ئەگەر پێش ئەوەی بدەیت بە height، height*2 بنووسیت، MATLAB بە دەوەستێت کە دەڵێت ناوی height ناناسێتەوە.

Quick checkپشکنینی خێراAfter x = 5; and then x = x + 1;, what is stored in x?دوای x = 5; و پاشان x = x + 1;، چی لە xـدا هەڵگیراوە؟

Variables: giving a value a nameگۆڕاوەکان: ناو دان بە نرخێک

Rules for variable namesیاساکانی ناونانی گۆڕاوەکان

  • A name starts with a letter.
  • After that it may have letters, digits and the _ — no spaces, no -, no !.
  • It must not be a such as if, for or end (iskeyword lists them all).
  • It can be long: namelengthmax gives the limit — 2048 characters since MATLAB R2025a (older releases allowed 63). Short, clear names are best anyway.
  • ناو بە پیتێک دەست پێدەکات.
  • دوای ئەوە دەتوانێت پیت، ژمارە و _ـی تێدا بێت — بێ ، بێ -، بێ !.
  • نابێت بێت وەک if، for یان end (iskeyword هەموویان لیست دەکات).
  • دەتوانێت درێژ بێت: namelengthmax سنوورەکە دەدات — ⁦2048⁩ لە ⁦MATLAB R2025a⁩ـەوە (وەشانە کۆنەکان ⁦63⁩یان ڕێگە پێدەدا). ناوی کورت و ڕوون هەر باشترن.
Some names, good and badهەندێک ناو، دروست و هەڵە
NameناوValid?دروستە؟Whyبۆچی
room_areayesبەڵێletters and an underscoreپیت و
x6yesبەڵێstarts with a letterبە پیت دەست پێدەکات
totalMarksyesبەڵێcapital letters are allowed inside a nameپیتی گەورە لەناو ناودا ڕێگەپێدراوە
6xnoنەخێرstarts with a digitبە ژمارە دەست پێدەکات
room-areanoنەخێر- is the minus operator- کەمکردنەوەیە
my areanoنەخێرa space splits it into two names دەیکات بە دوو ناو
endnoنەخێرa keyword
Quick checkپشکنینی خێراWhich of these is a valid MATLAB variable name?کام لەمانە ناوێکی دروستی لە MATLABـدا؟

MATLAB Crash Course for BeginnersfreeCodeCamp.org · Englishئینگلیزی · 1.7M viewsبینین · 37K likesلایک · Partبەشی 1:42:57–1:45:09 (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 1:42:57-1:45:09: good variable names (camelCase or underscores), no keywords such as for, no function names such as sum, and no digit at the start.

لە ⁦1:42:57⁩ تا ⁦1:45:09⁩ سەیر بکە: ناوی باش بۆ ( یان )، نە وەک for، نە ناوی وەک sum و نە لە سەرەتادا.

Variables: giving a value a nameگۆڕاوەکان: ناو دان بە نرخێک

Capital letters matterپیتی گەورە و بچووک جیاوازن

MATLAB is : a and A are two different variables, and the same holds for : sqrt(9) works, Sqrt(9) does not. Avoid names that MATLAB already uses — sum, max, i, pi, ans. A variable named like a function hides that function until you clear the variable. exist name tells you whether a name is free (it answers 0).

MATLAB : a و A دوو جیاوازن و هەمان شت بۆ ڕاستە: sqrt(9) کار دەکات، Sqrt(9) کار ناکات. خۆت لەو ناوانە بپارێزە کە MATLAB پێشتر بەکاریان دەهێنێت — sum، max، i، pi، ans. کە ناوی هەبێت، ئەو دەشارێتەوە تا بە clear لادەبەیت. exist name پێت دەڵێت ئایا ناوێک ئازادە (وەڵامی 0 دەداتەوە).

Quick checkپشکنینی خێراWhich line works in MATLAB?کام دێڕ لە MATLABـدا کار دەکات؟

Variables: giving a value a nameگۆڕاوەکان: ناو دان بە نرخێک

Several commands on one lineچەند فەرمانێک لە یەک دێڕدا

You may put several commands on one line. A comma separates them and shows the result; a separates them and hides it.

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

Comma shows, semicolon hidesکۆما پیشان دەدات، خاڵبۆر دەشارێتەوەMATLABType in a terminalلە تێرمیناڵدا بینووسە
p = 15, Q = 3; R = (p - Q) + 20 - p/Q*4
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

p = 15, is shown. Q = 3; is stored but not shown. R has nothing after it, so it is shown.

p = 15, پیشان دەدرێت. Q = 3; هەڵدەگیرێت بەڵام پیشان نادرێت. لە دوای R هیچ نییە، بۆیە پیشان دەدرێت.

Lineدێڕی 1

R=(15−3)+20−15/3×4R = (15 - 3) + 20 - 15/3 \times 4. The division and the multiplication are on the same level, so left to right: 15/3=515/3 = 5, then 5×4=205 \times 4 = 20. So R=12+20−20=12R = 12 + 20 - 20 = 12.

R=(15−3)+20−15/3×4R = (15 - 3) + 20 - 15/3 \times 4. و لێکدان لە هەمان ئاستدان، بۆیە لە چەپەوە بۆ ڕاست: 15/3=515/3 = 5، پاشان 5×4=205 \times 4 = 20. کەواتە R=12+20−20=12R = 12 + 20 - 20 = 12.

Note that p and Q are written in different cases. That is allowed, but remember they are different names: q would be a third variable.

سەرنج بدە کە p و Q بە دوو قەبارەی جیاوازی پیت نووسراون. ئەمە ڕێگەپێدراوە، بەڵام لەبیرت بێت کە دوو ناوی جیاوازن: q دەبێتە سێیەم.

Quick checkپشکنینی خێراWhat does MATLAB print for m = 2; n = 7, k = m*n;?MATLAB بۆ m = 2; n = 7, k = m*n; چی چاپ دەکات؟

Special valuesناوە تایبەتەکان و نرخەکانیان

Some names already have a value when MATLAB starts. You use them often, so learn them now:

هەندێک ناو کاتێک MATLAB دەکرێتەوە پێشتر هەیە. زۆر بەکاریان دەهێنیت، بۆیە ئێستا فێریان بە:

Values that MATLAB knows from the startناوە ئامادەکانی MATLAB و
NameناوMeaningواتاExampleنموونە
ansThe last unnamed resultدوایین ئەنجامی بێناوans
piThe number π=3.14159…\pi = 3.14159\ldotsژمارەی π=3.14159…\pi = 3.14159\ldots2*pi
epsThe gap between 1 and the next larger stored number: 2.2204e-16. It shows how precise numbers are (see Round-off).بۆشایی نێوان 1 و گەورەترین ژمارەی هەڵگیراوی دوای ئەو: ⁦2.2204e-16⁩. پیشان دەدات ژمارەکان چەند وردن (بڕوانە هەڵەی نزیککردنەوە).eps
i, jThe , −1\sqrt{-1} (see the imaginary unit). MathWorks advises writing 1i in calculations.، −1\sqrt{-1} (بڕوانە یەکەی خەیاڵی). MathWorks ئامۆژگاری دەکات لە هەژمارکردندا 1i بنووسیت.3 + 4i
Inf: a result too large to store, such as 1/0 (and -Inf): ئەنجامێک کە زۆر گەورەیە بۆ هەڵگرتن، وەک 1/0 (و -Inf)1/0
NaN“Not a Number”: a result with no meaning, such as 0/0«⁦Not a Number⁩»، واتە ژمارە نییە: ئەنجامێکی بێواتا، وەک 0/00/0
Special values at the promptناوە تایبەتەکان لە دوای دەقی داواکردنەوەMATLABType in a terminalلە تێرمیناڵدا بینووسە
1/0
-1/0
0/0
pi
eps
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-3

Dividing by zero does not stop MATLAB: it answers Inf, -Inf or NaN, and the calculation goes on with that value.

دابەشکردن بەسەر سفردا MATLAB ناوەستێنێت: Inf، -Inf یان NaN دەداتەوە و هەژمارکردنەکە بەو بەردەوام دەبێت.

Lineدێڕی 5

Very small numbers are shown in : 2.2204e-16 means 2.2204×10−162.2204 \times 10^{-16}.

ژمارەی زۆر بچووک بە پیشان دەدرێن: 2.2204e-16 واتە 2.2204×10−162.2204 \times 10^{-16}.

Quick checkپشکنینی خێراWhat does MATLAB give for 0/0?MATLAB بۆ 0/0 چی دەدات؟

Display formatsشێوەکانی پیشاندانی ژمارە

MATLAB stores every number with about 16 significant digits, but by default it shows only four decimals. The format command changes how numbers are shown. It never changes the stored value: MathWorks' documentation says formats affect only how numbers appear, not how MATLAB computes or saves them.

MATLAB هەموو ژمارەیەک بە نزیکەی ⁦16⁩ ژمارەی گرنگ هەڵدەگرێت، بەڵام بە شێوەی بنەڕەتی تەنها چوار ژمارەی دوای پیشان دەدات. format شێوەی پیشاندانی ژمارەکان دەگۆڕێت. هەرگیز هەڵگیراوەکە ناگۆڕێت: MathWorks دەڵێت شێوەکان تەنها کار لە دەرکەوتنی ژمارەکان دەکەن، نەک لە هەژمارکردن یان پاشەکەوتکردنیان.

One value, eight ways to show it (250/7 is stored as 35.714285714285715)یەک ، هەشت ڕێگەی پیشاندان (250/7 وەک ⁦35.714285714285715⁩ هەڵدەگیرێت)
Commandشێوەی پیشاندان250/7 is shown as250/7 بەم شێوەیە پیشان دەدرێتWhat you getچی وەردەگریت
format short35.7143Four decimals — the defaultچوار ژمارەی دوای — بنەڕەتییە
format long35.71428571428571515 decimalsپازدە ژمارەی دوای
format shortE3.5714e+01 with 4 decimals: e+01 means ×101\times 10^{1} بە چوار ژمارەی دوای : e+01 واتە ×101\times 10^{1}
format longE3.571428571428572e+01 with 15 decimals بە پازدە ژمارەی دوای
format shortG35.714Fixed or scientific, whichever is shorter; 5 digitsئاسایی یان زانستی، کامیان کورتتر بێت؛ پێنج ژمارە
format longG35.7142857142857The same with 15 digitsهەمان شت بە پازدە ژمارە
format bank35.71Two decimals, as for moneyدوو ژمارەی دوای ، وەک بۆ پارە
format rational250/7A fraction close to the value کە نزیکە لە

A format stays until you change it. format default brings back the default display (short, with the default line spacing).

شێوەیەک دەمێنێتەوە تا خۆت دەیگۆڕیت. format default پیشاندانە بنەڕەتییەکە دەگەڕێنێتەوە (short، بە بۆشایی بنەڕەتیی نێوان دێڕەکان).

Same x, three displaysهەمان x، سێ پیشاندانMATLABType in a terminalلە تێرمیناڵدا بینووسە
x = 250/7;
format long
x
format shortE
x
format default
x
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

x is stored once, with all its digits.

x یەک جار هەڵدەگیرێت، بە هەموو ژمارەکانییەوە.

Lineدێڕی 2-7

Each format changes only what you see the next time x is shown.

هەر formatـێک تەنها ئەوە دەگۆڕێت کە جاری داهاتوو کاتێک x پیشان دەدرێت دەیبینیت.

Quick checkپشکنینی خێراYou type format long and then y = 2/3. Has the value stored in y changed because of the format?format long دەنووسیت و پاشان y = 2/3. ئایا بەهۆی شێوەکەوە هەڵگیراو لە yـدا گۆڕاوە؟

Display formatsشێوەکانی پیشاندانی ژمارە

Format names, then and nowناوی شێوەکان، کۆن و ئێستا

Quick checkپشکنینی خێراWhich format shows 250/7 as 3.5714e+01?کام شێوە 250/7 وەک 3.5714e+01 پیشان دەدات؟

Data types: what kind of value?جۆرەکانی دراوە: چ جۆرە نرخێک؟

Every value in MATLAB has a class — its . Numbers are double unless you ask for something else. Double means double precision: each number takes 64 = 8 of memory (see bytes) and keeps about 16 significant digits. The function class tells you the class of any value.

هەموو لە MATLABـدا classـێکی هەیە — واتە . ژمارەکان doubleـن مەگەر شتێکی تر داوا بکەیت. Double واتە وردیی دووقات: هەر ژمارەیەک ⁦64⁩ = 8 لە دەگرێت (بڕوانە بایتەکان) و نزیکەی ⁦16⁩ ژمارەی گرنگ دەپارێزێت. class هەر پێت دەڵێت.

A tree with “array” at the top. Its branches are logical (true or false), char (text such as 'a'), numeric, string ("text"), struct (named fields such as img.width = 120) and cell. Numeric divides into double (the default, 8 bytes, such as 3.2567), single, and the integer types int8 to int64 and uint8 to uint64 (uint8 holds 0 to 255, such as a pixel's brightness).دارێک کە «array» لە سەرەوەیەتی. لقەکانی ئەمانەن: logical (ڕاست یان هەڵە)، char (دەقی وەک 'a')، numeric، string ("دەق")، struct (خانەی ناودار وەک img.width = 120) و cell. numeric دابەش دەبێت بۆ double (بنەڕەتی، 8 بایت، وەک 3.2567)، single و جۆرەکانی ژمارەی تەواو لە int8 تا int64 و لە uint8 تا uint64 (uint8 لە 0 تا 255 هەڵدەگرێت، وەک ڕووناکیی پیکسڵێک).
MATLAB's data types: every one of them is an array MATLAB: هەموویان CêIT
Asking for the classپرسیارکردن لە classMATLABType in a terminalلە تێرمیناڵدا بینووسە
x = 7;
class(x)
c = 'a';
class(c)
t = true;
class(t)
p = uint8(200);
class(p)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

A plain number is a double.

ژمارەیەکی ئاسایی doubleـە.

Lineدێڕی 3-4

Text in single quotes is a char (a row of ). Text in double quotes, "a", would be a string.

دەق لەناو کۆتەیشنی تاک charـە (ڕیزێک لە ). دەق لەناو کۆتەیشنی جووت، "a"، دەبێتە string.

Lineدێڕی 5-6

true and false are logical values, shown as 1 and 0 ().

true و false logicalـن و وەک 1 و 0 پیشان دەدرێن ().

Lineدێڕی 7-8

uint8 is an stored in 8 bits.

uint8 کە لە 8 هەڵدەگیرێت.

Why would anyone want uint8? Eight bits have 28=2562^8 = 256 patterns (how many patterns), so a uint8 holds the whole numbers 0 to 255 in one byte instead of eight. The brightness of each in a photo is stored like this. A uint8 cannot go outside those limits: uint8(300) gives 255, uint8(-5) gives 0, and uint8(12.6) rounds to 13.

بۆچی کەسێک uint8ـی دەوێت؟ هەشت 28=2562^8 = 256 شێوەیان هەیە (چەند شێوە)، بۆیە uint8 لە 0 تا ⁦255⁩ لە یەک هەڵدەگرێت لە جیاتی هەشت. ڕووناکیی هەر لە وێنەیەکدا بەم شێوەیە هەڵدەگیرێت. uint8 ناتوانێت لە نێوان ئەو دوو سنوورە دەربچێت: uint8(300) دەکاتە ⁦255⁩، uint8(-5) دەکاتە 0 و uint8(12.6) بۆ ⁦13⁩ نزیک دەکرێتەوە.

whos: sizes, bytes and classes of the workspacewhos: قەبارە، بایت و classـی شوێنی کاریMATLABType in a terminalلە تێرمیناڵدا بینووسە
whos
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Run after the block above. whos lists every variable with its size (1x1 = one value), its memory in bytes and its class. A double takes 8 bytes, a char 2 bytes per character, uint8 and logical 1 byte.

دوای بلۆکی سەرەوە جێبەجێی بکە. whos هەموو لەگەڵ قەبارەکەی (1x1 = یەک )، بە و classـەکەی لیست دەکات. double 8 دەگرێت، char بۆ هەر 2 ، uint8 و logical 1 .

Other classes are only named here: single (4 bytes, fewer digits), the integer types int8 … int64 and uint8 … uint64, string, struct (a record with named fields, such as img.width = 120), cell and function_handle.

classـەکانی تر لێرە تەنها ناو دەبرێن: single (⁦4⁩ ، ژمارەی کەمتر)، جۆرەکانی int8 … int64 و uint8 … uint64، string، struct (تۆمارێک بە خانەی ناودار، وەک img.width = 120)، cell و function_handle.

Quick checkپشکنینی خێراHow many bytes does MATLAB use for one ordinary number such as 7?MATLAB بۆ ژمارەیەکی ئاسایی وەک 7 چەند بەکار دەهێنێت؟

MATLAB Crash Course for BeginnersfreeCodeCamp.org · Englishئینگلیزی · 1.7M viewsبینین · 37K likesلایک · Partبەشی 3:17–5:00 (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 3:17-5:00: whos shows the class of each variable; numbers are double, 'new' in single quotes is a char and "York" in double quotes is a string.

لە ⁦3:17⁩ تا ⁦5:00⁩ سەیر بکە: whos هەر پیشان دەدات؛ ژمارەکان doubleـن، 'new' (بە ') charـە و "York" (بە ") stringـە.

Data types: what kind of value?جۆرەکانی دراوە: چ جۆرە نرخێک؟

Round-off: why 0.1+0.20.1 + 0.2 is not exactly 0.30.3هەڵەی نزیککردنەوە: بۆچی 0.1+0.20.1 + 0.2 ڕێک 0.30.3 نییە

A double keeps about 16 digits in binary. Most decimal fractions, such as 0.1, have no exact binary form, so the computer stores the nearest value it can (why this happens). The tiny difference is called a . You can see it in MATLAB:

double نزیکەی ⁦16⁩ ژمارە بە دوانی هەڵدەگرێت. زۆربەی کەرتە دەییەکان، وەک ⁦0.1⁩، شێوەیەکی دوانیی ڕێکیان نییە، بۆیە نزیکترین هەڵدەگرێت کە دەتوانێت (بۆچی ئەمە ڕوودەدات). جیاوازییە زۆر بچووکەکە پێی دەوترێت . لە MATLABـدا دەیبینیت:

Round-off you can seeهەڵەی نزیککردنەوە کە دەیبینیتMATLABType in a terminalلە تێرمیناڵدا بینووسە
0.1 + 0.2 == 0.3
1 - 3*(4/3 - 1)
eps
64^(1/3)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

== asks “are these equal?” and answers 1 (true) or 0 (false). The answer is 0, because 0.1+0.20.1 + 0.2 is stored as 0.30000000000000004. Comparisons come in the lesson on conditions, which also shows another comparison trap (0 < x < 10).

== دەپرسێت «ئایا ئەمانە یەکسانن؟» و 1 (ڕاست) یان 0 (هەڵە) دەداتەوە. وەڵامەکە 0ـە، چونکە 0.1+0.20.1 + 0.2 وەک ⁦0.30000000000000004⁩ هەڵدەگیرێت. بەراوردکردن لە وانەی مەرجەکان دێت، کە تەڵەیەکی تری بەراوردکردنیش پیشان دەدات (0 < x < 10).

Lineدێڕی 2-3

MathWorks' own example: 4/34/3 cannot be stored exactly, so the result is not 0 but exactly eps, the gap between 1 and the next double.

نموونەی خودی MathWorks: 4/34/3 ناتوانرێت ڕێک هەڵبگیرێت، بۆیە ئەنجامەکە 0 نییە بەڵکو ڕێک epsـە، بۆشایی نێوان 1 و doubleـی دوای ئەو.

Lineدێڕی 4

The decimals in 4.0000 are a warning sign: a whole number would be shown as 4. The stored value is 3.9999999999999996, because 1/31/3 is not exact. nthroot(64,3) gives exactly 4 (see roots and powers).

ژمارەکانی دوای لە 4.0000ـدا نیشانەی ئاگادارکردنەوەن: وەک 4 پیشان دەدرێت. هەڵگیراو ⁦3.9999999999999996⁩ـە، چونکە 1/31/3 ڕێک نییە. nthroot(64,3) ڕێک 4 دەدات (بڕوانە ڕەگ و توان).

Quick checkپشکنینی خێراWhy does 0.1 + 0.2 == 0.3 give 0 (false) in MATLAB?بۆچی 0.1 + 0.2 == 0.3 لە MATLABـدا 0 (هەڵە) دەدات؟

Managing your sessionبەڕێوەبردنی دانیشتنەکەت

These session commands keep your Command Window and your tidy and help you find information:

دانیشتن ⁦Command Window⁩ و ڕێکوپێک دەهێڵنەوە و یارمەتیت دەدەن زانیاری بدۆزیتەوە:

Session commands دانیشتن
Commandناوی What it doesچی دەکات
clcClears the Command Window screen. Your variables stay. ⁦Command Window⁩ پاک دەکاتەوە. دەمێنن.
clear x yRemoves the variables x and y from the workspace. Names are separated by spaces. x و y لە لادەبات. ناوەکان بە جیا دەکرێنەوە.
clearRemoves all variables from the workspace.هەموو لە لادەبات.
clear allAlso removes functions kept in memory. MathWorks: it “decreases code performance, and is usually unnecessary”.هەروەها لادەبات کە لە هەڵگیراون. MathWorks دەڵێت «کارایی کۆد کەم دەکاتەوە و زۆرجار پێویست نییە».
whoLists the names of your variables.ناوی لیست دەکات.
whosLists them with size, bytes and class.لەگەڵ قەبارە، و class لیستیان دەکات.
exist('x')1 if x is a variable, 0 if the name is unused (other numbers for files and functions).1 ئەگەر x بێت، 0 ئەگەر ناوەکە بەکار نەهاتبێت (ژمارەی تر بۆ و ).
help sqrtPrints a short help text for sqrt in the Command Window.دەقێکی کورتی یارمەتی بۆ sqrt لە ⁦Command Window⁩ چاپ دەکات.
doc sqrtOpens the documentation page of sqrt.پەڕەی sqrt دەکاتەوە.
lookfor rootSearches the one-line summaries of functions for a word (here “root”).لە پوختە یەک دێڕییەکانی بە دوای وشەیەکدا دەگەڕێت (لێرەدا «root»).
quitCloses MATLAB (exit does the same).MATLAB دادەخات (exitـیش هەمان کار دەکات).
globalDeclares a variable shared by several functions. You will meet it, and why MathWorks advises against it, with function files later in the track. ڕادەگەیەنێت کە لە نێوان چەند هاوبەشە. دواتر لەم بەشەدا لەگەڵ فایلی کردار دەیبینیت و دەزانیت بۆچی MathWorks ئامۆژگاری دەکات بەکاری نەهێنیت.
Removing two variablesلابردنی دوو گۆڕاوMATLABType in a terminalلە تێرمیناڵدا بینووسە
a = 3; b = 8; c = a*b;
who
clear a b
who
exist('a')
exist('c')
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

who lists a, b and c.

who ئەمانە لیست دەکات: a، b و c.

Lineدێڕی 3-4

After clear a b only c is left.

دوای clear a b تەنها c دەمێنێتەوە.

Lineدێڕی 5-6

exist('a') is 0: the name is free again. exist('c') is 1: c is a variable.

exist('a') 0ـە: ناوەکە دیسان ئازادە. exist('c') 1ـە: c .

Quick checkپشکنینی خێراWhich command clears the screen but keeps all your variables?کام پاک دەکاتەوە بەڵام هەموو دەهێڵێتەوە؟

Managing your sessionبەڕێوەبردنی دانیشتنەکەت

Using clear correctlyبەکارهێنانی دروستی clear

Quick checkپشکنینی خێراWhat does clear x, y really do?clear x, y لە ڕاستیدا چی دەکات؟

Comments and other special charactersلێدوانەکان و هێما تایبەتەکانی تر

A % starts a : MATLAB ignores everything from % to the end of the line. Comments explain your code to people.

% دەست پێدەکات: MATLAB هەموو شتێک لە %ـەوە تا کۆتایی دێڕەکە پشتگوێ دەخات. کۆدەکەت بۆ خەڵک ڕوون دەکەنەوە.

MATLABType in a terminalلە تێرمیناڵدا بینووسە
% area of a room
area = 4*5   % square metres
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

Both comments are skipped; only area = 4*5 runs.

هەردوو پشتگوێ دەخرێن؛ تەنها area = 4*5 جێبەجێ دەکرێت.

The commands list of the course names every special character of MATLAB. You have met some of them; the others come in the next lessons:

لیستی وانەکە هەموو هێما تایبەتەکانی MATLAB ناو دەبات. هەندێکیانت بینیوە؛ ئەوانی تر لە وانەکانی داهاتوودا دێن:

MATLAB's special charactersهێما تایبەتەکانی MATLAB
CharactersهێماکانMeaningواتاWhereلە کوێ
+ - * / \ ^ArithmeticژمێرکاریThis lessonئەم وانەیە
=This lessonئەم وانەیە
( )Grouping, and the arguments of a functionکۆکردنەوەی بەشەکان، هەروەها This lesson; maths functionsئەم وانەیە؛ کردارەکانی بیرکاری
, ;Separate commands (show / hide); inside [ ] they separate elements and rows لێک جیا دەکەنەوە (پیشاندان / شاردنەوە)؛ لەناو [ ]ـدا و ڕیزەکان لێک جیا دەکەنەوەThis lesson; vectorsئەم وانەیە؛ ئاڕاستەبڕەکان
...Continue a command on the next lineبەردەوامکردنی لە دێڕی دواترداThis lessonئەم وانەیە
%CommentThis lessonئەم وانەیە
[ ]Build a vector or matrixدروستکردنی یان Vectors and rangesئاڕاستەبڕەکان و زنجیرەکان
:Ranges such as 1:10زنجیرەی وەک 1:10Colon rangesزنجیرە بە دوو خاڵ
'Transpose (row ↔ column) (ڕیز ↔ ستوون)Vectors, then matrices (' on complex numbers)ئاڕاستەبڕەکان، پاشان ماتریکسەکان (' بۆ ژمارە ئاوێتەکان)
.* ./ .\ .^ .'Element-by-element versions of * / \ ^ 'شێوەی بە * / \ ^ 'Element-wise operations (why the dot matters)کارەکانی توخم بە توخم (بۆچی خاڵەکە گرنگە)
.Decimal point (2.5), and a named part of a struct (img.width) (2.5)، هەروەها بەشێکی ناوداری struct (img.width)This lesson (data types)ئەم وانەیە (جۆرەکانی دراوە)
Quick checkپشکنینی خێراWhat does MATLAB do with area = 4*5 % m2?MATLAB چی دەکات بە area = 4*5 % m2؟

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

MistakeهەڵەWhat happensچی ڕوودەداتFixچارەسەر
Capital letters: Sqrt(16), Clear xپیتی گەورە: Sqrt(16)، Clear xAn error: MATLAB does not know the name.: MATLAB ناوەکە ناناسێت.Lower case: sqrt(16), clear x.پیتی بچووک: sqrt(16)، clear x.
clear x,yنووسینی clear x,yOnly x is removed; y is printed.تەنها x لادەبرێت؛ y چاپ دەکرێت.clear x yبنووسە clear x y
27^1/3 for a cube root27^1/3 بۆ 9, not 3: the power is done first.9، نەک 3: سەرەتا دەکرێت.27^(1/3) or nthroot(27,3)27^(1/3) یان nthroot(27,3)
-2^2 expecting 4چاوەڕوانیی 4 لە -2^2−4-4: the power comes before the minus.−4-4: پێش نیشانەی کەم دێت.(-2)^2بنووسە (-2)^2
2^3^2 expecting 512چاوەڕوانیی ⁦512⁩ لە 2^3^264: MATLAB works left to right.⁦64: MATLAB⁩ لە چەپەوە بۆ ڕاست ئەنجام دەدات.2^(3^2)بنووسە 2^(3^2)
pi = 3 (or i = 2, sum = 0)pi = 3 (یان i = 2، sum = 0)Later formulas silently use your value. دواتر بە بێدەنگی تۆ بەکار دەهێنن.Choose other names; clear pi repairs it.ناوی تر هەڵبژێرە؛ clear pi چاکی دەکاتەوە.
Python's power 2**3 Python، واتە 2**3An error: ** is not a MATLAB operator.: ** MATLAB نییە.2^3بنووسە 2^3
0.1 + 0.2 == 0.3 expecting trueچاوەڕوانیی ڕاست لە 0.1 + 0.2 == 0.30 (false) because of round-off.0 (هەڵە) بەهۆی .abs(a - b) < 1e-10بنووسە abs(a - b) < 1e-10
Thinking format long makes results more accurateوا بزانیت format long ئەنجامەکان وردتر دەکاتNothing changes except the display.جگە لە پیشاندان هیچ ناگۆڕێت.Formats are for reading; the stored value is always full.شێوەکان بۆ خوێندنەوەن؛ هەڵگیراو هەمیشە تەواوە.

Practiceڕاهێنان

ExerciseڕاهێنانPredict, then checkپێشبینی بکە، پاشان بیپشکنە

Work out each line on paper, then type it in MATLAB or Octave: (15 + 9)/4 - 2^3 15 + 9/4 - 2^3 -3^2 + (-3)^2 2^2^3

هەر دێڕێک لەسەر کاغەز ئەنجام بدە، پاشان لە MATLAB یان Octave بینووسە: (15 + 9)/4 - 2^3 15 + 9/4 - 2^3 -3^2 + (-3)^2 2^2^3

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
(15 + 9)/4 - 2^3
15 + 9/4 - 2^3
-3^2 + (-3)^2
2^2^3
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

24/4=624/4 = 6, 23=82^3 = 8, 6−8=−26 - 8 = -2.

24/4=624/4 = 6، 23=82^3 = 8، 6−8=−26 - 8 = -2.

Lineدێڕی 2

Only 9 is divided by 4: 15+2.25−8=9.2515 + 2.25 - 8 = 9.25.

تەنها 9 دابەش بە 4 دەکرێت: 15+2.25−8=9.2515 + 2.25 - 8 = 9.25.

Lineدێڕی 3

−(32)+9=−9+9=0-(3^2) + 9 = -9 + 9 = 0.

واتە −(32)+9=−9+9=0-(3^2) + 9 = -9 + 9 = 0.

Lineدێڕی 4

Left to right: (22)3=43=64(2^2)^3 = 4^3 = 64.

لە چەپەوە بۆ ڕاست: (22)3=43=64(2^2)^3 = 4^3 = 64.

ExerciseڕاهێنانFrom maths to MATLABلە بیرکارییەوە بۆ MATLAB

Write one MATLAB line for each expression and find its value:

بۆ هەر یەک دێڕی MATLAB بنووسە و بدۆزەرەوە:

53+74×31253+2−1\frac{5^3 + 7}{4 \times 3} \qquad\qquad \sqrt[3]{125} + 2^{-1}
Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
(5^3 + 7)/(4*3)
125^(1/3) + 2^(-1)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

The whole top and the whole bottom need brackets: 132/12=11132/12 = 11.

هەموو سەرەوە و هەموو خوارەوە پێویستیان بە کەوانەیە: 132/12=11132/12 = 11.

Lineدێڕی 2

The root's fraction needs brackets, and so does the negative power: 5+0.5=5.55 + 0.5 = 5.5.

ڕەگەکە کەوانەی پێویستە، هەروەها توانە سالبەکەش: 5+0.5=5.55 + 0.5 = 5.5.

ExerciseڕاهێنانShopping with variablesکڕین بە گۆڕاوەکان

Hana buys 3 notebooks at 1.5 thousand IQD each and 2 pens at 0.5 thousand IQD each. Store the numbers in variables with clear names (hide them with ;) and compute the total in thousand IQD.

هانا 3 دەفتەر دەکڕێت کە هەریەکەیان ⁦1.5⁩ هەزار دینارە، هەروەها 2 پێنووس کە هەریەکەیان ⁦0.5⁩ هەزار دینارە. ژمارەکان لە بە ناوی ڕوون هەڵبگرە (بە ; بیانشارەوە) و کۆی گشتی بە هەزار دینار هەژمار بکە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
notebooks = 3;
pens = 2;
notebook_price = 1.5;
pen_price = 0.5;
total = notebooks*notebook_price + pens*pen_price
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

Multiplication before addition: 3×1.5+2×0.5=4.5+1=5.53 \times 1.5 + 2 \times 0.5 = 4.5 + 1 = 5.5 thousand IQD, that is 5,500 dinars.

لێکدان پێش کۆکردنەوە: 3×1.5+2×0.5=4.5+1=5.53 \times 1.5 + 2 \times 0.5 = 4.5 + 1 = 5.5 هەزار دینار، واتە ⁦5500⁩ دینار.

ExerciseڕاهێنانOne value, many formatsیەک نرخ، چەند شێوە

Store x = 22/7 and show it with format short, format long, format shortE, format bank and format rational. Finish with format default.

x = 22/7 هەڵبگرە و بە format short، format long، format shortE، format bank و format rational پیشانی بدە. بە format default کۆتایی پێبهێنە.

Show answerوەڵامەکە پیشان بدە
FormatشێوەShown asپیشاندان
short3.1429
long3.142857142857143
shortE3.1429e+00
bank3.14
rational22/7

The stored value never changed; only the display did.

هەڵگیراو هەرگیز نەگۆڕا؛ تەنها پیشاندانەکە گۆڕا.

ExerciseڕاهێنانGood namesناوی باش

Which of these are valid variable names? speed2, 2speed, top_speed, top speed, for, Speed.

کام لەمانە ناوی دروستی ؟ speed2، 2speed، top_speed، top speed، for، Speed.

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

Valid: speed2, top_speed, Speed (but Speed is a different variable from speed). Not valid: 2speed (starts with a digit), top speed (space), for (keyword).

دروست: speed2، top_speed، Speed (بەڵام Speed جیایە لە speed). نادروست: 2speed (بە ژمارە دەست پێدەکات)، top speed ()، for ().

ExerciseڕاهێنانTidy the workspaceشوێنی کار ڕێک بخە

You have the variables a, b and c. Remove only b and c, check what is left, and clean the screen.

a، b و cـت هەیە. تەنها b و c لاببە، بپشکنە چی ماوەتەوە و پاک بکەرەوە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
clear b c
who
clc
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Spaces, not commas, between the names.

، نەک کۆما، لە نێوان ناوەکاندا.

Lineدێڕی 3

clc cleans the screen; a is still in the workspace.

clc پاک دەکاتەوە؛ a هێشتا لە .

ExerciseڕاهێنانA round-off surpriseسەرسوڕمانێکی هەڵەی نزیککردنەوە

What do you expect 1 - 0.9 - 0.1 to give? Type it and explain the answer.

چاوەڕێ دەکەیت 1 - 0.9 - 0.1 چی بدات؟ بینووسە و وەڵامەکە ڕوون بکەرەوە.

Show answerوەڵامەکە پیشان بدە
MATLABType in a terminalلە تێرمیناڵدا بینووسە
1 - 0.9 - 0.1

In exact maths the answer is 0. Neither 0.9 nor 0.1 can be stored exactly in binary, so a tiny error of about −2.8×10−17-2.8 \times 10^{-17} is left. It is far smaller than eps and harmless in most work — but it is why you should not compare doubles with ==.

لە بیرکاریی ڕێکدا وەڵامەکە 0ـە. نە ⁦0.9⁩ و نە ⁦0.1⁩ ناتوانرێن ڕێک بە دوانی هەڵبگیرێن، بۆیە زۆر بچووک بە نزیکەی −2.8×10−17-2.8 \times 10^{-17} دەمێنێتەوە. لە eps زۆر بچووکترە و لە زۆربەی کارەکاندا زیانی نییە — بەڵام بەهۆی ئەمەوەیە کە نابێت doubleـەکان بە == بەراورد بکەیت.

Summaryپوختە

  • Operators: + - * / \ ^; a\b means b÷ab \div a.
  • Precedence: brackets → ^ → unary minus → * / \ → + -; equal levels left to right, so 8^1/3 gives 2.6667, -2^2 gives −4-4 and 2^3^2 gives 64. Use brackets when in doubt.
  • ... continues a command; , shows and ; hides a result; % starts a comment.
  • Variables: name = expression; names start with a letter, use letters, digits and _; MATLAB is case-sensitive.
  • Special values: ans, pi, eps, i/j, Inf, NaN — never reuse them as names.
  • format short/long/shortE/longE/shortG/longG/bank/rational changes only the display; format default resets it.
  • Numbers are double (8 bytes, about 16 digits); round-off makes 0.1 + 0.2 == 0.3 false.
  • Session: clc (screen), clear x y (variables), who, whos, exist, help, doc, lookfor, quit.
  • : + - * / \ ^؛ a\b واتە b÷ab \div a.
  • : کەوانە ← ^ ← نیشانەی سالب ← * / \ ← + -؛ ئاستە یەکسانەکان لە چەپەوە بۆ ڕاست، بۆیە 8^1/3 دەکاتە ⁦2.6667⁩، -2^2 دەکاتە −4-4 و 2^3^2 دەکاتە ⁦64⁩. کاتێک دڵنیا نیت کەوانە بەکار بهێنە.
  • ... بەردەوام دەکات؛ , ئەنجام پیشان دەدات و ; دەیشارێتەوە؛ % دەست پێدەکات.
  • : name = expression؛ ناو بە پیت دەست پێدەکات و پیت، ژمارە و _ بەکار دەهێنێت؛ MATLAB .
  • ناوە تایبەتەکان: ans، pi، eps، i/j، Inf، NaN — هەرگیز وەک ناو دووبارە بەکاریان مەهێنە.
  • format short/long/shortE/longE/shortG/longG/bank/rational تەنها پیشاندان دەگۆڕێت؛ format default دەیگەڕێنێتەوە.
  • ژمارەکان doubleـن (⁦8⁩ ، نزیکەی ⁦16⁩ ژمارە)؛ وا دەکات 0.1 + 0.2 == 0.3 هەڵە بێت.
  • دانیشتن: clc ()، clear x y ()، who، whos، exist، help، doc، lookfor، quit.
Review questionsپرسیارەکانی پێداچوونەوە
Why is 8^1/3 not the cube root of 8?بۆچی 8^1/3 ڕەگی سێجای 8 نییە؟

Because ^ is done before /: it computes 81/3=2.66678^1/3 = 2.6667. Write 8^(1/3).

چونکە ^ پێش / دەکرێت: 81/3=2.66678^1/3 = 2.6667 هەژمار دەکات. بنووسە 8^(1/3).

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

clc only cleans the Command Window; clear deletes variables from the workspace.

clc تەنها ⁦Command Window⁩ پاک دەکاتەوە؛ clear لە دەسڕێتەوە.

Does format long change the result of a calculation?ئایا format long ئەنجامی هەژمارکردنێک دەگۆڕێت؟

No. It only shows more digits of the value that was already stored.

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

Why should you not name a variable pi?بۆچی نابێت ناوی گۆڕاوێک بنێیت pi؟

It hides MATLAB's π\pi, so every later formula that uses pi gets your value instead.

π\piـی MATLAB دەشارێتەوە، بۆیە هەموو دواتر کە pi بەکار دەهێنێت تۆ وەردەگرێت.

Videoڤیدیۆ

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

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

Learn MATLAB in ONE Video!Jousef Murad | Deep Dive · Englishئینگلیزی · 217K viewsبینین · 5.5K likesلایک · Partبەشی 4:58–13:24 (ofلە 43:42)

A calm MATLAB overview: what MATLAB is, the desktop, arithmetic, variables, display formats, clearing variables, built-in constants and functions.

پێداچوونەوەیەکی هێمنی ⁦MATLAB: MATLAB⁩ چییە، ، ، ، شێوازەکانی پیشاندانی ژمارە، سڕینەوەی ، و .

Watch 4:58-13:24: arithmetic and ans, brackets and precedence, ; to hide output, variables with useful names, format short/long, help format, clear x and clear x*, who/whos, several commands on a line, pi, Inf, NaN and i.

لە ⁦4:58⁩ تا ⁦13:24⁩ سەیر بکە: و ans، کەوانە و ، ; بۆ شاردنەوەی ، بە ناوی بەسوود، format short/long، help format، clear x و clear x*، who/whos، چەند لە یەک دێڕدا، pi، Inf، NaN و i.

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

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

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

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

Built-in Maths Functionsکردارە ئامادەکانی بیرکاری

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

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