You are on page 1of 5

ME

2115 Final Project, due December 7, 2015 (11:59PM)

pg 1/5

This project is the comprehensive Final Exam for this course:




Instructions
This project is to be done by each student individually. Cheating will not be tolerated.
Students who submit similar work risk incurring a penalty that ranges from receiving a
reduced grade, up to receiving an F for the course. All academic integrity violations will be
referred to the Office of Student Conduct.

Before uploading and submitting your project, you must agree that you have followed the
honor code, by completing a one question Blackboard Test, in which you answer True to
the following:

Honor Code - TTU ME Department
I hereby certify that I will follow the Code of Student Conduct as defined by the
University and the Department, that I will not cheat nor will I condone cheating.

To solve these problems, you may use: anything posted on Blackboard for this class, your
textbook, and your notes. You will not need any new material to complete the project.
Searching MATLAB documentation is acceptable, but only functions that are in the base
MATLAB package are allowed. If you are unsure, please ask. No outside code is acceptable,
and this includes code found on the Internet.

Grading
Your grade is determined using the files you submit on Blackboard. It is based on
Percentage of Cody tests passed
Percentage of hand testing passed
Code documentation please follow posted guidelines
Use of good programming techniques

Code uploaded to Blackboard that does not run will receive a testing grade of zero

Remember
1) Take online Honor Code quiz.
2) Submit code on Cody Coursework.
3) Follow submission instructions on Blackboard
Name the M-files exactly as instructed. Files not named correctly will
receive a grade of zero.
4) Upload all M-files & pdf files to Blackboard in order to receive full credit for your
work.

ME 2115 Final Project, due December 7, 2015 (11:59PM)

pg 2/5

Part 1a: Evaluating a discontinuous piecewise function



Write a MATLAB function M-file named FinalPiece to evaluate the following piecewise
function:

04
=

4 4 < 6
!
4

>6


Examples:
>> FinalPiece(3)
ans =
1.7321
>> Y = FinalPiece(5.5)
Y =
-4
>> yy = FinalPiece(10)
yy =
-25

Input Restrictions & special cases:

The function should return a red error message for the following conditions.

Any input is nonscalar


Any input is less than zero




Publish all three sample cases as pdf, and upload both FinalPiece.m and
FinalPiece.pdf to Blackboard



ME 2115 Final Project, due December 7, 2015 (11:59PM)

pg 3/5

Part 1b: Plotting a discontinuous piecewise function



Write a MATLAB script M-file to generate a plot of the discontinuous function as shown:



Code Requirements:

The script file must call (use) the function FinalPiece to plot the piecewise
function. No credit will be given if the plot is generated any other way.
Use an open circle for inequalities, and closed circle for equalities
Plot smooth, separated curves
Use the plot command onlyno other MATLAB plotting functions are permitted.

Publish the script file as FinalPiecePlot.pdf. If the plot does not show in the pdf file,
you will receive a grade of zero for this part of the assignment.

Helpful hints
Remember to suppress output in both the function & script files.
Multiple plot commands will be needed.
Here is code to plot a filled red circle at x=2 & y=3:

plot(2,3,'ro','markerfacecolor','r')
Publish as pdf, & upload FinalPiecePlot.m & FinalPiecePlot.m to Blackboard

ME 2115 Final Project, due December 7, 2015 (11:59PM)

pg 4/5

Part 2a: Determining Greatest Common Divisor / Least Common Multiple



Write a MATLAB function M-file named GCD_LCM that accepts two positive integers, and
computes their greatest common divisor and least common multiple.

Example:

>> [g,l]=GCD_LCM(54,24)
g =
6
l =
216

Code Requirements:

You may not use MATLAB built-in functions gcd, lcm or rem. No credit will be
given if these, or any similar functions, are used. Please ask if you are not sure.

Input Restrictions & special cases:
The function should return a red error message for the following conditions.

Any input is not positive


Any input is not an integer


Part 2b: Table of GCD & LCM

Write a MATLAB script GCD_LCMtable to print a table of 10 randomly-generated
numbers, and their gcd & lcm, using your function GCD_LCM. Here is the code to use for
generating random numbers:

Sample Results
a = randi([10 30],[1,10]);

b = randi([10 30],[1,10]);
a
b
GCD LCM
30
10
10
30
21
28
7
84
Code Requirements:
20
29
1
580

14
26
2
182
You must use function GCD_LCM. No credit
20
12
4
60
will be given if not used.
23
15
1
345
Do not use the table function
24
17
1
408
18
17
30

24
12
25

6
1
5

72
204
150

Publish the function as pdf using the sample case



Publish the script as pdf.
Upload files GCD_LCM.m, GCD_LCM.pdf, GCD_LCMtable.m, GCD_LCMtable.pdf

ME 2115 Final Project, due December 7, 2015 (11:59PM)

pg 5/5

Part 3: Floating zeroes


Write a MATLAB function M-file names FloatZero that has a matrix of any size as input,
and pushes all of the zeroes in the matrix to the top (or front). All other numbers remain in
their original order.

Examples:

>> a = [9 0 4;0 7 6;5 7 8;1 4 0]
a =
9
0
4
0
7
6
5
7
8
1
4
0
>> FloatZero(a)
ans =
0
0
9
7
5
7
1
4

0
4
6
8

>> FloatZero(b)
ans =
5
0
4
-1

2
1

0
0

4
-6

>> FloatZero([7 0 8 0 2 0 7])


ans =
0
0
0
7
8

>> FloatZero([1 0 2 0 3]')


ans =
0
0
1
2
3

Code Requirements:

No vectorization is allowed, nor any functions, such as find, that work on an entire array.

Helpful hints

Although you are not sorting the entire array, researching the bubble sort algorithm
could be useful. This does not mean cut and paste MATLAB code that you might find!


Publish the first sample case as pdf. Upload files FloatZero.m & FloatZero.pdf

You might also like