Operators and functions (Matlab, C)

Arithmetic Operators

Operator    Matlab   C
Addition + +
Subtraction - -
Multiplication * *
Division / /
Power^function pow
Modulofun. mod %

Logical Operators

Operator    Matlab   C
NOT~ !
AND & &&
OR | ||

Relational Operators

Relation    Matlab   C
Equal to == ==
Not equal to ~= !=
Less than < <
Less than or equal to <= <=
Greater than > >
Greater than or equal to >= >=

Mathematical constants

Constant    Matlab   C
Number PipiM_PI

Mathematical Functions

Function    Matlab   C
sin xsin(x)sin(x)
cos xcos(x)cos(x)
tg xtan(x)tan(x)
arcsin xasin(x)asin(x)
arccos xacos(x)acos(x)
arctg xatan(x)atan(x)
e xexp(x)exp(x)
ln xlog(x)log(x)
x 1/2sqrt(x)sqrt(x)
a xpower(a, x)pow(a, x)
abs. value (modulus)abs(x)fabs(x)
roundround(x)floor(x + 0.5)
round upceil(x)ceil(x)
round downfloor(x)floor(x)
remainder after x divided by ymod(x, y)fmod(x, y)

Input from keyboard and output to screen

Function    Matlab   C
Read integer value into variable n:n = input('Give a number: ')scanf("%d", &n);
Read real value into variable x:x = input('Give the weight: ')scanf("%f", &x);
Print integer n:disp(n)printf("%d", n);
  ... and with a comment:fprintf('Number is %.0f', n)printf("Number is %d", n);
Print real x:disp(x)printf("%f", x);
  ... with a comment and new line:fprintf('The weight is %f kg.\n', x)printf("The weight is %f kg.\n", x);


Last updated: 27. September 2016