Sei sulla pagina 1di 6

ECE120L – INTRODUCTION TO MATLAB

LABORATORY ACTIVITY #1
MATLAB Basic Functions and Commands

Name: Tagalog, Michelle Anne Therese C. Date: April 01, 2020


Section: A33 Laboratory Instructor: Jipcy Maurris Narvaez

I. Learning Outcomes:
At the end of the laboratory activity, the students should be able to:
1. Familiarize MATLAB environment, its capabilities, functions and basic commands
2. Use MATLAB in solving basic arithmetic problems

II. Laboratory Activity:


1.
a. Problem:
Polynomials
𝑓(𝑥)=𝑥4−8𝑥3−9𝑥−6
𝑔(𝑥)=𝑥3+𝑥2−3𝑥+1

ℎ(𝑥)=3𝑥4−8𝑥3−37𝑥2+2𝑥+4
𝑝(𝑥)=2𝑥3+3𝑥2−2𝑥+5
1. Add, subtract, multiply, and divide each pair of polynomials
2. Multiply the four polynomials by 4, 5, 6, and 7, in that order
3. Find the roots of each four given polynomials
4. Use the results of part 3 to find the polynomial coefficients from the given roots
5. Evaluate the four polynomials at the point x =1, 3, 5, and –2

b. MATLAB Codes:
1. addition
1a. >>f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
f+g
ans =
1 -7 1 -12 -5 x4-7x3+x2-12x-5

1b.>>h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
h+p
ans =
x4-6x3-34x2+9
3 -6 -34 0 9

Subtraction
1c. >>f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
f-g
ans = x4-9x3-x2-6x-7
1 -9 -1 -6 -7

1d. >>h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
h-p = 3x4-10x3-40x2+4x-1
3 -10 -40 4 -1

Multiplication
1e. >>f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
product=conv(f,g)
ans =
0 1 -7 -11 16 -23 21 9 -6

x7-7x6-11x5+16x4-23x3+21x2-9x-6

1f. >>h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
product=conv(h,p)
ans =
0 6 -7 -104 -76 48 -177 2 20
7 6 5 4 3 2
6x -7x -104x -76x +48x -177x +2x+20

Division
1g. >>f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
[Q,R]=deconv(g,f)
ans =
Q=0 Quotient = 0
Remainder = x3+x2-3x+1
R=
0 1 1 -3 1

1h. >>h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
[Q,R]=deconv(p,h)
Quotient = 0
Q=0 Remainder = 2x3+3x2-2x+5
R=
0 2 3 -2 5
2.
2a. f1=f*4
f1 = f1(x)=4x4-32x3-36x-24
4 -32 0 -36 -24
2b. g1=g*5
g1 =
0 5 5 -15 5
g1(x)=5x3+5x2-15x+5
2c. h1=h*6
h1(x)=18x4-48x3-222x2+12x+24
h1 =
18 -48 -222 12 24

2d. p1=p*7
p1 =
0 14 21 -14 35 p1(x)=14x3+21x2-14x+35

3. >>f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
r1 = roots(f)
r1 =
8.1467 + 0.0000i
0.1904 + 1.1661i
0.1904 - 1.1661i
-0.5276 + 0.0000i

r2 = roots(g)
r2 =
-2.4142
1.0000
0.4142

r3 = roots(h)
r3 =
5.0653
-2.4296
0.3450
-0.3140

r4 = roots(p)
r4 =
-2.3681 + 0.0000i
0.4340 + 0.9313i
0.4340 - 0.9313i

4. >>poly(r1)
ans =
1 -8 0 -9 -6
>> poly(r2)
ans =
1 1 -3 1
>> poly(r3)
ans =

>> poly(r4)
ans =

5. >> f=[1,-8,0,-9,-6];
g=[0,1,1,-3,1];
h=[3,-8,-37,2,4];
p=[0,2,3,-2,5];
x=[1:2:7];

a=polyval(f,x)
a = -22 -168 -426 -412

b=polyval(g,x)
b = 0 28 136 372

c=polyval(h,x)
c = -36 -296 -36 2664

d=polyval(p,x)
d = 8 80 320 824

2. a. Problem:
Partial – Fraction Expansion with MATLAB
Determine the partial fraction expansion of the following:

b. MATLAB Codes:
B1. >>Num=[10 70];
Den=[1 9 18];
[r,p,k]=residue(Num,Den)

r =
-3.3333
13.3333
p =
-6
-3
k =
[]

b2. >> Num=[1 2 4 1 3];


Den=[1 7 3 2 1 3];
[r,p,k]=residue(Num,Den)
r =
0.8331 + 0.0000i
0.0606 - 0.2411i
0.0606 + 0.2411i
0.0229 - 0.1960i
0.0229 + 0.1960i
p =
-6.5889 + 0.0000i
-0.6304 + 0.6142i
-0.6304 - 0.6142i
0.4249 + 0.6381i
0.4249 - 0.6381i
k =
[]

b3. >> Num=[1 2 5 1 1];


Den=[1 3 2 4 5 2];
[r,p,k]=residue(Num,Den)
r =
1.0486 + 0.0000i
0.3140 - 0.2522i
0.3140 + 0.2522i
-0.3383 - 0.7823i
-0.3383 + 0.7823i
p =
-2.5797 + 0.0000i
0.4432 + 1.1784i
0.4432 - 1.1784i
-0.6534 + 0.2494i
-0.6534 - 0.2494i
k =
[]
b4. >> Num=[1 4 6 5];
Den=[1 21 222 471 589 168];
[r,p,k]=residue(Num,Den)
r =
-0.0051 - 0.0486i
-0.0051 + 0.0486i
0.0001 + 0.0013i
0.0001 - 0.0013i
0.0101 + 0.0000i
p =
-9.3318 + 9.3836i
-9.3318 - 9.3836i
-0.9775 + 1.2489i
-0.9775 - 1.2489i
-0.3814 + 0.0000i
k =
[]
III. Learnings and Conclusion

MATLAB® can execute different commands that could fulfill the basic needs of a problem, could serve
as a solution and could be utilized in different aspects of life. This just proved that MATLAB® is useful and
important in all professions especially engineering professions.

To be familiarized in the MATLAB® language, tools and commands, this experiment gave a simple
introduction in its environment and a simple discussion of its basic built-in functions. The experiment
provided different mathematical problems to serve as an exercise in the familiarization of MATLAB®.
Working with polynomials using MATLAB®, which is one of the basic data elements of MATLAB®, is
practiced. Several operations that work on polynomial algebra are included in the functions of MATLAB®
such as addition and subtraction of polynomials, scalar multiplication, multiplication and division of
polynomials, polynomial roots and partial fraction.

All the objectives of the experiment were reached so this experiment is considered as a success.

Potrebbero piacerti anche