E7_Su2010_Solutions3_all

E7_Su2010_Solutions3_all - Assigned October 2 Fall 2009 Due...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Assigned: October 2 Fall 2009 Due: October 14 E7 Laboratory Assignment 5 The purpose of this lab is to introduce you to cell arrays, structure arrays and machine precision. Note: You will use MATLAB’s publish command (accessible in the Editor window via File -> Publish to HTML ) to generate a printable document that contains your code and your answers. You must turn in the printed copy to the appropriate homework boxes in 1109 Etcheverry by 12:00 pm on WEDNESDAY October 14 . Your M-file used to generate the HTML document must be uploaded to bSpace, also by noon. Name this file lastname firstname lab04.m. For the simple Run each of the following commands exercises, please follow the new format. Describe, in a comment after the command, what the command does. Aim for 10 words or less (not a strict limit but rather a guideline). After the comment itself, insert one, blank commented line, separating this comment / command pair from the next. Although you will run the code without terminating semicolons (so you can see the output, and learn what is happening), when you are ready to publish the final copy, please place a semicolon after these commands in your m-file to suppress the output. This will shorten the length of your final paper. The readers will focus their attention to the (concise) comments you have written. IMPORTANT: Don’t forget to publish your separate M-files in your main script using type . 1. (a) Write a function with the header line function num = Day2Num(day) using the switch statement that takes a single string argument and returns the corresponding number of day , assuming that the week starts on Sunday (i.e. Sunday is 1, Monday is 2, etc.). Your function should be able to return the appropriate number regardless of the letter casing in day . If day is misspelled, return NaN . Test your function for day=’tUesDay’ . Solution: begin code 1 function num=Day2Num(day) 2 switch lower(day) 3 case ’sunday’ 4 num = 1; 5 case ’monday’ 6 num = 2; 7 case ’tuesday’ 8 num = 3; 1 of 22
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Assigned: October 2 Fall 2009 Due: October 14 9 case ’wednesday’ 10 num = 4; 11 case ’thursday’ 12 num = 5; 13 case ’friday’ 14 num = 6; 15 case ’saturday’ 16 num = 7; 17 otherwise 18 num = NaN; 19 end 20 21 >> Day2Num(’tUesDay’) 22 ans = 23 3 end code (b) Write a function with the header line function totaldays = DaysInMonth(month,year) using if statements, relational operators, and strcmp that will take two arguments, month and year , and return the numbers of days in the month of that year. Your function should be able to compute leap years where the month of February will return 29 days. In addition, your function should be able to return the appropriate number regardless of the letter casing in month . If month is misspelled, return NaN . (Hint: look up leap year in Wikipedia to determine the formula that will calculate which years are leap years) Solution: begin code 1 % Solution 1 2 function totaldays=DaysInMonth(month, year) 3 month = lower(month); 4 if (strcmp(month,’january’) | strcmp(month,’march’) |...
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern