====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:fall-2014:math445:hw4 [2014/10/06 12:52] gibson |
gibson:teaching:fall-2014:math445:hw4 [2014/10/10 09:33] (current) gibson |
||
---|---|---|---|
Line 7: | Line 7: | ||
**Problem 3:** Write a function ''decimal2hms'' that converts a time in decimal hours to hours, minutes, and seconds. Use it to compute the hours, minute, and seconds equivalent of 18.782 hours. | **Problem 3:** Write a function ''decimal2hms'' that converts a time in decimal hours to hours, minutes, and seconds. Use it to compute the hours, minute, and seconds equivalent of 18.782 hours. | ||
- | **Problem 3:** Write a function ''polar2cartesian'' that converts polar coordinates ''r, theta'' to Cartesian coordinates ''x,y''. Use it to compute the Cartesian coordinates of ''r=2, theta=pi/6''. | + | **Problem 4:** Write a function ''polar2cartesian'' that converts polar coordinates ''r, theta'' to Cartesian coordinates ''x,y''. Use it to compute the Cartesian coordinates of ''r=2, theta=pi/6''. |
- | **Problem 4:** Write a function ''cartesian2polar'' that converts Cartesian coordinates ''x,y'' to polar coordinates ''r, theta''. Use it to compute the polar coordinates of ''x=2, y=3''. | + | **Problem 5:** Write a function ''cartesian2polar'' that converts Cartesian coordinates ''x,y'' to polar coordinates ''r, theta''. Use it to compute the polar coordinates of ''x=2, y=3''. Hint: use the arctangent function ''atan'' to compute ''theta'' from ''x'' and ''y''. |
- | **Problem 5:** It is likely that for problem 4 you used an inverse trigonometric function to get the value of ''theta'' from ''x'' and ''y''. Are there any special values of ''x,y'' for which this calculation would fail? Revise ''cartesian2polar'' function so that it uses an ''if-else'' statement in order to work around this problem. | + | **Problem 6:** Are there any values of ''x,y'' for which your function from problem 4 fails? Try these values of ''(x,y)'': ''(1,0), (-1,0), (0,0)''. Revise ''cartesian2polar'' function to fix these the problems these examples point out using ''if-else'' statements, so that your function gives correct ''r, theta'' values for all ''x,y'' values. |
+ | |||
+ | **Problem 7:** Write a ''tempconvert'' function that converts a temperature in any of C, F,or K units and converts it to any desired units. The function should take a single input argument ''t''. It should then prompt the user for the units of ''t'' using an ''input'' statement, prompt again for the desired units of the output, print a statement using ''fprintf'' of the form ''67 F is equivalent to 292.594 K'' (where the numbers and units depend on the input values), and then return the numerical value of the temperature in the desired output units. If the input temperature is below absolute value, the program should print an error message and return absolute zero in the desired units. | ||