Professional Documents
Culture Documents
HOMEWORK #4
Due: Class 4b
0. Reading Assignment
Ideas to Innovation Textbook:
Chapter 26: pp. 589-597.
Mathworks Tutorials (Optional but Recommended): Much (but not all) of the content
in the above reading is represented visually in the following Interactive MATLAB
Tutorial materials available through the MathWorks website,
www.mathworks.com/purduefirstyear/matlabtutorial. The recommended segments for
this week are:
Programming in MATLAB
Flow and Loop Control
o Flow Control
o Writing Conditional Statements
ENGR 13200 Ideas to Innovations Part II Spring 2011
Line
Code
#
1 function [vol,area] = cone_calcs(r,h)
2 % This function computes the volume and surface area
3 % of a right-circular cone.
4 % INPUTS: the scalar radius r of the circular base
5 % the scalar height h of the cone
6 % OUTPUTS: the scalar volume V of the cone
7 % the scalar area A of the cone
8
9 if r=<0 || h<=0
10 error(‘The cone must have positive dimensions’)
11
12 base = pi*r^2; % area of base circle
13 sides = pi*r*sqrt(r^2 + H^2); % area of the sloped sides
14 else if
15 V = 1/3*base*H; % volume
16 A = sides + base; % total surface area
17 end
18
ENGR 13200 Ideas to Innovations Part II Spring 2011
1. What does she/he need to type in the MATLAB Command window to run this user-
defined function for a cone with a height of 4 cm and radius of 3 cm?
>>
2. When you type the command from step 1, it results in an error message. Identify
THREE (3) errors in the code using the table below. Clearly indicate the line number
of the error, describe the error and how it could be fixed. Each error counts as one,
even if there are multiple errors on the same line.
Line number What is the error? How could it be fixed?
Deliverables: A hard copy printout of the command to run the user-defined function
and the three errors identified above.
Write a MATLAB function that determines the correct phases that may exist for a given
mass % of B and temperature. The input arguments for the function are the mass % of B
and the temperature. There are no output arguments for this function.
1. Draw a flowchart that uses conditional statements to determine the correct phases
based upon the mass % of B and the temperature.
2. Open the function_header_template.m file in the MATLAB editor and save as
phases_yourlogin.m. Modify the Comments section for this problem.
3. Under the INPUT section of your function, assign the values in the problem statement
that determine the phase boundaries which are fixed (and not known to most users).
4. Under the CALCULATION section:
a. Use conditional statements to check that the user has entered valid inputs.
b. Use conditional statements to direct the program to the correct phase based on the
composition and temperature entered.
5. Under the OUTPUT section, use the fprintf command to restate the input values and
display the result formatted as:
“For ##.# mass % B at ###.# degrees C, the phase is your phase result.”
Remember to indicate if the provided conditions are on the eutectic line or at the
eutectic point.
6. Test your function at the command line using the following test cases. Using
comments in the OUTPUT section of your function, paste what is displayed by your
function (if you turn in results you know are wrong, please say so and indicate what is
not working properly):
a. 400 °C, 12% B c. 280 °C, 60% B
b. 300 °C, 35% B d. 100 °C, 110% B
ENGR 13200 Ideas to Innovations Part II Spring 2011
Deliverables:
1. Flowchart for your function from step 1.
2. Hardcopy printout of your phases_yourlogin.m file.
3. Electronic submission of your phases_yourlogin.m file to your Faculty Instructor’s
Assignment Drop Box on Blackboard.
of your team's rules are to be entered on this page. To add each item to your Code, select
the “Create New Item …” button at the bottom of the page. Be sure to designate whether
the item added is a team or individual item. Unlike other online assignments, you will be
able to go back to your Code of Cooperation and edit your items.
Once your team has completed your Code of Cooperation, print out one copy for
submission. Each team member must sign his/her name directly next to his/her name at
the top of the Code. Your signature signifies that you actively participated in the creation
of the Code of Cooperation and that you agree to abide by the rules set forth. Failure to
collect all team members’ signatures will result in a 0 on the assignment.
You will use this online version of your COC to perform your peer and team evaluation
in a few weeks. To ensure that the evaluation goes smoothly, each member of your team
must test his/her own access to your team's Code of Cooperation once your team has
begun entering your team's rules. Should you have access problems (e.g. you are not
accessing your team's Code, your team number is incorrect, or the members of your team
are not correct), contact Chell Nyquist (nyquist@purdue.edu) immediately. All
correspondence with Chell Nyquist must include ENGR 13200 and section number, your
team number, and your Purdue career account login.
Deliverable: Your team must submit one hardcopy printout of your Code of
Cooperation for your entire team. Be sure that your entire Code of Cooperation fits on
your printout. To do this, you may have to use options under the File menu, including
the Page Setup... options or the Printer Properties under Print... Each team member
must sign the Code of Cooperation.