ENGR 1181 | Midterm Exam 2: Study Guide and Practice Problems Disclaimer Problems seen in this study guide may resemble problems relating mainly to the pertinent homework assignments. Reading this study guide and solving the practice problems is not a sufficient level of studying for this exam. Students should also review the relevant reading material and PowerPoint slides as questions will be asked from those places as well. Please remember that the number of “show your work” practice problems exceeds the number of “show your work” exam problems. Exam Specifications 50 Points Total - 30 points multiple choice (15 questions, 2 pts. each) o Done on Carmen using a “lockdown browser” o No other internet access is allowed. Those accessing the internet otherwise will be sent to COAM. Please review OSU’s policy on academic misconduct. o Graded automatically and entered into Carmen, your score will be visible but any missed problems will not be shown immediately after the exam is over. - 20 points – 2 “show your work” problems - o Both problems will be in MATLAB, you will create the script files. Always start your script files by displaying your name, seat number etc. and using close all; clear; clc o Make sure you assign a different name for each PDF file during the exam. o Do not use “run section” during the exam, it will not save your script file and your work will be lost! ALWAYS use “run”. Calculators are not allowed. The exam is closed book closed notes. No communication with other students is allowed. Please review OSU’s policy on academic misconduct. No use of cell phones. Name: Seat Number: __________ Content Review - Below is contained the content and learning objectives that will be tested on this exam. Not all learning objectives will be tested exactly as read, however students should use this material to keep track of what they need to be reviewing. 1. MATLAB a. Array Creation i. [a, b, c ; d, e, f] notation ii. [min : step : max] notation iii. linspace function iv. I/O Associated learning objectives Demonstrate proper usage of basic MATLAB features (e.g., the Command Window, script files, other default windows, arithmetic operations, assigning variables and names, built-in functions, help command) Demonstrate proper notation for accessing elements from previously assigned onedimensional arrays (e.g., single elements, list of elements) and two-dimensional arrays (e.g., those with rows and columns) b. Array Accessing i. Pure array accessing ii. Sub arrays iii. Using the colon operator Associated learning objectives Demonstrate proper notation for accessing elements from previously assigned onedimensional arrays (e.g., single elements, list of elements) and two-dimensional arrays (e.g., those with rows and columns) Explain that a string is a one dimensional array and can be used the same way as numeric arrays c. Array Operations (“.” Operators) Associated learning objectives Explain meaning of element-by-element operations Identify situations where the standard operators in MATLAB (when used with arrays) are reserved for linear algebra, which is not always element-by-element Apply dot operators for o The six cases where linear algebra is not element-by-element and therefore dot operators are needed to produce element-by-element calculations Name: Seat Number: __________ d. MATLAB algebra syntax (conversion from math expression) Associated learning objectives Explain meaning of element-by-element operations Identify need to translate mathematical notation into proper MATLAB syntax e. Conditional Statements and logical operators Associated learning objectives Explain how conditional statements (e.g., if-end, if-else-end, switch-case) are used to make decisions Apply logical operations correctly in arrays Analyze data using logical operators. f. MATLAB looping Associated learning objectives Use more complex ways of setting the loop index Use loops to repeat a code with conditional statements 2. Labs continued a. Solar Meter Associated learning objectives Describe and build both a calibration and solar meter circuit Convert decimal values to binary values Compare a pictorial image of a circuit to a schematic wiring diagram b. Solar Cell Associated learning objectives Identify the advantages and disadvantages of solar cells. Calculate the efficiency of a solar cell. c. Beam Bending Associated learning objectives Employ the concepts of stress, strain, and Young's modulus for structural materials. Use the stress-strain equation to calculate how applied forces deform structures. Calculate the moment of inertia of various beam geometries. Determine how beam geometry affects the stiffness and strength of beams. Identify unknown beam material through analysis and calculation of Young’s Modulus. Evaluate behavior of various beams based on material and shape. d. Wind Turbine – part A Associated learning objectives Describe the relationship between velocity (of the wind) and pressure based on Bernoulli’s Equation for incompressible flow. Calculate the power available in the wind and compare it to the power generated by a wind turbine. Summarize the characteristics of the wind tunnel and turbine. Name: Seat Number: __________ Describe the relationship between velocity (of the wind) and pressure. Determine the power available in the wind. Relate the power available in the wind to the wind speed. Compare the power generated by a wind turbine to the power in the wind. Here is a syntax guide for help in reviewing. PRINTING AND BRINING THIS TO THE EXAM IS NOT ALLOWED. MatLab Syntax Review Sheet – FOR MIDTERM 2 RELEVANT INFORMATION ONLY Current Directory – your current working directory with a list of m-files Workspace – current list of MatLab variables and values Command History – past commands that have been typed and executed Command Window – where commands can be entered Editor Window – where you write and run MatLab script files Don’t forget that typing “help” into MATLAB will assist you with specific functions and is allowed during the exam “show your work” problems! MatLab Tips >> clc clear command window; does not clear memory >> cmd displays the result of a command in the command window >> cmd; does not display the result in the command window >> cmd1, cmd2 displays both results >> cmd1; cmd2 displays last result only clear clears ALL variables from memory clear x,y,z clears only x, y, and z variable names 1. must begin with a letter 2. are case sensitive contain letters, numbers, and _ math precedence ... (ellipsis) highest → ( ) ; ^ ; * / ; + - ← lowest 3. extends a command to the next line up arrow ↑ scrolls backward through previous commands down arrow ↓ scrolls forward through commands help abcd help on the subject "abcd" ( doc abcd -- works too ) Name: Seat Number: __________ Numeric Display Formats format short nnn.1234 format long nnn.12345678901234 (14 decimal places) format short e n.1234e+001 format bank nnn.12 Input / Output Commands disp( ' any text ' ) displays ' any text ' in the command window fprintf('Text = %i,%f',k,x) formatted output – prints "Text = integer and fixed point" x = input( ' any text ' ) asks the user to enter a value for x from the keyboard 1-D Array (row and column vectors) scalar, s is a single number (a 1 x 1 array) vector, v is a 1 row x n column array a list of numbers v_list = [ a b c ] or = [ a , b , c ] row vector v_row = [ a b c ] or = [ a , b , c ] column vector v_col = [ a ; b ; c ] constant spacing v_space = [ first : space : last ] single spacing v_1space = [ first : last ] vector with n terms, evenly spaced v_nterms = linspace( first, last, n ) transpose of a vector v_col = v_row ' value of the ith term v(i) Addition / Subtraction z = x y z = [ 𝑥1 𝑦1 , 𝑥2 𝑦2 , 𝑥3 𝑦3 ] Multiplication / Division z = x .* y and z = x . / y Exponents z = x .^ y z = [ 𝑥1 . ^ 𝑦1 , 𝑥2 . ^ 𝑦2 , 𝑒𝑡𝑐. ] max(v) or min (v) Returns largest / smallest element of v length(v) Returns the length (# of elements) in vector v mean(v) or sum(v) Returns average value / sum of elements in v 2-D Array (matrix) Matrix, A is an r (rows) X c (columns) array A( r, c ) is the value of the element ( r, c ) in A A( r, c ), in rows A = [ row1 ; row2 ; row3 ] A( r1:r2, c1:c2 ) retrieves values in row and column ranges Example: A(1:3, [1 4 6]) means rows 1-3 and columns 1,4,6 of matrix A Name: Seat Number: __________ Logic – Conditional and Relational Operators Less than / Greater than < / > Less than equal to / greater than equal to <= / >= Equal to / Not equal to == / ~= TRUE statement / FALSE statement 1 (or any non-zero number) / 0 & AND ( Example: A & B ) TRUE when A and B are both true | OR ( Example: A | B ) TRUE when either A is true or B is true ~ NOT ( Example: ~ A ) TRUE if A is false / FALSE if A is true Operator precedence ( high low ) ( ) ^ ~ */ +– > < >= <= == ~= & | Conditional Statements if conditional statement Works when there is only one command group Command Group end if conditional statement Command Group 1 else If the conditional statement is "True", then do "Command Group 1". It the conditional statement is "False", then do "Command Group 2". Command Group 2 end if ( conditional 1 ) "If – elseif – else – end" do Command Group 1 elseif ( conditional 2 ) do Command Group 2 elseif ( conditional 3 ) do Command Group 3 When there are more than two command groups, you can use this form with elseif Elseif = if not the first, do the second, or if not the second, do the third, etc. else do Command Group 4 end The "else" never has a conditional and is optional. Name: Seat Number: __________ Loops k = first : step : last Loop index variable = first value : step size : last value Example of a loop in a script file: v1 = [ 0 : 5 : 25 ] ; % Define the vector v1 for i = 1 : length (v1) % The step size is 1 This loop calculates a new vector v2 from an existing vector v1. Note that the loop uses vector addressing. % Each pass in the loop v2(i) = v1(i) ^ 2 ; % calculates a new element % in the vector v2 end disp(v2) Common Functions sqrt(x) square root of x exp(x) 𝑒 𝑥 = exponential function abs(x) absolute value of x log(x) natural log of x log10(x) log base 10 of x factorial(x) factorial function [ x! ], where x is a positive integer sin(x) / cos(x) / tan(x) trig functions with angle in radians sind(x) / cosd(x) / tand(x) trig functions with angle in degrees round(x) Round to the nearest integer fix(x) Round toward zero ceil(x) Round toward infinity floor(x) Round toward negative infinity rem(x,y) Equals the remainder of x divided by y if rem(x,y) == 0 Conditional test that is true when x is a multiple of y sign(x) Signum function – returns [1 if x>0], [-1 if x<0], [0 if x=0] Name: Seat Number: __________ Practice Problems Problem 1: Work out Problem Use MATLAB to create a script file to accomplish the task described below. Run the script file for all three cases using a “for” loop. Save pdf files of both the script file and the command window. Write a script file to calculate distance traveled by a water balloon after asking the user for the initial speed and angle of launch. The program should determine the distance traveled by the following equation: 𝐷= 𝑣 20 sin(2𝜃) 𝑚𝑒𝑡𝑒𝑟𝑠 𝑔 Have the program output the distance traveled using fprintf. Use g = 9.81 m/s2. The input cases are: Launch Number Launch 1 Launch 2 Launch 3 Initial Speed (m/s) 50 25 36 Angle of Launch (degrees) 30 60 45 The script file should produce output for each launch that looks like: For Launch X the distance traveled was () meters Don’t forget to start your script file with disp(‘Your Name, seat #’) Name: Seat Number: __________ Problem 2: Work out Problem Use MATLAB to create a script file to accomplish the task described below. Run the script file for all three cases using a “for” loop. Save pdf files of both the script file and the command window. Use your knowledge of circuits to write a MATLAB script file that calculates values for all three currents. Ask the user for the power supply and three resistor values for each run. Have the program output the three currents using fprintf. The input cases are: Power Supply (V) 12 V 9V 6V R1 (Ω) 50 100 150 R2 (Ω) 75 50 80 R3 (Ω) 90 75 120 The script file should produce output for each power supply that looks like: For the power supply of () V: I1 was () A, I2 was () A, I3 was () A. Don’t forget to start your script file with disp(‘Your Name, seat #’) Name: Seat Number: __________ Problem 3: Work out Problem Use MATLAB to create a script file to accomplish the task described below. Run the script file for all four cases using a “for” loop. Save pdf files of both the script file and the command window. Terminal Velocity is defined as the velocity at which an object falling through a fluid has its weight equal to the drag force on that object. Write a MATLAB script file to calculate terminal velocity of various objects falling in air. Ask the user to input the mass, drag coefficient and frontal area “A” of each object. Print each objects terminal velocity to the command window using fprintf. At the end of the program, use conditional statements to determine and print using fprintf to the command window which object has the fastest terminal velocity. 2𝑚𝑔 𝑉𝑡 = √ 𝜌𝐴𝐶𝑑 Common Constants: g = 9.81 m/s2, ρair = 1.29 kg/m3 The input cases are: Object #1 #2 #3 #4 m (kg) 20 40 30 50 Cd (unitless) 0.48 0.50 0.49 0.39 The script file should produce output for each object that looks like: For object #(): the terminal velocity was () m/s. The end of the program should produce an output that looks like: Object #() had the maximum terminal velocity of () m/s. Don’t forget to start your script file with disp(‘Your Name, seat #’) A (m2) 0.50 2.00 3.00 0.75 Name: Seat Number: __________ Problem 4: Work out Problem Use MATLAB to create a script file to accomplish the task described below. Run the script file using a while loop. Save pdf files of both the script file and the command window. A prosthetic foot must be designed so that the correct spring rate is achieved for the patient to walk normally. For a particular design, the spring stiffness k (with units of lb/in) can be expressed as: 𝑘= 𝐸𝑡 3 3𝑡 3 + (𝐶1 + 6𝑡 3 )2 − 450 The variable t is the spring thickness (inches), C1 is a constant with value 850 for this design, and E is the modulus of Elasticity (200 GPa for Steel). Write a script file to determine an appropriate thickness of the spring to give an overall stiffness of at least 1000 lb/in and Steel as the material. Use the while loop to check each value of a vector of t ranging from 0 to 0.5 in 1000 increments. When the value of t is found, print it to the screen with the resulting spring stiffness. The script file should produce output that looks like: The minimum spring thickness required is () inches producing a spring stiffness of () lb/in. Don’t forget to start your script file with disp(‘Your Name, seat #’) Name: Seat Number: __________ 1. The modulus of elasticity is defined as: a) The ratio of yield stress to strain (ys/ε) in the plastic region. b) The slope of strain to stress (ε/σ) in the elastic region. c) The slope of stress to strain (σ/ε) in the elastic region. d) The ratio of stress to strain (σ/ε) in the plastic region. e) The slope of stress to material stiffness (σ/E) in the elastic region. 2. Write the command to create a vector, X, starting at 50 and ending at 5 with values every 0.2, which displays the created vector in the command window. ___________________________________________________________________ 3. What is the command to use a built-in system function to find the average of the vector X from question #1 above, assign the value to RESULT, and suppress output in the command window? _____________________________________ 4. If C = [1 2 3 4] and D = [7 8 9], what is the command to create a single row array X with the elements of C and D (afterwards X = [1 2 3 4 7 8 9])? ___________________________________________________________________ 5. Write the command to find the sine of 30°? ______________________ 6. The Solar Meter Lab used a Trim Pot (Trim Potentiometer) in the breadboard setup. When you turn the knob on the TrimPot, which variable is adjusted? _________________________ Name: Seat Number: __________ 7. Given that x=[1 2 3 4; 5 6 7 8; 9 10 11 12] has been assigned, what would be the result of y=x(2:3,[1 2 4])? ________________________________________ 8. Write a single statement that prompts the user with 'Please enter the day of the week: ' Assign the results to a variable called 'today', suppressing any outputs to Command Window. ____________________________________________ 9. Given a 10 by 3 matrix M, write a single command that extracts all members of the 3rd column of matrix M and assigns it to a vector called M_col_3 using the colon operator. _________________________________________ 10. A vector x is defined in MATLAB by: x = [1:2:7]; x2 Consider the equation: y = (x+3) Write a MATLAB command that creates a vector y where each element has a value calculated by the equation with the corresponding element in the vector x. __________________________________________