\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

Dec 03, 2024 | 608 words | 6 min read

14.3.1. Task 1#

Learning Objective#

Learn and practice how to import data, write and run user-defined functions, and plot in MATLAB.

Introduction#

../../../../../_images/springs.png

Fig. 14.1 Spring schematic.#

Springs have many applications across most engineering disciplines. Springs are found in vehicle engines and suspensions, earthquake-rated buildings, hinged aircraft door mechanisms, farm equipment, medical devices, and more.

A commonly used spring is a helical compression spring as illustrated in Fig. 14.1. This is the “standard” coiled spring that is designed to offer resistance against an axial force (i.e., a force in the direction through the open center of the spring). You are working with a design team that is sizing compression springs for a project. You are responsible for writing a program that can determine a spring’s wire length (i.e., the length of wire used to manufacture the spring) and total mass when given information about the spring’s parameters.

You will use these equations to calculate the values you need:

(14.1)#\[L=\frac{\pi n(d_0+d_i)}{2}\]

Where \(L\) is the spring wire length, \(n\) is the number of coils in the spring, \(d_0\) is the outer diameter of the spring, and \(d_i\) is the inner diameter of the spring.

(14.2)#\[m_s=\rho L(d_0-d_i)^2\]

Where \(m_s\) is spring mass and \(\rho\) is the spring metal density. All springs in the system will be made with the same high-carbon steel. The steel, oil-tempered ASTM A229, has a density of \(\qty{7.861}{\gram\per\centi\meter\cubed}\).

Task Instructions#

Your program must work within a larger program structure, so you must write it as a function based on what you know about the spring project and the other parts of the larger program. You know the following information:

  • Your function will require two inputs: one input is the inner and outer diameters of the spring, the other input is the number of coils in the spring.

  • The diameters and number of coils must meet certain criteria:

    • The diameter input variable must be a 2-element vector and the number of coils input must be a scalar.

    • The first element of the diameter vector must be the inner diameter (i.e., the smaller diameter). The inner diameter cannot be greater than 95% of the outer diameter.

    • Both elements within the diameter vectors must be lengths between 2.5 cm and 30 cm, inclusive.

    • The spring must have at least 4 coils.

  • Your function must return two output arguments: wire length (scalar) and spring mass (scalar)

  • Finally, your function must follow the design team’s flowchart shown below.

../../../../../_images/ma3_flowchart.png

Fig. 14.2 Flowchart for the spring design analysis.#

  1. Open the template (ENGR133_MATLAB_UDF_Template.m.) and complete the header information. Save your script as ma3_ind_1_springs_username.m.

  2. In the INITIALIZATION section of the script, define any constants you will need to use.

  3. In the CALCULATIONS section of the script implement the conditions and calculations required from the flowchart above.

  4. In the FORMATED TEXT & FIGURE DISPLAYS section of the script, write fprintf() commands to display the wire length and spring mass values.

  5. Run the test cases in Table 14.9 for your function by calling it from the Command Window. In the RESULTS section of the script, paste the function call and the printed display from the Command Window for each of the following test cases. You must include the function call for each test case with the results. Suppress the output argument variables when you call the function by adding a semicolon to the end of the function call, just like with variable assignments from built-in functions.

  6. Publish your function as a PDF and name it ma3_ind_1_springs_username.pdf.

  7. Submit all your deliverables to Gradescope.

Sample Output#

Use the values in Table 14.9 below to test your program.

Table 14.9 Test Cases#

Case

Diameters (\(\centi\meter\))

Number of Coils

1

[10, 12]

10

2

[2.5, 3]

6

3

[15.75, 20]

3

4

[5, 5.8, 6.2]

12

5

[14.5, 15]

10

6

[6, 5.5]

8

7

[0.5, 2]

15

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

>> ma3_ind_1_username([10, 12], 10) Wire length: 345.58 cm Spring Mass: 10866.27 g

Case 2 Sample Output

>> ma3_ind_1_username([2.5, 3], 6) Wire length: 51.84 cm Spring Mass: 101.87 g

Case 3 Sample Output

>> ma3_ind_1_username([15.75, 20], 3) The spring must have at least 4 coils Wire length: -78.00 cm Spring Mass: -78.00 g

Case 4 Sample Output

>> ma3_ind_1_username([5, 5.8, 6.2], 12) Inputs have incorrect dimensions Wire length: -110.00 cm Spring Mass: -110.00 g

Case 5 Sample Output

>> ma3_ind_1_username([14.5, 15], 10) The inner diameter value is larger than allowed Wire length: -27.00 cm Spring Mass: -27.00 g

Case 6 Sample Output

>> ma3_ind_1_username([6, 5.5], 8) The inner diameter value is larger than allowed Wire length: -27.00 cm Spring Mass: -27.00 g

Case 7 Sample Output

>> ma3_ind_1_username([0.5, 2], 15) Diameter values must be between 2.5 and 30 cm, inclusive Wire length: -99.00 cm Spring Mass: -99.00 g