Answered step by step
Verified Expert Solution
Question
1 Approved Answer
to check for correct homework answers 1) Rewrite the following switch statement using if-elseif-else statemen. Assume that there is a variable letter and that it
to check for correct homework answers
1) Rewrite the following switch statement using if-elseif-else statemen. Assume that there is a variable letter and that it has been initialized. switch letter case 'x' disp('Hello') case 'y' disp('Yes') case 'e' disp('Quit') otherwise disp('Error') end 2) In chemistry, the pH of an aqueous solution is a measure of its acidity. The pH scale ranges from 0 to 14, inclusive. A solution with a pH of 7 is said to be neutral, a solution with a pH greater than 7 is basic, and a solution with a pH less than 7 is acidic. Write a script that will prompt the user for the pH of a solution, and will print whether it is neutral, basic, or acidic. If the user enters an invalid pH, an error message will be printed. 3) Write a script that will prompt the user for a temperature in degrees Celsius, and then an 'F' for Fahrenheit or 'K' for Kelvin. The script will print the corresponding temperature in the scale specified by the user. For example, the output might look like this: >>Enter the temp in degree C: 29.3 >>Do you want K or F? F >>The temp in degrees F is 84.7 The format of the output should be exactly as specified above. The conversions are: F = C+32 K = C + 273.15 4) A file called "hightemp.txt" was created some time ago which stores, on every line, a year followed by the high temperature at a specific location for each month of that year. For example, the file might look like this: 89 42 49 55 72 63 68 77 82 76 67 90 45 50 56 59 6268 75 77 75 66 91 44 43 60 6060 65 6974 70 70 As can be seen, only two digits were used for the year (which was common in the last century). Write a script that will (1) read this file into a matrix, (2) create a new matrix that stores the years correctly as 19xx, and (3) then write this to a new file called "Year2000.txt". (Hint: add 1900 to the entire first column of the matrix.) Such a file, for example, would look like this: 1989 424955 72 63 68 77 82 76 67 1990 45 50 56 59 62 68 75 77 75 66 1991 44 43 60 60 60 65 69 74 70 70 5) Write a function nexthour that receives one integer as the input argument, which is an hour of the day, and returns the next hour as the output argument. This assumes a 12-hour clock; so, for example, the next hour after 10 would be 11; but the next hour after 12 would be 1. Here are two examples of calling this function. >> nexthour (3) ans = 4 >> nexthour (12) ans = 6) Write a function calc_area that will calculate and return the area of a rectangle. Pass the length and width to the function as the input arguments and return the area as the output argument. Your function should check if any of the two inputs is negative. If that's the case, the function should return -1 as the output. An example execution of this function: >> area=calc_area (4.0, 3.0) area = 12.000 >> area=calc area (4.0, -3.0) area = -1 7) Bonus (10pts extra credit) Write a function to merge two vectors Vecl and Vec2. The function should return a new vector with Vec2 in the middle of Veci. For example, >>Vecl = [1 2 3 4 5 6); >>Vec2 = [10 20 30]; >>NewVec = Merge (Veci, Vec2) NewVec = 1 2 3 10 20 30 4 5 6 >>Vecl = [1 2 3 4 5]; >>Vec2 = [10 20 30]; >>NewVec = Merge (Veci, Vec2) NewVec = 1 2 10 20 30 3 4 5Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started