MATLABMATLAB · Chapterبەش 3 · Lectureوانە 3.3
Built-in Maths Functionsکردارە ئامادەکانی بیرکاری
Call MATLAB's elementary maths functions: square and n-th roots, exp and e, abs, the three logarithms, factorial, sine and cosine in radians and degrees, complex numbers with abs, angle and conj, and the rounding functions round, fix, floor and ceil — then solve six textbook-style calculations.
سەرەتایی بیرکاریی MATLAB بانگ بکە: و ڕەگی n-یەم، exp و e، abs، سێ ، ، و بە و ، بە abs، angle و conj، هەروەها : round، fix، floor و ceil — پاشان شەش هەژمارکردن لە شێوەی پرسیارەکانی کتێب چارەسەر بکە.
What you will learnچی فێر دەبیت
- Call a built-in function with a number, an expression or another call as its argument.
- Use sqrt, nthroot, exp, abs, log, log10, log2 and factorial correctly, including =
exp(1)and . - Choose between sin and sind (radians or degrees) and write as
sin(x)^2. - Work with complex numbers and explain why angle uses atan2.
- Predict round, fix, floor, ceil, rem and mod for positive and negative numbers.
- بانگ بکەیت و ژمارەیەک، یان بانگکردنێکی تر وەک بدەیتێ.
- sqrt، nthroot، exp، abs، log، log10، log2 و factorial بە دروستی بەکار بهێنیت، لەوانە =
exp(1)و . - لە نێوان sin و sind ( یان ) هەڵبژێریت و وەک
sin(x)^2بنووسیت. - کار لەگەڵ بکەیت و ڕوونی بکەیتەوە بۆچی angle بە atan2 کار دەکات.
- ئەنجامی round، fix، floor، ceil، rem و mod بۆ و پێشبینی بکەیت.
Calling a functionبانگکردنی کردارێک
MATLAB has hundreds of . You use one by writing its name and, in round brackets, the value it should work on: name(argument). The value in the brackets is the ; the function sends back a result. This is a . Each of these functions computes a mathematical function () such as or . Every example here also runs in GNU Octave and in the free version of MATLAB Online; where they differ, the lesson says so.
MATLAB سەدان هەیە. بۆ بەکارهێنانی یەکێکیان ناوەکەی دەنووسیت و لەناو کەوانەی بازنەییدا ئەو کە دەبێت کاری لەسەر بکات: name(argument). ناو کەوانەکە ؛ ئەنجامێک دەگەڕێنێتەوە. ئەمە . هەر یەکێک لەوانە هەژمار دەکات، وەک یان . هەموو نموونەکانی ئێرە لە GNU Octave و وەشانی بێبەرانبەری MATLAB Onlineـیشدا کار دەکەن؛ لە هەر شوێنێک جیاواز بن، وانەکە دەیڵێت.
A function is like the juice stand at the bazaar: you hand over oranges (the argument), the machine works, and a glass of juice comes back (the result). The same oranges always give the same juice.
وەک دووکانی شەربەتی بازاڕ وایە: پرتەقاڵ دەدەیت ()، ئامێرەکە کار دەکات و پەرداخێک شەربەت دەگەڕێتەوە (ئەنجامەکە). هەمان پرتەقاڵ هەمیشە هەمان شەربەت دەدات.
Where the analogy stops workingسنووری ئەم نموونەیە
Some functions need more than one argument, such as nthroot(x, n), and some need none, such as pi and rand.
هەندێک زیاتر لە پێویستە، وەک nthroot(x, n). هەندێکیشیان هیچیان پێویست نییە، وەک pi و rand.
The argument can be a number, an , or even another function call — and a call can sit inside a bigger expression:
دەتوانێت ژمارەیەک بێت، بێت یان تەنانەت تر — هەروەها بانگکردنێک دەتوانێت لەناو گەورەتردا بێت:
sqrt(49)
sqrt(30 + 12*4)
sqrt(19 + 9*sqrt(81))
(24 + 300/5)/sqrt(144)ans =
7
ans =
8.8318
ans =
10
ans =
7Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
A number.
ژمارەیەک.
- Lineدێڕی 2
An expression: MATLAB first works out , then .
: MATLAB سەرەتا ئەنجام دەدات، پاشان .
- Lineدێڕی 3
A function inside a function: , , . The inner call runs first.
لەناو : ، ، . بانگکردنە ناوەکییەکە یەکەم جار جێبەجێ دەکرێت.
- Lineدێڕی 4
A call inside an expression: .
بانگکردنێک لەناو : .
A calm MATLAB overview: what MATLAB is, the desktop, arithmetic, variables, display formats, clearing variables, built-in constants and functions.
پێداچوونەوەیەکی هێمنی MATLAB: MATLAB چییە، ، ، ، شێوازەکانی پیشاندانی ژمارە، سڕینەوەی ، و .
Watch 14:51-15:49: built-in functions typed as name(argument): sin(5), cos(0), sind, exp, log and abs, and the long list of built-in functions.
لە 14:51 تا 15:49 سەیر بکە: بە شێوەی name(argument): sin(5)، cos(0)، sind، exp، log و abs، هەروەها دەبینیت MATLAB چەندە زۆری هەیە.
Roots, powers and absolute valueڕەگ، توان و نرخی ڕووت
| Function | Meaningواتا | Exampleنموونە | Resultئەنجام |
|---|---|---|---|
sqrt(x) | sqrt(121) | 11 | |
nthroot(x, n) | Real n-th rootڕەگی n-یەمی ڕاستی | nthroot(-8, 3) | -2 |
exp(x) | , the ، | exp(3) | 20.0855 |
abs(x) | abs(-17) | 17 |
MATLAB has no ready-made e. To get Euler's number write exp(1); is exp(2). (Octave also has e, but exp(1) works in both.) The maths of is in the natural exponential function; is in the absolute value function.
MATLAB eـی ئامادەی نییە. بۆ وەرگرتنی بنووسە exp(1)؛ دەبێتە exp(2). (Octave eـیشی هەیە، بەڵام exp(1) لە هەردووکیاندا کار دەکات.) بیرکاریی لە نەخشەی توانی بە بنچینەی e و بیرکاریی لە نەخشەی نرخی ڕووت ڕوون کراوەتەوە.
exp(1)
sqrt(-9)
(-8)^(1/3)
nthroot(-8, 3)
-8^(1/3)ans =
2.7183
ans =
0.0000 + 3.0000i
ans =
1.0000 + 1.7321i
ans =
-2
ans =
-2Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
No real number squared gives , so MATLAB answers with a : 3i (see Complex numbers).
هیچ بە دوو نابێتە ، بۆیە MATLAB بە وەڵام دەداتەوە: 3i (بڕوانە ژمارە ئاوێتەکان).
- Lineدێڕی 3
A fractional power of a negative number gives a complex root, not .
بۆ ڕەگێکی ئاوێتە دەدات، نەک .
- Lineدێڕی 4
nthrootgives the real cube root (odd roots of negative numbers).nthrootڕاستی، واتە ، دەدات (ڕەگی تاکی ژمارە سالبەکان).- Lineدێڕی 5
Also , but only because of precedence: it is
-(8^(1/3)). Do not rely on it.ئەمیش ، بەڵام تەنها بەهۆی پێشینەییەوە: واتە
-(8^(1/3)). پشتی پێ مەبەستە.
nthroot is also more exact for whole-number roots: 64^(1/3) is stored as 3.9999999999999996 (MATLAB shows 4.0000), but nthroot(64, 3) gives exactly 4. For what a root is, see square roots and cube roots.
nthroot بۆ ڕەگی ژمارە تەواوەکانیش وردترە: 64^(1/3) وەک 3.9999999999999996 هەڵدەگیرێت (MATLAB 4.0000 پیشان دەدات)، بەڵام nthroot(64, 3) ڕێک 4 دەدات. بۆ ئەوەی ڕەگ چییە، بڕوانە ڕەگی دووجا و ڕەگی سێجا.
Logarithmsلۆگاریتمەکان
Careful: in MATLAB log(x) is the , with base — not base 10. The base-10 logarithm is log10(x) and the base-2 logarithm is log2(x). The maths is in ln and the common logarithm.
ئاگاداربە: لە MATLABـدا log(x) ـە، واتە بە بنچینەی — نەک بنچینەی 10. (بنچینەی 10) log10(x)ـە و بنچینەی 2 log2(x)ـە. بیرکارییەکەی لە وانەی ln و لۆگاریتمی دەیی ڕوون کراوەتەوە.
log(100)
log10(100)
log2(64)
log(exp(2))
log(0)ans =
4.6052
ans =
2
ans =
6
ans =
2
ans =
-InfExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
, but : the same number, very different answers.
، بەڵام : هەمان ژمارە، دوو وەڵامی زۆر جیاواز.
- Lineدێڕی 4
logundoesexp: .logکاریexpهەڵدەوەشێنێتەوە: .- Lineدێڕی 5
is not a number; MATLAB answers
-Inf. The log of a negative number comes out complex.ژمارە نییە؛ MATLAB
-Infدەداتەوە. ئاوێتە دەردەچێت.
Logarithmsلۆگاریتمەکان
Factorialفاکتۆریێل
factorial(n) gives . It accepts only non-negative whole numbers, and factorial(0) is 1 (see factorials and why ).
factorial(n) ئەمە دەدات: . تەنها وەردەگرێت کە سالب نەبێت و factorial(0) یەکسانە بە 1 (بڕوانە فاکتۆریێلەکان و بۆچی ).
factorial(6)
factorial(0)ans =
720
ans =
1Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
.
واتە .
Factorials grow very fast. MathWorks' factorial page promises an exact result only for n up to 21; for larger n the result is correct to the first 15 digits, and from factorial(171) on it is too big and you get Inf. factorial(2.5) and factorial(-3) stop with an error.
زۆر خێرا گەورە دەبن. پەڕەی factorialـی MathWorks تەنها بۆ n تا 21 ئەنجامی ڕێک بەڵێن دەدات؛ بۆ n ـی گەورەتر ئەنجامەکە تا 15 ژمارەی یەکەم ڕاستە و لە factorial(171)ـەوە زۆر گەورە دەبێت و Inf وەردەگریت. factorial(2.5) و factorial(-3) بە دەوەستن.
Trigonometry: radians or degrees?سێگۆشەناسی: ڕادیان یان پلە؟
sin, cos and tan expect the angle in (see radians). For MATLAB has twins with a d at the end: sind, cosd, tand. The same holds for the inverse functions (see inverse trigonometric functions): asin, acos, atan answer in radians, asind, acosd, atand in degrees, and atan2(y, x) gives the angle of the point (x, y) in the correct quadrant.
sin، cos و tan گۆشەکە بە چاوەڕێ دەکەن (بڕوانە ڕادیانەکان). بۆ MATLAB جووتێکی هەیە کە dـیان لە کۆتاییدایە: sind، cosd، tand. هەمان شت بۆ ڕاستە (بڕوانە نەخشە سێگۆشەییە پێچەوانەکان): asin، acos، atan بە وەڵام دەدەنەوە، asind، acosd، atand بە . هەروەها atan2(y, x) گۆشەی خاڵی (x, y) لە چارەکی دروستدا دەدات.
| Radiansبە | Degreesبە | Meaningواتا |
|---|---|---|
sin(x) | sind(x) | |
cos(x) | cosd(x) | |
tan(x) | tand(x) | |
asin(x) | asind(x) | ، پێچەوانەی |
acos(x) | acosd(x) | ، پێچەوانەی |
atan(x) | atand(x) | ، پێچەوانەی |
sind(45)
cosd(120)
sin(pi/4)
sin(45)
sind(180)
sin(pi)
atand(1)ans =
0.7071
ans =
-0.5000
ans =
0.7071
ans =
0.8509
ans =
0
ans =
1.2246e-16
ans =
45Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-3
and radians are the same angle, so
sind(45)andsin(pi/4)agree.و هەمان گۆشەن، بۆیە
sind(45)وsin(pi/4)یەک دەگرنەوە.- Lineدێڕی 4
A classic mistake:
sin(45)means 45 radians, about .هەڵەیەکی ناسراو:
sin(45)واتە 45 ، نزیکەی .- Lineدێڕی 5-6
sind(180)is exactly 0, butpiis only the nearest double to , sosin(pi)is a tiny round-off number (MathWorks' own example).sind(180)ڕێک 0ـە، بەڵامpiتەنها نزیکترینdoubleـە لە ، بۆیەsin(pi)ژمارەیەکی زۆر بچووکی (نموونەی خودی MathWorks).- Lineدێڕی 7
The inverse in degrees: the angle whose tangent is 1 is .
پێچەوانە بە : ئەو گۆشەیەی 1ـە، ـە.
To convert yourself, use deg2rad(x) and rad2deg(x), or multiply by pi/180 and 180/pi (see converting degrees and radians). The of sind is just the number: the course notes write Sind(30°), but you type sind(30) — lower case and without the ° sign; it gives 0.5000. The commands list also names the hyperbolic functions sinh, cosh, tanh and their inverses asinh, acosh, atanh; you will not need them in this course. Why programs prefer radians is explained in radians in your code.
بۆ گۆڕینی خۆت deg2rad(x) و rad2deg(x) بەکار بهێنە، یان لێکی بدە لە pi/180 و 180/pi (بڕوانە گۆڕینی پلە و ڕادیان). sind تەنها ژمارەکەیە: تێبینییەکانی وانەکە Sind(30°) دەنووسن، بەڵام تۆ sind(30) دەنووسیت — بە پیتی بچووک و بێ نیشانەی °؛ 0.5000 دەدات. لیستی هەروەها هایپەربۆلی ناو دەبات: sinh، cosh، tanh و پێچەوانەکانیان asinh، acosh، atanh؛ لەم کۆرسەدا پێویستت پێیان نابێت. بۆچی پێ باشترە لە ڕادیانەکان لە کۆدەکەتدا ڕوون کراوەتەوە.
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 5:40-9:05: sin(30) gives -0.9880 because 30 is read as radians; sin(30/180*pi) and sind(30) give 0.5; then cos(60) and cosd(60).
ڤیدیۆیەکی کوردی (سۆرانی)، لە 5:40 تا 9:05 سەیر بکە: sin(30) ئەنجامی -0.9880 دەدات، چونکە 30 بە دەخوێنرێتەوە؛ sin(30/180*pi) و sind(30) ئەنجامی 0.5 دەدەن؛ پاشان cos(60) و cosd(60).
Trigonometry: radians or degrees?سێگۆشەناسی: ڕادیان یان پلە؟
Checking an identityپشکنینی هاوئەنجامێک
MATLAB is a quick way to test a formula. The Pythagorean identity says for every x (see the Pythagorean identities). Try it with x = 1.2:
MATLAB ڕێگەیەکی خێرایە بۆ تاقیکردنەوەی . فیساگۆرس دەڵێت بۆ هەموو x (بڕوانە هاوئەنجامەکانی فیساگۆرس). بە x = 1.2 تاقی بکەرەوە:
x = 1.2;
E = sin(x)^2 + cos(x)^2E =
1Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Write
sin(x)^2: first the sine, then the square. Maths books write , butsin^2(x)is not valid MATLAB.بنووسە
sin(x)^2: سەرەتا ، پاشان دوو. کتێبی بیرکاری دەنووسێت، بەڵامsin^2(x)MATLABـی دروست نییە.
For some other values of x the answer comes out as 1.0000 instead of 1 — a round-off of about , not a broken identity.
بۆ هەندێک تری x وەڵامەکە وەک 1.0000 دەردەچێت لە جیاتی 1 — بە نزیکەی ، نەک تێکچوونی .
Complex numbersژمارە ئاوێتەکان
MATLAB works with as easily as with real ones (the maths is in complex numbers). Type them with i or j: z = -3 - 4i. When x and y are variables, write z = x + 1i*y — MathWorks recommends 1i because i may have been reused as a variable.
MATLAB بە هەمان ئاسانیی کار لەگەڵ دەکات (بیرکارییەکەی لە ژمارە ئاوێتەکانـدایە). بە i یان j بیاننووسە: z = -3 - 4i. کاتێک x و y ، بنووسە z = x + 1i*y — MathWorks 1i پێشنیار دەکات، چونکە لەوانەیە i وەک دووبارە بەکار هاتبێت.
| Function | Givesچی دەدات | For بۆ |
|---|---|---|
abs(z) | The length درێژی | 5 |
real(z) | The real part xبەشی ڕاستی x | -3 |
imag(z) | The imaginary part yبەشی خەیاڵی y | -4 |
angle(z) | The angle in radians, from to گۆشەکە بە ، لە تا | -2.2143 |
conj(z) | The | -3.0000 + 4.0000i |
z = -3 - 4i
abs(z)
angle(z)
angle(z)*180/pi
conj(z)z =
-3.0000 - 4.0000i
ans =
5
ans =
-2.2143
ans =
-126.8699
ans =
-3.0000 + 4.0000iExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
.
واتە .
- Lineدێڕی 3-4
: the point lies in the third quarter of the plane, below and left of 0.
= : خاڵەکە لە چارەکی سێیەمی ڕووتەختەکەدایە، لە خوارەوە و چەپی 0.
- Lineدێڕی 5
Only the sign of the imaginary part changes.
تەنها نیشانەی بەشە خەیاڵییەکە دەگۆڕێت.
angle uses atan2: and have the same بۆچی angle بە atan2 کار دەکات: و هەمان ـیان هەیەCêITRounding: round, fix, floor and ceilنزیککردنەوە: round، fix، floor و ceil
Four functions turn a number into a whole number, each in its own way:
چوار ژمارەیەک دەکەن بە ، هەریەکە بە شێوەی خۆی:
round(x)— to the nearest integer; a tie such as 2.5 goes away from zero (to 3, and to ).fix(x)— toward zero: it simply cuts off the decimals.floor(x)— down, to the left on the number line (the floor function).ceil(x)— up, to the right (the ceiling function).
round(x)— بۆ نزیکترین ؛ نیوە بە نیوەیەکی وەک 2.5 لە سفر دوور دەکەوێتەوە (2.5 بۆ 3 و بۆ ).fix(x)— بەرەو سفر: تەنها ژمارەکانی دوای دەبڕێت.floor(x)— بەرەو خوار، بەرەو چەپ لەسەر (نەخشەی گەورەترین ژمارەی تەواو).ceil(x)— بەرەو سەرەوە، بەرەو ڕاست (نەخشەی بچووکترین ژمارەی تەواو).


x = [-2.7 -2.5 -0.5 0.5 2.5 2.7];
round(x)
fix(x)
floor(x)
ceil(x)ans =
-3 -3 -1 1 3 3
ans =
-2 -2 0 0 2 2
ans =
-3 -3 -1 0 2 2
ans =
-2 -2 0 1 3 3Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Square brackets make a list of six numbers; every function below works on each of them. Lists are the topic of the next lesson.
کەوانەی چوارگۆشە لیستێکی شەش ژمارەیی دروست دەکات؛ هەر خوارەوە لەسەر هەریەکەیان کار دەکات. لیستەکان بابەتی وانەی داهاتوون.
- Lineدێڕی 3
fixgives for (toward zero) butfloorgives (down). For positive numbers they agree.fixبۆ ژمارە دەدات (بەرەو سفر)، بەڵامfloorژمارە (بەرەو خوار). بۆ یەک دەگرنەوە.
sign(x) gives , 0 or 1 for a negative number, zero or a positive number. round(x, n) rounds to n decimals: round(pi, 2) is 3.1400. This two-argument form is MATLAB only; Octave's round takes one argument, so there you write round(pi*100)/100. fix will be useful in the lesson on the switch statement, where fix(mark/10) turns a mark such as 87 into the group 8. For rounding rules in everyday statistics see rounding, truncating, floor and ceiling; for floor and ceiling in programs see floor and ceiling in programs.
sign(x) بۆ ، سفر یان ، 0 یان 1 دەدات. round(x, n) بۆ n ژمارەی دوای نزیک دەکاتەوە: round(pi, 2) دەکاتە 3.1400. ئەم شێوەیە کە دوو وەردەگرێت تەنها لە MATLABـدایە؛ roundـی Octave یەک وەردەگرێت، بۆیە لەوێ دەنووسیت round(pi*100)/100. fix لە وانەی ڕستەی switch بەسوود دەبێت، کە fix(mark/10) نمرەیەکی وەک 87 دەکات بە کۆمەڵەی 8. بۆ یاساکانی لە ئاماری ڕۆژانەدا بڕوانە نزیککردنەوە، بڕینەوە، floor و ceiling؛ بۆ floor و ceiling لە بڕوانە floor و ceiling لە بەرنامەکاندا.
Rounding: round, fix, floor and ceilنزیککردنەوە: round، fix، floor و ceil
Remainders: rem and modپاشماوە: rem و mod
rem(a, b) and mod(a, b) give the (remainder) of . For positive numbers they agree: rem(17, 5) and mod(17, 5) are both 2. With a negative number they differ: rem uses fix, so its result has the sign of a; mod uses floor, so its result has the sign of b.
rem(a, b) و mod(a, b) دەدەن. بۆ یەک دەگرنەوە: rem(17, 5) و mod(17, 5) هەردووکیان 2ن. لەگەڵ جیاوازن: rem fix بەکار دەهێنێت، بۆیە ئەنجامەکەی نیشانەی aـی هەیە؛ mod floor بەکار دەهێنێت، بۆیە ئەنجامەکەی نیشانەی bـی هەیە.
rem(17, 5)
rem(-7, 3)
mod(-7, 3)ans =
2
ans =
-1
ans =
2Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
.
واتە .
- Lineدێڕی 3
.
واتە .
More families of functionsخێزانی تری کردارەکان
The commands list of the course groups many more functions. You will use these in later lessons; here is where each family belongs:
لیستی وانەکە زۆر تر کۆمەڵ دەکات. ئەمانە لە وانەکانی داهاتوودا بەکار دەهێنیت؛ ئەمە شوێنی هەر خێزانێکە:
| Familyخێزان | Functions | Used inلە کوێ بەکار دێت |
|---|---|---|
| Statisticsئامار | mean, median, std; erf (the error function of statistics)mean، median، std؛ erf ( هەڵە لە ئاماردا) | Applied to whole arrays in functions for arraysلەسەر تەواو، لە وانەی کردارەکانی ڕیزەک |
| Random numbers | rand (evenly spread between 0 and 1), randn (normal distribution)rand (بە یەکسانی لە نێوان 0 و 1)، randn () | One number now; whole matrices in creating matricesئێستا یەک ژمارە؛ تەواو لە وانەی دروستکردنی ماتریکس |
| Textدەق | strcmp, char, strfind, contains | In script files with input and outputلە فایلەکانی دەسنووس لەگەڵ نێوخستە و دەرخستە |
| Complex and roundingئاوێتە و | abs, angle, conj, real, imag, round, fix, floor, ceil, sign | This lessonئەم وانەیە |
rand
strcmp('Erbil', 'Erbil')ans =
0.8147
ans =
logical
1Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
A random number between 0 and 1. Your number will probably be different: only MATLAB's very first
randafter start-up is always 0.8147, and Octave starts differently.لە نێوان 0 و 1. لەوانەیە ژمارەیەکی جیاواز ببینیت: تەنها یەکەمین
randـی MATLAB دوای کردنەوە هەمیشە 0.8147ـە و Octave بە ژمارەیەکی تر دەست پێدەکات.- Lineدێڕی 2
strcmpcompares two pieces of text and answers 1 (true) when they are exactly the same.strcmpدوو پارچە دەق بەراورد دەکات و کاتێک ڕێک وەک یەک بن 1 (ڕاست) دەداتەوە.
Practice: six calculationsڕاهێنان: شەش هەژمارکردن
These six problems follow the textbook problems of the course notes, with new numbers. Each one mixes powers, roots, e, logarithms and angles. Type each formula as one line, put brackets around every numerator and denominator, and compare your answer.
ئەم شەش پرسیارە شوێنی پرسیارەکانی کتێبی تێبینییەکانی وانەکە دەکەون، بە ژمارەی نوێ. هەریەکەیان توان، ڕەگ، e، و گۆشە تێکەڵ دەکات. هەر وەک یەک دێڕ بنووسە، کەوانە بخەرە دەوری هەموو سەرەوە و خوارەوەیەکی و وەڵامەکەت بەراورد بکە.
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
(18 + 4.2^2)/(40 - 5.3^2)ans =
2.9924Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Top: . Bottom: . Without the brackets MATLAB would divide only by 40.
سەرەوە: . خوارەوە: . بێ کەوانەکان MATLAB تەنها دابەش بە 40 دەکرد.
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
35/6 + 7^2/4 - 80/3.5^2ans = 11.5527
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Here no brackets are needed:
^goes first, then each/, then+and-. .لێرە کەوانە پێویست نییە: سەرەتا
^، پاشان هەر/ێک، پاشان+و-. .
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
sqrt(36^2 - 4.8^2)/(exp(4) - 40.6)ans =
2.5488Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
is
exp(4)= 54.5982, so the bottom is 13.9982; the top is .دەبێتە
exp(4)= 54.5982، بۆیە خوارەوە 13.9982ـە؛ سەرەوە ـە.
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
150^(1/3) + log(300)/6
nthroot(150, 3) + log(300)/6ans =
6.2639
ans =
6.2639Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
Both ways give the cube root 5.3133. is
log: .هەردوو ڕێگەکە 5.3133 دەدەن. دەبێتە
log: .
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
cos(5*pi/8) + tan(2*pi/9)*sind(25)ans = -0.0281
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
The first two angles are in radians, so
cosandtan; needssind. .دوو گۆشەی یەکەم بە ، بۆیە
cosوtan؛ پێویستی بەsindـە. .
Calculate in MATLAB:
لە MATLABـدا هەژماری بکە:
Show answerوەڵامەکە پیشان بدە
sind(70)^2 - (cosd(20)*sind(70))^2/0.25^(1/3)ans = -0.3547
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
is written
sind(70)^2. .بە
sind(70)^2دەنووسرێت. .
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | What happensچی ڕوودەدات | Fixچارەسەر |
|---|---|---|
Degrees into sin: sin(30) بۆ ناو sin: sin(30) | , because 30 is read as radians، چونکە 30 وەک دەخوێندرێتەوە | sind(30) or sin(pi/6)sind(30) یان sin(pi/6) |
A capital letter: Sqrt(16), Log(5)پیتی گەورە: Sqrt(16)، Log(5) | An error: unknown name: ناوی نەناسراو | sqrt(16), log(5)sqrt(16)، log(5) |
log for base 10log بۆ بنچینەی 10 | is computed insteadلە جیاتی ئەوە هەژمار دەکرێت | log10(x)log10(x) |
e^2 for e^2 بۆ | MATLAB does not know e (Octave does)MATLAB e ناناسێت (Octave دەیناسێت) | exp(2)exp(2) |
sin^2(x) for sin^2(x) بۆ | An error | sin(x)^2sin(x)^2 |
(-8)^(1/3) for the real cube root(-8)^(1/3) بۆ ڕاستی | A complex number, ، | nthroot(-8, 3)nthroot(-8, 3) |
atan(y/x) for the angle of a pointatan(y/x) بۆ گۆشەی خاڵێک | The wrong quarter when x is negativeچارەکی هەڵە کاتێک x سالبە | atan2(y, x) or angle(x + 1i*y)atan2(y, x) یان angle(x + 1i*y) |
fix and floor mixed upتێکەڵکردنی fix و floor | Different answers for negative numbers: and for وەڵامی جیاواز بۆ : و بۆ | Toward zero: fix; down: floorبەرەو سفر: fix؛ بەرەو خوار: floor |
More practiceڕاهێنانی زیاتر
A taxi fare comes out as 4.65 thousand IQD. What do round, fix, floor and ceil give? Which one would a driver who always rounds up use?
کرێی تەکسییەک دەبێتە 4.65 هەزار دینار. round، fix، floor و ceil چی دەدەن؟ شوفێرێک کە هەمیشە بۆ سەرەوە نزیک دەکاتەوە کامیان بەکار دەهێنێت؟
Show answerوەڵامەکە پیشان بدە
fare = 4.65;
round(fare)
fix(fare)
floor(fare)
ceil(fare)ans =
5
ans =
4
ans =
4
ans =
5ceil always rounds up, to 5 thousand IQD. For a positive number fix and floor agree.
ceil هەمیشە بۆ سەرەوە نزیک دەکاتەوە، بۆ 5 هەزار دینار. بۆ fix و floor یەک دەگرنەوە.
For z = 6 - 8i find the length, the angle in degrees and the conjugate. In which quarter of the plane is z?
بۆ z = 6 - 8i درێژی، گۆشە بە و بدۆزەرەوە. z لە کام چارەکی ڕووتەختەکەدایە؟
Show answerوەڵامەکە پیشان بدە
z = 6 - 8i;
abs(z)
angle(z)*180/pi
conj(z)ans =
10
ans =
-53.1301
ans =
6.0000 + 8.0000i. x is positive and y negative, so z is in the fourth quarter and the angle is negative: .
. x موجەبە و y سالب، بۆیە z لە چارەکی چوارەمدایە و گۆشەکە سالبە: .
A student typed these lines to compute . Find and fix the three mistakes.
Log(50) + sin(60) + e^1.5
قوتابییەک ئەم دێڕەی نووسی بۆ هەژمارکردنی . سێ هەڵەکە بدۆزەرەوە و چاکیان بکەرەوە.
Log(50) + sin(60) + e^1.5
Show answerوەڵامەکە پیشان بدە
log(50) + sind(60) + exp(1.5)ans =
9.2597Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Log→log(lower case);sin(60)→sind(60)(degrees);e^1.5→exp(1.5). Then .Log←log(پیتی بچووک)؛sin(60)←sind(60)()؛e^1.5←exp(1.5). پاشان .
Summaryپوختە
- A function call is
name(argument); the argument can be a number, an expression or another call. sqrt,nthroot(real roots of negatives),exp(exp(1)is e),abs.logis ;log10andlog2are the other bases.factorial(n)needs a whole number that is not negative; .sin cos tantake radians,sind cosd tanddegrees;sind(180)is exactly 0,sin(pi)is 1.2246e-16.- Complex:
abs,real,imag,angle(atan2, to ),conj(); write1i. round(nearest, ties away from 0),fix(toward 0),floor(down),ceil(up),sign;remandmodgive remainders.
- بریتییە لە
name(argument)؛ دەتوانێت ژمارە، یان بانگکردنێکی تر بێت. sqrt،nthroot(ڕەگی ڕاستیی )،exp(exp(1)واتە e)،abs.logواتە ؛log10وlog2بنچینەکانی ترن.factorial(n)پێویستە کە سالب نەبێت؛ .sin cos tanوەردەگرن،sind cosd tand؛sind(180)ڕێک 0ـە وsin(pi)1.2246e-16ـە.- ئاوێتە:
abs،real،imag،angle(atan2، لە تا )،conj()؛1iبنووسە. round(نزیکترین، نیوە بە نیوە دوور لە 0)،fix(بەرەو 0)،floor(بەرەو خوار)،ceil(بەرەو سەرەوە)،sign؛remوmodدەدەن.
If you know Python: these functions live in Python's math module (math.sqrt, math.log…) — see the math module. In MATLAB they are always ready, with no import.
ئەگەر Python دەزانیت: ئەم وانەیە لە مۆدیوڵی mathـی Pythonـدان (math.sqrt، math.log…) — بڕوانە مۆدیوڵی math. لە MATLABـدا هەمیشە ئامادەن، بێ هاوردەکردن.
Why does sin(pi) not give exactly 0?بۆچی sin(pi) ڕێک 0 نادات؟
pi is only the nearest double to , so the sine is a tiny round-off number, 1.2246e-16. sind(180) gives exactly 0.
pi تەنها نزیکترین doubleـە لە ، بۆیە ژمارەیەکی زۆر بچووکی ، 1.2246e-16. sind(180) ڕێک 0 دەدات.
What is the difference between fix(-3.6) and floor(-3.6)?جیاوازیی نێوان fix(-3.6) و floor(-3.6) چییە؟
fix goes toward zero (); floor goes down ().
fix بەرەو سفر دەچێت ()؛ floor بەرەو خوار ().
Why use angle(z) and not atan(y/x)?بۆچی angle(z) بەکار بهێنین نەک atan(y/x)؟
angle uses atan2 and gives the angle in the correct quarter; atan(y/x) cannot tell from .
angle atan2 بەکار دەهێنێت و گۆشەکە لە چارەکی دروستدا دەدات؛ atan(y/x) ناتوانێت لە جیا بکاتەوە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Vectors and Rangesئاڕاستەبڕەکان و زنجیرەکان
Related lecturesوانە پەیوەندیدارەکان
- Vectors and Rangesئاڕاستەبڕەکان و زنجیرەکان
- The Six Trigonometric Functionsشەش نەخشە سێگۆشەییەکە
- Logarithms and Their Rulesلۆگاریتمەکان و یاساکانیان
- Sets of Numbers: From Natural to Complexکۆمەڵەکانی ژمارە: لە ژمارە سروشتییەکانەوە تا ژمارە ئاوێتەکان
- Piecewise Functions: Absolute Value, Floor and Ceilingنەخشە ڕێسا پەلدارەکان: نرخی ڕووت، نەخشەی گەورەترین ژمارەی تەواو و نەخشەی بچووکترین ژمارەی تەواو
- Operators and Expressionsکارپێکەرەکان و دەربڕینەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- MathWorks: sind (sine of argument in degrees)
- MathWorks: angle (phase angle, uses atan2)
- MathWorks: fix (round toward zero)
- MathWorks: round (ties away from zero, TieBreaker)
- MathWorks: rem (remainder after division; compared with mod)
- MathWorks: nthroot (real n-th root)
- MathWorks: factorial
- MathWorks: i (imaginary unit; use 1i)
- MathWorks: Floating-Point Numbers
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.