Aller au contenu
Hub Nexus

MATLAB ProgrammingPage 4 sur 42

MATLAB Programming, Fundamentals of MATLAB, MATLAB operator

MATLAB Operator

MATLAB have a few operator types to manipulate shown below

Note: Variables a and b below represents number

Arithmetic Operations

Arithmetic Operator is used as mathematical operator that manipulates the number according to the formula requirement. The result is shown as numbers.

Additiona + b
Subtractiona - b
Multiplicationa * b
Forward divisiona / b
Backward divisiona \ b
Exponentiationa ^ b
Assignmenta = b

Relational Operations

Relational Operator is used to check if numbers are having any significant relationship with one or another. The results is usually is shown TRUE or FALSE.

Equal Toa == b
Not Equal Toa ~= b
Greater thana > b
Greater or equal toa >= b
Lesser thana < b
Lesser or equal toa <= b

Logical Operations

Logical Operator is used to check if number fulfills the logical conditions, the result is usually shown TRUE or FALSE.

Logical ANDa && b
Logical ORa || b
Logical NOTa ~ b

Elementary Mathematics Constants and Functions

Besides mathematical formula, there are a few mathematical constant and function that you can use to make your works in Matlab easier.
More information about the functions used can be found here:Mathematical_symbols

piReturns value of 3.1416 (Note: Ratio of a circle's circumference to its diameter)
sqrt(a)Returns square root of a
exp(1)Returns value of 2.7183 This is exponential function (Note: it is inverse of natural log, try log(exp(1) and see the result)
log(a)This logarithm operator is to find natural number log of a number
log10(a)This base10 log operator is common logarithm for base 10
mod(a,b) or rem(a,b)This modulo operator returns the remainder after a is divided by b.
: (Colon)Generate a sequence

b > 0: round to a digits to the right of the decimal point.
b = 0: round to the nearest integer.
b < 0: round to a digits to the left of the decimal point. |
| primes(a) | Returns a list of prime numbers less than or equal to number a |
| gcd(a,b) | Returns the greatest common divisors of the number of a and b. |
| lcm(a,b) | Returns the least common multiples of the number of a and b. |

Trigonometry Operations

Trigonometry Triangles (Image: Celso Soto, CC BY-SA 4.0)

The trigonometry formula are given as followed:

Sin α - a / h

Cos α - b / c

Tan α - a / b

sin(α)This sine operator returns sine value of argument in radians
sind(α)This sine operator returns sine value of argument in degree
cos(α)This cosine operator returns cosine value of argument in radians
cosd(α)This cosine operator returns sine value of argument in degree
tan(α)This tan operator returns tangent value of argument in radians
tand(α)This tan operator returns tangent value of argument in degree
deg2rad(α)Convert angle from degrees to radian
rad2deg(α)Convert angle from radians to degrees (Note: Try to convert the pi from radian to degrees )

Matrix Operations

[ ]Container for matrix
,Matrix row separator
;Matrix column separator

Where this page came from

This page was imported from Wikibooks. From “MATLAB Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.