Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Chemical Engineering Department

University of Florida
ECH 6326 COMPUTER PROJECT No. 1

Date Due: Student Name:


Grader: Group:

PLEASE SIGN THE FOLLOWING PLEDGE

On my honor, I have neither given nor received unauthorized aid in doing this work. I understand that the
instructor may assign a failing grade in this course as a sanction for honor-code violations.

Signature

********* Please submit this SIGNED page with your project *********

GRADING TABLE

Laboratory Exercise Score

Computer Laboratory Experiment 1 /3

Computer Laboratory Experiment 2 n/a

Computer Laboratory Experiment 3A /3

Computer Laboratory Experiment 3B /3

Average Score /9 = /100

1
Chemical Engineering Department
University of Florida
ECH4323L/ECH 6326 COMPUTER LABORATORY EXPERIMENT No. 1

Date Due: Student Name:


Grader: Group:

********* Please submit this SIGNED page with your project *********

GRADING TABLE
Problem Score
1 /3
2 /3
3 /3
4 /3
5 /3
6 /3
7 /3
Average Score /6 = /100

Introduction to MATLAB
Problem 1. Reading Assignment
Read the class handout entitled MATLAB MINIGUIDE.
You are responsible for all the material appearing in the handout.
Learn all the commands mentioned in the section entitled "List of Essential Commands and Operators".
Consult the MATLAB on-line manuals for each command, for example, to obtain help on the command
diary , type help diary.

Problem 2. Access MATLAB in your own computer if in one of the following CIRCA labs
that is most convenient for you:

• CSE 211
• Architecture 118
• Weil Hall 408
• Bryan Hall 232
• Norman Hall G514.

For more information on CIRCA labs, please visit http://labs.at.ufl.edu.


(a) Lauch the MATLAB program.
(b) Execute the MATLAB command demo (simply type demo after the prompt sign ”  ”). Select
several options and verify that the options that demonstrate the plotting capabilities actually succeed
in bringing up plots in the screen. If you do not see plots or figures generated by the MATLAB demo
program in your monitor screen, report this problem to your instructor.

2
(c) Quit from MATLAB (type quit or select Quit from the file menu).

Problem 3. Access MATLAB as in Problem 2.

