Dec 04, 2025 | 492 words | 5 min read
16.2.2. Task 2#
Learning Objectives#
Read code with user defined functions. Create user defined functions in MATLAB.
Task Instructions#
Part A: Tracking User Defined Functions through MATLAB Code#
The following exercise is to be worked on as a team in-class. Work with the problems by hand first and then type the solutions into MATLAB to check them. Be prepared to show a member of the instructional team after you find the correct solutions. When you are finished, write your answer in ma2_team_2_teamnumber.pdf and save the file.
Consider the user-defined functions, fn1 and fn2, as shown below.
function [x,y]=fn1(x,y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Help description
%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = x - 4;
[y,x] = fn2(x,y);
y = x^2 - 10;
end
function [out1,out2]=fn2(in1,in2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Help description
%%%%%%%%%%%%%%%%%%%%%%%%%%%
out1 = in1 + in2;
out2 = in2 - in1;
end
The following codes are executed in the MATLAB Command window. What values do the variables x and y have?
>> x = 3;
>> y = 5;
>> [x,y] = fn1(x,y)
Part B: Creating User Defined Functions in MATLAB#
Open up the following document:
(ma2_Team_2_teamnumber.docx)
In the following exercise, you will create three user-defined functions that will be
used in Task #3 of this assignment. The background of these functions is explained in
Task #3, but is not needed to complete this task. These functions will be created in
three different MATLAB files using the MATLAB UDF file template,
ENGR133_MATLAB_UDF_Template.m.
The geometric parameters of a blind are:
\(S\) = slat spacing (\(\milli\meter\))
\(W\) = slat width (\(\milli\meter\))
\(M\) = width of slat that is illuminated (\(\milli\meter\))
\(\Psi\) = slat angle with horizontal (given in degrees)
\(\sigma\) = vertical shadow angle (given in degrees)
Additionally, the blind surface material has an absorptivity constant, \(\alpha\) (alpha). This is a dimensionless value between \(0\) and \(1\).
User-Defined Function 1:#
Create a UDF named
ma2_team_2_fractions_teamnumber.m that
calculates and returns the three fraction values \(F_1\), \(F_2\), and
\(F_3\) in a vector as [F1, F2, F3]. The inputs to this function are
\(S\), \(W\), and \(\Psi\).
Publish this file as ma2_team_2_fractions_pub_teamnumber.pdf
Sample Output#
Use the values in Table 16.3 below to test your program.
Case |
\(S\) |
\(W\) |
\(\Psi\) |
|---|---|---|---|
1 |
40 |
50 |
30 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
>> ma2_team_2_ma2_team_2_fractions_teamnumber(40, 50, 30)
ans =
0.1190 0.4393 0.4417
User-Defined Function 2:#
Create a UDF named ma2_team_2_transmission_teamnumber.m that calculates and returns \(T_D\). The inputs to this function are a vector containing \([F_1, F_2, F_3]\), and the geometric parameters \(S\), \(W,\) \(\Psi\), \(\alpha\), and \(\sigma\).
Publish this file as ma2_team_2_transmission_pub_teamnumber.pdf
Sample Output#
Use the values in Table 16.4 below to test your program.
Case |
[F1, F2, F3] |
\(S\) |
\(W\) |
\(\Psi\) |
\(\alpha\) |
\(\sigma\) |
|---|---|---|---|---|---|---|
1 |
[0.119, 0.4393, 0.4417] |
40 |
50 |
30 |
0.5 |
18 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
>> ma2_team_2_ma2_team_2_transmission_teamnumber([0.119, 0.4393, 0.4417], 40, 50, 30, 0.5, 18)
ans =
0.1341
User-Defined Function 3:#
Create a UDF named ma2_team_2_absorb_teamnumber.m that calculates and returns \(A_D\). The inputs to this function are \(F_2\), \(S\), \(W\), \(\Psi\), \(\alpha\), and \(\sigma\).
Publish this file as ma2_team_2_absorb_teamnumber.pdf
Sample Output#
Use the values in Table 16.5 below to test your program.
Case |
\(F_2\) |
\(S\) |
\(W\) |
\(\Psi\) |
\(\alpha\) |
\(\sigma\) |
|---|---|---|---|---|---|---|
1 |
0.4393 |
40 |
50 |
30 |
0.5 |
18 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
>> ma2_team_2_ma2_team_2_absorb_teamnumber(0.4393, 40, 50, 30, 0.5, 18)
ans =
0.6258
Deliverables |
Description |
|---|---|
ma2_team_2_fractions_teamnumber.m |
Your completed MATLAB code. |
ma2_team_2_transmission_teamnumber.m |
Your completed MATLAB code. |
ma2_team_2_absorb_teamnumber.m |
Your completed MATLAB code. |
ma2_team_2_fractions_pub_teamnumber.pdf |
PDF with published MATLAB code |
ma2_team_2_transmission_pub_teamnumber.pdf |
PDF with published MATLAB code |
ma2_team_2_absorb_teamnumber.pdf |
PDF with published MATLAB code |
ma2_team_2_teamnumber.pdf |
Your answers for part A of this task. |