0% found this document useful (0 votes)
8 views8 pages

Ele323 02

The document provides an overview of MATLAB's interactive help features, arithmetic operations, order of precedence, display formats, and built-in functions for elementary math, trigonometry, and complex numbers. It includes examples of calculations using MATLAB commands and functions, demonstrating how to perform various mathematical operations. Additionally, it covers rounding functions and arithmetic operations with complex numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Ele323 02

The document provides an overview of MATLAB's interactive help features, arithmetic operations, order of precedence, display formats, and built-in functions for elementary math, trigonometry, and complex numbers. It includes examples of calculations using MATLAB commands and functions, demonstrating how to perform various mathematical operations. Additionally, it covers rounding functions and arithmetic operations with complex numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Applications (ELE323) Prof. Mahmoud M.

Khater

19/02/2025 - Lecture 2

MATLAP Help and Help Window

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

>> Help sin

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.

Operation Symbol Example

Addition + 7+3

Subtraction - 7–3

Multiplication * 7*3

Right division / 7/3

1
Computer Applications (ELE323) Prof. Mahmoud M. Khater

Left division \ 7\3=3/7

Exponentiation ^ 7^3 (means 73 = 343)

Order of Precedence

MATLAB executes the calculations according to the following order of precedence:

Precedence Mathematical Operation


First Parentheses. For nested parentheses, the innermost are
executed first.
Second Exponentiation.
Third Multiplication, division (equal precedence).
Fourth Addition and subtraction.

Example Q5-a Sheet 1

3.82 5.2  1.85


Use MATLAB to calculate 
2.75  41 25 3.5

a=3.8^2/(2.75-41*25)+(5.2+1.8^5)/sqrt(3.5)

Display Formats

Command Description Example


format short Fixed-point with 4 decimal digits >> 351/7
ans = 50.1429
format long Fixed-point with 14 decimal digits >> 351/7
ans =
50.14285714285715
format short e Scientific notation with 4 decimal >> 351/7
digits ans = 5.0143e + 001
format long e Scientific notation with 15 decimal >> 351/7
digits ans =
5.014285714285715e001
format short g Best of 5 digit fixed or floating >> 351/7
point ans = 50.143
format long g Best of 15 digit fixed or floating >> 351/7
point ans = 50.1428571428571
format bank Two decimal digits >> 351/7

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)

Elementary Math Built-In Functions

Common math functions

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.

Trigonometric and hyperbolic functions.

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

asin(x) Computes the arcsine or inverse sine of x, where x must be


between –1 and 1.
The function returns an angle in radians between −𝜋⁄2 and 𝜋⁄2.
asind(x) Computes the arcsine or inverse sine of x, where x must be
between –1 and 1.
The function returns an angle in radians between −90° and 90°.
acos(x) Computes the arccosine or inverse cosine of x, where x must be
between –1 and 1. The function returns an angle in radians
between 0 and .
acosd(x) Computes the arccosine or inverse cosine of x, where x must be
between –1 and 1. The function returns an angle in radians
between 0 and 180.
atan(x) Computes the arctangent or inverse tangent of x. The function
returns an angle in radians between −𝜋⁄2 and 𝜋⁄2.
atand(x) Computes the arctangent or inverse tangent of x. The function
returns an angle in radians between −90° and 90°.
Atan2(y,x) Computes the arctangent or inverse tangent of the value 𝑦⁄𝑥 . The
function returns an angle in radians that will be between - and ,
depending on the signs of x and y.
sinh(x) e x  e x
Computes the hyperbolic sine of x, which is equal to
2
cosh(x) e x  e x
Computes the hyperbolic cosine of x, which is equal to
2
tanh(x) sinh x
Computes the hyperbolic tangent of x, which is equal to
cosh x
asinh(x) Computes the inverse hyperbolic sine of x, which is equal to

ln x  x 2  1 
acosh(x) Computes the inverse hyperbolic cosine of x, which is equal to

ln x  x 2  1 
atanh(x) Computes the inverse hyperbolic tangent of x, which is equal to
1 x
ln for x  1
1 x

4
Computer Applications (ELE323) Prof. Mahmoud M. Khater

Example Q3, Sheet 2

3. Use MATLAB to calculate


sin  0.2  sin 2 37
 tan 72  tan 64 cos15  
2

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

Example Q9, Sheet 2

9. The perimeter of an ellipse can be


approximated by

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)))

Example Q11, Sheet 2

11. The arc length of a segment of a parabola ABC is given by:

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

Command Description Example


round(x) Round to the nearest integer >> round(20/6)
ans = 3
fix(x) Round towards zero >> fix(13/6)
ans = 2
ceil(x) Round towards infinity >> ceil(13/5)
ans = 3
floor(x) Round towards minus infinity >> floor(–10/4)
ans = –3
rem(x,y) Returns the remainder after x is divided >> rem(14,3)
by y ans = 2
sign(x,y) Signum function. Returns 1 if x > 0, –1 >> sign(7)
if x < 0, and 0 if x = 0. ans = 1

Complex number 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.

Arithmetic operations with complex numbers.

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

c1 a12  b12 (magnitude or absolute value of c1)

6
Computer Applications (ELE323) Prof. Mahmoud M. Khater

c1* c1  a1  jb1 (conjugate of c1)

Assume that c1  a1  jb1 and c2  a2  jb2

Example Q16, Sheet 2

16. Use MATLAB to make the following calculations, for 𝑥 = −7 − j5 and 𝑦 = 4 +


j3

(a) 𝑥+𝑦 (b) 𝑥𝑦 (c) 𝑥 ⁄𝑦

x=-7-5i;
y=4+3i;
a=x+y
b=x*y
c=x/y

Example Q18, Sheet 2

18. Use MATLAB to make the following calculations, for 𝑥 = 5 − j8 and 𝑦 = −6 +


j7

(a) 𝑢 =𝑥+𝑦 (b) 𝑣 = 𝑥𝑦 (c) 𝑤 = 𝑥 ⁄𝑦


(d) 𝑧 = 𝑒𝑥 (e) 𝑟 = √𝑦 (f) 𝑠 = 𝑥𝑦 2

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

Example Q19, Sheet 2

19. Use MATLAB to calculate the following complex expressions:

(a) z = 25 -54o + 13 64o - 47 36o + 2418o  12 -76o

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

13  j 14 15  j 12  12 63  19 15o 13  j 11


(c) z  
13  j 16 11  j 12  j 21 25  j 15 

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))

(d) z  17.532  j 16.317  32.573e j 9.13  13.174  j 16.319  e j 0.341

z=17.532+16.317j+32.573*exp(9.13j)+(13.174+16.319j)*exp(0.341*pi*j)

You might also like