MATLAB TEST1
CVEN308
Test1 Fall 2016
Please submit your m codes along with any generated graphs and outputs in MATLAB all in ONE WORD file (Please print
this word file and attach this page as the cover page, and bring the hardcopy with you to next class). I will NOT accept late
soft copy submissions. Your word file, containing all your code, results from MATLAB command window and figures (save
your figures as jpg files and then insert then into word) must be submitted by 12:30 on Wednesday September 21 st . A hard
copy of your work, with this page serving as the first page, SIGNED AND DATED, is due in my office on Wednesday at
12:30 p.m.. If something prohibits you from turning in the hard copy by the due time, make sure you let me know as soon
as possible and please make sure the soft copy is already submitted by 12:30 p.m on Wednesday September 21 st .
I _________________________ declare that this is solely my work and I have not sought help nor provided help to anyone. I understand that cheating in anyway will result in a grade of F in the course. Signature:_______________________________________ Date:__________________________________ ______________________________________________________________________________________
1. [20 pts] You are testing a theory which says that the output displacement of a measurement device should vary with time according to the equation:
( ) ( )
So far, you have measured the following set of experimental data for D and t:
t (min) 0 1 1.5 2 2.5 3 4 5 6 8 10
M (mm) 0.01 .3 .1 -.8 -1.5 -2.2 -2 1.9 5.1 -1.3 -8
1) Plot the function ( ) in the range of . Use increment of 0.1. 2) On the same plot, aslo plot the above Data (M versus t).
3) Add a title, label the axes, and use proper legends appropriately. Submit the graph and the m file
(both copied in your word file) you have produced to produce the plot.
_____________________________________________________________________________________
2. [20 pts] Write a MATLAB function that can be used to solve a quadratic equation if answers are real
numbers (you have to do following steps):
0432 2
cbxax . The inputs to the function are the three coefficients a, b, and c.
. Check if the equation has real solutions. If there are no real solution the program should display
‘THERE ARE NO REAL SOLUTIONS’, then quit the program.
. Otherwise, calculate the solutions and display them as shown in the following example ( use the
fprintf command showing each solution with 4 decimal points). As example:
‘The solutions are -3.4135 and 9.7435’
.Try to solve two quadratic equations with coefficients: [a, b, c] = [ 1 , 1, -4 ] and [a,b, c] = [ 5 -1
3 ]
Submit the m file for your function, and the results of both test runs done in MATLAB (again copy
and paste them in the word file)
3. [15 pts]
a) Write a function m-file that will calculate the function f(x ). x
exf
)(
b) Calculate f(1) in MATLAB and print it in with 15 decimals.
c) The taylor series for the function f(x) is given as
...!/)1(...24/6/2/1)( 432
nxxxxxexf nnx
If we only take 6 terms (including constant term) of this series to compute f(1), what is the true
percentage error? Use answer in part (b) as true answer.
______________________________________________________________________________
4. [10 pts] Answer the following questions (keep your answers short and precise)
a) Explain the differences of operators ‘ * ’ and ‘ .* ’ in MATLAB.
b) The following MATLAB script is written in MATLAB by another user but when you try to use it
function value generate error message. Please correct these statements so it will generate y(x) on the
domain, x from 0 to 2π.
xx
xe xy
x
3
)(cos )(
3
2
The MATLAB script x=linspace(0,2pi);
y(x)= e^x*cos^2(x)/x^3+3x
____________________________________________________________________________________
5. [15 pts] Develop a MATLAB function that will compute the following function. Test your function for t =
7, 15, 25 and 100. Include your m file and the output of your tests in the word file.
( ) {
( )
( )
Plot the function in the range of -4