Ele323 02
Ele323 02
Khater
19/02/2025 - Lecture 2
One of the most attractive features of MATLAP is its interactive help. The straight
forward way to get help is using the command help followed by any MATLAB topic
you would like ask about.
For example to get help about the build-in function sin type
MATLAB responds by displaying the definition of that function, its syntax and some
other functions similar to this function.
You can get help about any MATLAB command the same way.
You can also open the MATLAB help window or MATLAB documentation window
by clicking the (?) icon in the Toolstrip as shown below.
Through this documentation window you can browse the index to access any topic of
MATLAB documents.
Arithmetic Operations
The symbols for arithmetic operations with scalars are summarized below.
Addition + 7+3
Subtraction - 7–3
Multiplication * 7*3
1
Computer Applications (ELE323) Prof. Mahmoud M. Khater
Order of Precedence
a=3.8^2/(2.75-41*25)+(5.2+1.8^5)/sqrt(3.5)
Display Formats
2
Computer Applications (ELE323) Prof. Mahmoud M. Khater
ans = 50.14
format Eliminates empty lines to allow more lines with information
compact displayed on the screen
format loose Adds empty lines (opposite of compact)
Function Description
abs(x) Computes the absolute value of x.
sqrt(x) Computes the square root of x.
round(x) Rounds x to the nearest integer.
fix(x) Rounds (or truncates) x to the nearest integer toward 0.
floor(x) Rounds x to the nearest integer toward −∞.
ceil(x) Rounds x to the nearest integer toward ∞.
sign(x) Returns a value of −1 if x is less than 0, a value of 0 if x equals 0,
and a value of 1 otherwise.
rem(x,y) Returns the remainder of 𝑥 ⁄𝑦. for example, rem(25, 4) is 1, and
rem(100, 21) is 16. This function is also called a modulus
function.
exp(x) Computes 𝑒 𝑥 , where e is the base for natural logarithms, or
approximately 2.718282.
log(x) Computes log e x , the natural logarithm of x to the base e.
log10(x) Computes log10 x the common logarithm of x to the base 10.
Function Description
deg2rad(x) Compute the angle in radians for a given value x in degrees.
rad2deg(x) Compute the angle in degrees for a given value x in radians.
sin(x) Computes the sine of x, where x is in radians.
sind(x) Computes the sine of x, where x is in degrees.
cos(x) Computes the cosine of x, where x is in radians.
cosd(x) Computes the cosine of x, where x is in degrees.
tan(x) Computes the tangent of x, where x is in radians.
tand(x) Computes the tangent of x, where x is in degrees.
3
Computer Applications (ELE323) Prof. Mahmoud M. Khater
4
Computer Applications (ELE323) Prof. Mahmoud M. Khater
cos 6
(a) (b)
cos 2 20
a=sin(0.2*pi)/cos(pi/6)+tand(72)
b=(tand(64)*cosd(15))^2+(sind(37)/cosd(20))^2
p 3 a b 3a b a 3b
Calculate the perimeter of an ellipse with
𝑎 = 18 𝑖𝑛. and 𝑏 = 7 𝑖𝑛.
a=16;
b=11;
p=pi*(3*(a+b)-sqrt((3*a+b)*(a+3*b)))
a 2 2h
2
2h
LABC a 4h ln
2 2
1
2h a a
Determine LABC if a=8 in. and h=13 in.
a=8;
h=13;
L_ABC=sqrt(a^2+4*h^2)*a^2/(2*h)*log(2*h/a+sqrt((2*h/a)^2+1))
5
Computer Applications (ELE323) Prof. Mahmoud M. Khater
Round-off functions
Function Description
conj(x) Computes the complex conjugate of the complex number x. Thus,
if x is equal to a + ib, then conj(x) will be equal to a – ib.
angle(x) Computes the angle using the value of atan2(imag(x), real(x));
thus, the angle value is between - and .
real(x) Computes the real portion of the complex number x.
imag(x) Computes the imaginary portion of the complex number x.
abs(x) Computes the absolute value of magnitude of the complex number
x.
Operation Result
c1 c2 a1 a2 j b1 b2
c1 c2 a1 a2 j b1 b2
c1 .c2 a1a2 b1b2 j a1b2 a2b1
c1 a1a2 b1b2 ab ba
2 2
j 2 21 2 2 1
c2 a2 b2 a2 b2
6
Computer Applications (ELE323) Prof. Mahmoud M. Khater
x=-7-5i;
y=4+3i;
a=x+y
b=x*y
c=x/y
x=5-8i;
y=-6+7i;
u=x+y
v=x*y
w=x/y
z=exp(x)
r=sqrt(y)
s=x*y^2
7
Computer Applications (ELE323) Prof. Mahmoud M. Khater
z1=25*exp(-j*54/180*pi);
z2=13*exp(j*64/180*pi);
z3=47*exp(j*36/180*pi);
z4=24*exp(j*18/180*pi);
z5=12*exp(-j*76/180*pi);
z=z1+z2-z3+z4*z5
17 16o 7 j 13
(b) z 19 j 15 27 -56o
j 23 25 j 11
z1=17*exp(j*16/180*pi);
z2=27*exp(-j*56/180*pi);
z=z1*(7-13j)/(23j*(25+11j))+19+15j+z2
z1=12*exp(j*63/180*pi);
z2=19*exp(j*15/180*pi);
z=(13+14j)*(15+12j)*z1/((13+16j)*(11+12j))+z2*(13-11j)/(21j*(25+15j))
z=17.532+16.317j+32.573*exp(9.13j)+(13.174+16.319j)*exp(0.341*pi*j)