(a) Experiment with all the commands discussed in Section 1.4 of the MATLAB MINIGUIDE ("Overview
of MATLAB Operations").
   
0.1 0.6 log10 19
(b) Let A = and b =
1.2 0.93672 ln 16

(a) Calculate c = Ab =

(b) Use the eig function to calculate the eigenvalues of matrix A

Λ(A) =

Problem 4. Use MATLAB to carry out the indicated mathematical operations.


You can use the MATLAB function abs for calculating s6 and the function angle for calculating s7. (Type
help abs and help angle for a description of the functions). Let

s1 = 1.6993 + 0.9311i

and
s2 = 0.7773 + 1.8313i

(a) Calculate s3 = s1 + s2 =

s1
(b) Calculate s4 = =
s2 1

(c) Calculate s5 = s1 s2 =

3
(d) Calculate s6 = |s1 s2 | =

(e) Calculate s7 = arg (s1 s2 ) =

(f) Calculate s8 = s81 =

Problem 5. Indicate how you would represent the following polynomials using the MATLAB
notation.

(a) Calculate N (s) = 2s2 + 4s + 1 

(b) Calculate N (s) = 3s2 + 1 

(c) Calculate N (s) = 3s2 + 4s 

(d) Calculate N (s) = 15s4 + 4s + 1 

Problem 6. Use roots command of MATLAB to find the roots of the following polynomials.

(a) N (s) = s2 + 4 Roots:

4
(b) N (s) = s5 + 4s + 1 Roots:

(c) N (s) = 3s2 + 4s Roots:

(d) N (s) = 15s4 + 4s + 1 Roots:

Problem 7. Use poly command of MATLAB to find a polynomial with the indicated roots.

(a) roots : {−1, −9} N (s) =

(b) roots : {1, 2 ± i} N (s) =

(c) roots : {–0.44, –0.55, 1} N (s) =

5
Chemical Engineering Department

University of Florida
ECH4323L/ECH 6326 COMPUTER LABORATORY EXPERIMENT No. 3A

Date Due: Student Name:


Grader: Group:

********* Please submit this SIGNED page with your project *********

GRADING TABLE
Problem Score
1 /3
2 /3
3 /3
4 /3
5 /3
Average Score /15 = /100

Operations with Polynomials and


Rational Functions Using MATLAB

A rational function is a ratio of two polynomials. For example,


2s + 1
G(s) =
s2 + 3s + 1
is a rational function because it is the ratio of a numerator polynomial N (s) = 2s + 1 and a denominator
polynomial D(s) = s2 + 3s + 1, that is
N (s)
G(s) =
D(s)
By definition, a complex number z is a said to be a zero of a rational function G(s) if, after making the
substitution s = z,
G(z) = 0
Equivalently, lims→z G(s) = 0. That is, a zero is any complex number that makes the rational function
become identically zero. Also by definition , a complex number p is said to be a pole of G(s) if, after the
substitution s = p,
|G(p)| → ∞
where |G(s)| represents the magnitude of the rational function. Equivalently, lims→p |G(s)| = ∞. For
example,
s+2
G(s) =
s+1
−2 + 2 0
has a zero at z = −2, because G(2) = = = 0. Furthermore, the rational function has a pole at
−2
+ 1 −1
−1 + 2 1
s = −1 because |G(−1)| = = → ∞ given that division of a constant number by zero results in
−1 + 1 0
an infinitely large result.

6
Consider the rational function
2s + 4
G(s) = (1)
s2 + 4s + 3
Because the numerator and denominator are written as weighted sums of powers of s (that is, written as
standard polynomials), function (1) is said to be written in standard rational form. Noting that in this case

N (s) = 2s + 4 = 2(s + 2)
D(s) = s2 + 4s + 3 = (s + 1)(s + 3)

it follows that (1) can be written as


2(s + 2)
G(s) = (2)
(s + 1)(s + 3)
which is known as pole-zero rational form for the rational transfer function G(s). The form (2) is given the
pole-zero name because by simple inspection one concludes that G(s) has a zero z = −2 and poles p1 = −1
and p2 = −3.

Problem 8. Polynomial multiplication.


Use the MATLAB function conv to find polynomial C(s) = P (s)Q(s).
(a) Let P (s) = s + 2 and Q(s) = s + 3.

Calculate C(s) =

(b) Let P (s) = s2 + 2s + 1 and Q(s) = 3s + 1.

Calculate C(s) =

(c) Let P (s) = 1.15s3 + 2.233s2 + 1 and Q(s) = 4s + 1.

Calculate C(s) =

(d) Let P (s) = (s + 1.25)(s–3.9)(s + 1.47) and Q(s) = 4s + 1.

Calculate C(s) =

Problem 9. Calculation of rational-function zeros and poles


Use the MATLAB function roots to find the poles and zeros of the following rational functions.
Hint: find the roots of the numerator and of the denominator polynomials

7
2s3 + 6s2 − 4s + 3
(a) G(s) =
s5 + 7s4 + 9s3 + 3s2 + 5s + 3

Zeros:

Poles:

1.73s3 + 3.10s2 − 4.78s + 1.5


(b) G(s) =
s5 + 2.66s4 + 7.7s2 + 2.1s + 93

Zeros:

Poles:

Problem 10. Conversion of rational functions to the pole-zero form


Use the MATLAB command roots to assist you in converting the following standard rational functions
to their equivalent pole-zero form.
10s2 − 10s − 20
(a) G(s) =
s3 + 9s2 + 26s + 24

G(s) =

3s2 + 9s + 6
(b) G(s) =
s3 + 14s2 + 56s + 64

G(s) =

s3 + 2s2 − 4s − 8
(c) G(s) =
s4 + 9s3 + 11s2 + 6s

G(s) =

8
Problem 11. Conversion of rational functions to the rational form
Use the MATLAB command conv to assist you in converting the following standard rational functions
to their equivalent pole-zero form.
6 (s + 1) (s + 2)
(a) G(s) =
(s + 3) (s + 4) (s + 5)

G(s) =

6 (s − 1.55) (s + 0.33)
(b) G(s) =
(s + 1.78) (s + 1.55) (s + 0.27)

G(s) =

Problem 12. Rational-function multiplication.


Use MATLAB to carry out the product of rational functions G(s) = G1 (s)G2 (s).
• Hint: the numerator polynomial of G(s) is obtained by multiplying the numerators of G1 (s) and G2 (s),
and the denominator polynomial is obtained by multiplying the denominators of G1 (s) and G2 (s).
1 2
(a) Let G1 (s) = and G2 (s) = .
s+2 s+1

Calculate G(s) = G1 (s)G2 (s) =

10s 10s2 − 10s − 20


(b) Let G1 (s) = and G2 (s) = 3 .
s3+ 24 s + 9s2 + 26s + 24

Calculate G(s) = G1 (s)G2 (s) =

10s2 − 10s − 20 10s2 − 5


(c) Let G1 (s) = and G 2 (s) = .
s3 + 9s2 + 26s + 24 s3 + 9s2 + 26s + 24

Calculate G(s) = G1 (s)G2 (s) =

9
Chemical Engineering Department

University of Florida
ECH4323L/ECH 6326 COMPUTER LABORATORY EXPERIMENT No. 3B

Date Due: Student Name:


Grader: Group:

PLEASE SIGN THE FOLLOWING PLEDGE

On my honor, I have neither given nor received unauthorized aid in doing this work. I understand that the
instructor may assign a failing grade in this course as a sanction for honor-code violations.

Signature

********* Please submit this SIGNED page with your project *********

GRADING TABLE
Problem Score
1 /3
2 /3
3 /3
Average Score /9 = /100

MATLAB M-Files and Plots

Problem 13. Practice Assignment


Activate MATLAB and try out all the commands discussed in class concerning plotting, creating M-files,
and using while, for, and if structures.
Note that you can create an M-file from the MATLAB command window by selecting the menu entries
File . New . M-file. It is possible to edit an existing M-file by selecting File . Open.
You may want to seek interactive help from MATLAB on selected command. For example, to obtain a
description of the command diary, type help diary.

Problem 14. Generating MATLAB plots


Generate a plot of the function y = log10 (x) for values of x between 0.0001 and 100. Use increments of
0.01 for x. The plot must conform to the following specifications:

(i ) Plot the data using a dotted line.


(ii ) Include a title, an x-label, a y-label, and a grid. IMPORTANT: include your name and the
date as part of the title of your graph.

10
(a) Generate a pdf file of the graph using the MATLAB print command using the syntax
print –dpdf Filename
where Filename is the name that you want for the PDF file that will be produced (in this case
Filename.pdf).

The –d argument in the print command stands for the word “device”, and hence –dpdf defines a
pdf device (printer). Hence, print –dpdf is interpreted as “print using a pdf printer”. For more
information type help print. You are not required to submit an electronic copy of the PDF file.
(b) Open the PDF file created in Item (a) using a PDF reader of your choice (say, Adobe Acrobat reader,
for example) and print a hard copy. Submit the printed copy of the PDF file.
(c) Create an MS Word document that consists of 1 page. On the top of the page write the caption: “The
following figure is obtained by importing a MATLAB-created PDF file into MS Word”.

Import the PDF file created in Item (a) so that the figure appears immediately after the caption.
Submit a printed copy of this document.

If the resulting MS Word document does not contain a clearly visible graph, or if the figure appears
faint, then repeat Item (a) but using the alternative command

>‌>print –deps –tiff –r300 Filename

which will create an encapsulated postscript (EPS) file (instead of a PDF file) entitled Filename.eps
that will print in a PostScript printer with a resolution of 300 dpi (the default resolution is 150 dpi),
where “dpi” stands for “dots per inch”. The option -tiff creates a 72 dpi preview that allows the
figure to be visible in an MS Word window in a computer screen. Finally, proceed to import the
EPS file into MS Word. Submit a hardcopy of MS Word document (i.e., PDF-imported figure or
EPS-imported figure) that gives you the best result.

Hint 1: Use the MS Word menu commands Insert . Picture (details vary depending on the version of MS
Word being used).
Hint 2: To prevent the figure from automatically positioning itself in a non-desirable location, select
(you many need to right-click) the inserted figure and adjust its Properties (or select Format Picture
in certain versions). Select Layout . Keep with text. The last step will fix the picture at the insertion
point.
Hint 3: If needed, resize the figure to fit in the page. This can be done by adjusting one of the corners
of the figure, but better results are obtained by proceeding as in Hint 2 but selecting Layout . Size.
Hint 4: You can choose to center the paragraph that contains the set the figure in the middle of the
paragraph.
Remark 1: If you have a vector x in row form and you want to change it to column form you can use the
transpose command (a single apostrophe mark): x=x’
Remark 2: For on-line help on relevant commands for exercise you may type help plot, help
title, help xlabel, and help ylabel.

Problem 15. Generating a plot using an M File


Write an M-file that generates a plot of the function y = cos(x) for values of x between 0 and 6. Use
increments of 0.2 for x.
The plot must conform to the following specifications:

11
(A) Use a dash-dot line to connect the points.

(B) Include a title, an x-label, a y-label, and a grid. IMPORTANT: include your name and the date
as part of the title of your graph.
The M-file must conform to the following specifications:
(i ) The first line of the M-file starts with the comment character %, followed by a statement indi-
cating the file name.
(ii ) The second line of the M-file starts with the comment character %, followed by your name and
the date.
(iii ) The third (and optionally also the fourth) line of the M-file starts with the comment character
%, followed by a brief description of what the M file does.
(iv ) The M-file should generate a table of results that lists the values of the cosine for all the points
in the plot. For your reference, the first 3 entries in the table should appear as follows:

x cos(x)
------ ------
0 1.0000
0.2000 0.9801
0.4000 0.9211

Note that the character "x" is approximately centered with respect to the dashed lines in the first
column, and the string "cos(x)" is located exactly above the sequence of dashes on the second
column. Finally, note that the dashes in both columns are positioned in such a way that they
are aligned with the column of numbers lying below.
Remark 1: you may find useful the commands disp and num2str; type help disp and help num2str
for on-line help.
Remark 2: if your vector x is in row format, you can transpose it to a column form using the MATLAB
command: x = x’ where the prime mark (’) denotes a transposition.
(a) Print the plot and submit a hardcopy.

(b) Print the M-file and submit a hardcopy.


(c) Use the diary command (diary on), run the M-file, turn off the diary (diary off) to create
a diary file. Open the diary file using the MATLAB menu entries File . Open (or you can use
alternatively any editor, such as Xedit, etc.) and print the file using the menu entries File . Print.
Submit a hardcopy of the diary file (it should contain the table of results given in (iv ) above).

12

You might also like