0% found this document useful (0 votes)
2 views31 pages

MATLAB2

Uploaded by

levidust23
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)
2 views31 pages

MATLAB2

Uploaded by

levidust23
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/ 31

1

Logical Operations Math Functions Polynomial


• Logic operations • Elementary Math functions • Defining polynomials in
• Less than • Complex numbers MATLAB
• Greater than • Trigonometric Functions • Roots of polynomials
• Equal to • Logarithmic Functions • Multiplication & division of
• e.t.c polynomials

2
 To list elementary math function type

>> help elfun

 For a list of more advanced mathematical

and matrix functions type

>> help elmat

3
4
 Logical operations are very useful in conditional

programming.

 Output of a logical operation is either 1 or 0.

• 1 when statement is true

• 0 when statement is false

5
== equal to
> greater than
< less than
>= Greater or equal
<= less or equal
~ not
& and
| or
isfinite(), etc. . . .
all(), any()

find

6
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=MASS==4

Eligible =

0 0 1 0 0 0 0

7
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=MASS>4

Eligible =

0 0 0 1 0 1 1

8
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=MASS<4

Eligible =

1 1 0 0 1 0 0

9
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=MASS<=4

Eligible =

1 1 1 0 1 0 0

10
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=MASS>=4

Eligible =

0 0 1 1 0 1 1

11
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=all(MASS>=4)

Eligible =

12
 Consider the following example.

>> MASS=[1 2 4 10 0.5 6 7]

>> Eligible=any(MASS>=4)

Eligible =

13
 Consider the temperature data produced by a thermocouple
during an hour.

Temp=[-1 3 4 -2.4 6 10 20 23 27 9]

1. Develop a logic to indicate if temperature exceeds 11oC.


2. Develop a logic to indicate if temperature falls below 23oC.
3. Develop a logic to indicate if temperature equals to 9oC.
4. Develop a logic to indicate if temperature do not falls below -
2oC during the hour .

14
15
1 3
M=[1 3; 4 9] M = 
 4 9
sqrt(4) (ii) sqrtm(M)

(iii) linspace(1,20,100) (iv) logspace(1,20,100)

16
(i) sin(30) (ii) asin(30) (iii) sind(30)

(iv) cos(30) (v) acos(30) (vi) cosd(30)

(vii) tan(30) (viii) atan(30) (ix) tand(30)

(x) pi

17
q=2 r= 4+5*j re=3 im=4

(i) real(r) (ii) imag(r) (iii) complex(re,im)

(iv) isreal(q) (v) isreal(r) (vi) conj(r)

(vii) angle(q) (viii) angle(r) (ix) abs(r)

18
1 3
M=[1 3; 4 9] M = 
 4 9

(i) Log(2) (ii) Log2(2) (iii) log10(2)

(iv) logm(M) (v) exp(2) (vi) expm(M)

19
 MATLAB utilizes the following arithmetic operators:

+ Addition
- Subtraction
* Multiplication
/ Division
^ Power Operator

20
Consider t=3 and n=4 find out the values of x, y and z.

(1) x = 5e − 6t
t

(2) y = 60 sin(20 )e −6 t

4n
(3) z =
2 + n2

21
 MATLAB utilizes the following arithmetic operators:

+ addition
- subtraction
.* Array multiplication
./ Array division
.^ Array power operator
' transpose

22
(1) Initialize a linearly space vector t ranging from 0 to
30 with 150 equal spaces
(2) Initialize logarithmically spaced vector n ranging
from 1 to 20 with 120 spaces.

(3) x = 5e − 6
t t

(4) y = 60t sin(20 )e −6 t

4n
(5) z =
2 + n2 23
(1) Initialize a linearly space vector t ranging from 0 to
30 with 150 equal spaces
(2) Consider a=3 and b=4

(3) x = 3a − tb
t

(4) y = a sin(t )  b cos(t )


log 10( a )
(5) z =
log 2(t )
24
25
 In MATLAB, a polynomial is represented by a vector.
 To create a polynomial in MATLAB, simply enter each coefficient
of the polynomial into the vector in descending order.
 For instance, let's say you have the following polynomial:

Z=x4+3x3-15x2-2x+9

 To enter this into MATLAB, just enter it as a vector in the


following manner

>> z = [1 3 -15 -2 9]

26
You can find the value of a polynomial using the polyval
function. For example, to find the value of the above
polynomial at x=2,

>> Z=polyval([1 3 -15 -2 9 ], 2)


Or
>> Z=polyval(x,2)

27
Finding the roots would be as easy as entering the following
command;
>> roots([1 3 -15 -2 9])
Or
>> roots(x)

ans =
-5.5745
2.5836
-0.7951
0.7860
28
The product of two polynomials is found by taking the convolution of

their coefficients.

x+2 and x2+4x+8


>> x = [1 2];
>> y = [1 4 8];
>> z = conv(x,y)
z =
1 6 16 16
29
deconv is used to divide two polynomials. The deconv function
will return the remainder as well as the result. Let's divide z by
y and see if we get x

>> [xx, R] = deconv(z,y)

xx =

1 2

R=
0 0 0 0
30
x=2t2+3t+10 y=3t2+t-7

Enter the following polynomials in the MATLAB.

Find the value of x at t=3 and value of y at t=2.

Find out the roots of the polynomials.

Multiply both polynomials

Divide x by t+1.

31

You might also like