MEC E 390 – Summer 2020 Lab #2 Due: May 26, 2020
Instructions:
Submit your assignment as a single PDF file (for the Main Report) through eClass. In
addition, upload all code files (and data files, if any) to eClass.
...
MEC E 390 – Summer 2020 Lab #2 Due: May 26, 2020
Instructions:
Submit your assignment as a single PDF file (for the Main Report) through eClass. In
addition, upload all code files (and data files, if any) to eClass.
Answer all questions in the Main Report. In an Appendix, include print outs of all codes
used and refer to them in your Main Report. Plot figures should be included in the Main
Report.
Questions have weight as indicated. Up to 30 points may be deducted for incomplete or
disorganized Main Report.
Late assignments will not be accepted.
20/100 1. Write a Matlab function called plotfunc that does the following:
(a) Receives the name of another Matlab function as an input (e.g. func01, which
calculates ?(?)).
(b) Plots the function, including a horizontal line at ?(?) = 0, so that the user can
visually see the roots (see fplot()).
(c) Performs the plot inside a while loop that begins with a default interval,
−75 ≤ ? ≤ 75 and keeps asking the user for new interval limits until the user is
satisfied and the loop ends.
Hint: use input() to accept input from the user through the command window.
Hint: create your function (M-file) with:
function plotfunc(funcname)
...
fplot(@(x) funcname(x),[a,b])
Then call it in your command window with:
>> plotfunc(@(x) func01(x))
20/100 2. Test your plotfunc with the function
?(?) = −3.1?3 + 28.5?2 − 3.2? − 100.4
Find an interval and produce a single plot that clearly shows the three roots.
Hint: Note the dot-operators used to perform element-wise algebraic operations
function y = func01(x)
% Function for Lab 2
y = -3.1.*x.^3 + 28.5.*x.^2 - 3.2.*x-100.4
[Show More]