0% found this document useful (0 votes)
150 views

Holly Moore MATLAB For Engineers, 3rd Edition CHAPTER 8

Uploaded by

Dewi R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
150 views

Holly Moore MATLAB For Engineers, 3rd Edition CHAPTER 8

Uploaded by

Dewi R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
MATLAB — HW CHAPTER 5 Problem: S.1_A sensor that monitors the temperatize of backyard hot tb records the data shown in Table 85. Table 8.5 Hot Tub Temperature Date Tine of Day __Temporatvre, F (0000 100 100 101 zu tz 2.00 toa 400 109 0500 Joa 06.00 low 7.00 tos a00 106 oF00 106 1009 108 1100 tos 1200 toa 1300 toa 1409 101 1500 100 1600 %9 17.00 oo 1800 oz 1900 104 2000 106 21-00 107 2200 los 2300 oe 2400 toa (a) The temperanare should never exceed 105°F.Use the #nd fetion to find dhe index numbers of the temperatuces that exceed the maximum allowable temper (b) Use the Length function wih the resulls from part (a) © devermine how many times the maxim allowable temperature was exceeded. (©) Determine at what times the temperature exceeded the maximum allovable temperature, using the index mumbers found in part (2) (2) The temperature should never be lower than 102°E Use the Eid func tion together with the Lengths function to determine how many times the temperature was les than the minimum allowable temperacure. (e) Determine at what times the temperature was less than the minimum allowable temperatare. (8) Determine at what times the temperature was within the allowable limits (ie. between 102°F and 105'T, inclusive) (2) Use the max function o determine the maximum temperatute reached andl the ime at which it occurred. MATLAB — HW CHAPTER 5 Script: ‘temp = [100, 161, 102, 103, 103, 104, 104, 105, 106, 106, 106, 105, 104, 103, 101, 100, 99, 1¢@, 102, 104, 106, 107, 105, 104, 104]; time = [0:24]; Find ‘temp>1@5) Tength(a) time(a) Length( Find(temp<102)) ‘time Find (temp162)) Find(tempe=105 & temp>=102); time(x) gi = max(temp) [val, idx] = max(temp); g2 = time(idx) Output: b 5 c a 9 1 2 2 d 6 e eo 1 mm 1 w ow fe. 2 3 4 S$ 6 7 WM 412 13 1 19 2 2 24 gi 107 g= aa MATLAB — HW CHAPTER 5 Problem: 8.6 Create a function called g that satisfies the following criteria: Forx<—m, (x) =-1 Forx=—wandx= 7, g(x) Forx> 7, a(x) =-1 Plot your results for values of x from 2x to +2, Choose your spacing to create a smooth curve. Script: function g = g(x) ind_1 = find(x<-pi); ind_3 = find(xspi); x8 = x(ind_3); L3 = length(ind_3); g3 = -1ones(1,11)3 8 = [et g2 83) Output: Problem: MATLAB — HW CHAPTER 5 SAT The inverse sine (asin) and inverse cosine (acos) functions are valid only for inputs between —1 and +1, because both the sine and the cosine have values only between —1 and +1 (Figure P8.11), MATLAB® interpret the result of acin or acos for avalue outside the range as a complex number. For example, we might have acoa(-2) 3.adas = 1.21708 which is 2 questionable mathematical result. Create a function called my_ ‘asin that accepis a single value of x and checks to see if it is between —T and +1(-1< =x < =1), If is ouside the range, send an error message to the screen. If it is inside the allowable range, return the value of “The sine function angle Script: disp(x) else end value = input('Enter the value between -1 to 1: Af value >= -1 & value <= 1 x = asin(value) disp(‘Error. Please input another value between -1 to 1") Output: Problem: MATLAB — HW CHAPTER 5 8.12 Create a program dat prompis the user to enter a scalar value for the out side air temperature. If the temperature is equal to or above 80°F, send a ‘message to the command window telling the user to wear shorts. Ifthe tem- perauure is between 60°F and 80°F send a message to the command window telling the user that it is a beautiful day. If the temperature is equal to or below 60°F, send a message to the command window telling the user to wear a jacket oF coat Script: ‘temp = input (‘Enter the outside temperature in fahrenheit: if temp>=8@ disp(‘Wear a short! The outside is hot. elseif temp<80 & temp>60 disp(‘It is 2 beautiful day. Enjoy!') elseif temp<=60 disp(‘Please, wear a coat or jacket.") end Problem: B16 Ava local universiy, cach engincering major requires a different number of credits for graduation, For example, recently the requirements were a8 follows: (Civil Engineering 190 Chemica gineering 190 Computer Engineering a2 Flanval Fagneerng 168 Mechanical Engiesing 129 Prompt the user to select an engineering program from a menu, Use a ewitch/case structure to send the minimum number of credits required for graduation back to the command window. Script: EngMajor = menu('Select an engineering program Listed below:", ‘Civil’, ‘Chemical’, ‘Computer’, Electrical’ ‘Mechanical’ ); disp( ‘Minimum number of credits required for graduation : ') switch EngMajor case 1 MATLAB — HW CHAPTER 5 disp 30) case 2 disp('130") case 3 disp('122") case 4 disp('126.5") case 5 disp('129") end Output: eR z ti) i ae If select Civil, the result will be: Minimum number of credits required for graduation 130 If select Chemical, the result will be: Minimum number of credits required for graduation 130 If select Computer, the result will be: Minimum number of credits required for graduation 122 If select Electrical, the result will be: Minimum number of credits required for graduation 126.5 If select Mechanical, the result will be: Minimum number of credits required for graduation 129

You might also like