EECS 1570 Winter 2020 Assignment 4 Due: Thursday March 19, 2020 by 10:55 p.m.
- This assignment is worth 6% of your final grade. 2. Submit your solution files electronically through the course Moodle. 3. A list of the files to submit is found at the end of this assignment.
Questions: 1. (8 points) Write a user-defined MATLAB function named word2piglatin that receives a word as input and returns a pig Latin translation of the word. Both the input word and the pig Latin word are character arrays. The pig Latin translation involves first determining if the input word begins with a vowel (a, e, i, o, or u). If so, append ‘way’ to form the pig Latin translation. If the input word does not begin with a vowel, then form the pig Latin translation by moving the first letter to the end of the word and then appending ‘ay’. Some example translations are skip kipsay to otay all allway Include documentation for help. Test your function in MATLAB’s command window. An example follows. User input is underlined. >> help word2piglatin word2piglatin – convert a word to pig Latin word2piglatin(word) receives an input word as a character array and returns a pig Latin translation of the word, also a character array. Forming the pig Latin of a word involves moving the first letter of the word to the end of the word, then appending ‘ay’, for example, the pig Latin for ‘trim’ is ‘rimtay’. An exception is words beginning with a vowel: just append ‘way’. So, the pig Latin for ‘and’ is ‘andway’. Author: , ,
Once you are a confident your word2piglatin function is working properly, write a MATLAB test program named a4q1.m that uses the function. This program should prompt the user to enter a phrase. Input the phrase, then output the translated phrase in the command window. Below is an example dialog. User input is underlined.
Enter a phrase: summer is coming soon ummersay isway omingcay oonsay
For this question, you must submit two files: word2piglatin.m and a4q1.m.
- (5 points) Write a MATLAB function named ispalindrome that receives a word or character array as input and then analyses the word to determine if the character sequence is a palindrome. Return true (logical 1) if the sequence is a palindrome or false (logical 0) if the sequence is not a palindrome. A palindrome is a character sequence that is the same forwards and backwards. Examples include ‘deed’, ‘rotator’, or ‘02022020’. Your function code should use MATLAB’s for and if statements and perform the analysis without using any MATLAB functions. Test your function in the command window. Below are some example dialogs. User input is underlined.
help ispalindrome ispalindrome(word) – determine if word is a palindrome A word or character sequence is a palindrome if it is the same forwards and backwards. Examples are ‘rotator’, ‘deed’, and ‘02022020’. Return 1 (true) if the word is a palindrome, 0 (false) otherwise. Author: , ,
For this question, submit the code for your function: ispalindrome.m.
- (8 points) Write a MATLAB program (a4q3.m) that displays ASCII numeric codes as the corresponding characters. For example, the ASCII numeric code 97 corresponds to the character ‘a’. (See the ASCII chart in the Lecture 16 notes, or just search on “ASCII” in a browser.) Your program should proceed in a loop. Begin by prompting the user to enter some ASCII codes or -1 to quit. Input the codes and echo the corresponding characters to the command window. We’re only interested in the ASCII codes representing the core set of displayable characters. These fall in the range 32 to 126. For any codes outside this range (except -1, which is used to quit), substitute the code for a question mark. Proceed in a loop unit -1 is detected. When that happens, output ‘Bye!’ and terminate. An example run of the program is shown below. User input is underlined.
Enter ASCII code(s) or -1 to quit: 97 A Enter ASCII code(s) or -1 to quit: [72 101 108 108 111] Hello Enter ASCII code(s) or -1 to quit: [72 32 101 32 108 32 108 32 111] H e l l o Enter ASCII code(s) or -1 to quit: 65:90 ABCDEFGHIJKLMNOPQRSTUVWXYZ Enter ASCII code(s) or -1 to quit: 97:2:122 acegikmoqsuwy Enter ASCII code(s) or -1 to quit: 25:60 ??????? !”#$%&'()*+,-./0123456789:;< Enter ASCII code(s) or -1 to quit: 500:510 ??????????? Enter ASCII code(s) or -1 to quit: [70 117 110 63 32 87 111 119 33] Fun? Wow! Enter ASCII code(s) or -1 to quit: -1 Bye!
For this question, submit one file: a4q3.m.
- (6 points) Write a MATLAB program (a4q4.m) that creates and outputs the first 30 numbers in the Fibonacci series. The Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, 21, … The first two numbers are 0 and 1. Each subsequent number is the sum of the two preceding numbers. So, the next number in the example above is 13 + 21 = 34. And the next number is 21 + 34 = 55. And so on.
In your code, explicitly assign the first two numbers in the series, then built up the rest of series using a for-loop. Do not use MATLAB’s fibonacci function (available in the Symbolic Math Toolbox).
We’re looking for very specific output in this question. Output the 30 numbers, 5 numbers per line over 6 lines. Use an 8-character field width for each number. Here are the first five lines of output: (your program should generate six lines of output)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368
One final thing. Create all the output using a single fprintf statement that executes just once.
For this question, submit one file: a4q4.m.
- (12 points) Consider the following table, which contains data from an experiment comparing the text entry speed on two keyboard layouts, Opti and Qwerty: Participant Initials Age Gender A_Opti B_Qwerty Group P1 KR 32 F 7.47 21.35 AB P2 OI 36 F 9.21 37.66 BA P3 ASH 21 M 11.33 32.17 AB P4 AL 21 M 10.20 42.67 BA P5 VSH 21 M 9.46 32.50 AB P6 AK 21 F 12.87 32.50 BA P7 CH 21 F 8.42 32.52 AB P8 VA 36 M 14.22 43.12 BA P9 MCH 22 M 9.24 40.40 AB P10 EKU 30 M 10.48 33.72 BA P11 TE 31 M 10.70 34.51 AB P12 SA 24 M 10.68 31.66 BA P13 BARA 40 F 8.84 31.71 AB P14 SS 23 F 11.14 35.37 BA P15 JE 23 F 7.42 49.88 AB P16 DL 33 F 15.65 43.61 BA P17 AAH 23 F 8.41 36.81 AB P18 MM 35 M 10.41 26.70 BA P19 BN 29 M 10.46 37.82 AB P20 DAS 30 M 9.45 29.29 BA
The data are in the file opti_qwerty_experiment.xlsx, which is on the course Moodle. The data are organized in 7 columns and 21 rows. The rows include a header row and 20 data rows. There is one data row for each participant tested. The first four columns are self explanatory. The 5th and 6th columns contain the measured text entry speed (in words per minute) for each participant on each of two keyboard layouts, Opti and Qwerty. Each value is the mean over five trials. The 7th column indicates whether the participant was in the AB group or the BA group. For the AB group, testing was done first on keyboard A (Opti), then on keyboard B (Qwerty). For the BA group, testing was done in the reverse order. There were 10 participants in each group.1 1 Groups were used for counterbalancing, a technique used in psychology experiments to reduce order effects. Order effects, such as learning or fatigue, are common in experiments that use a within-subjects design. This is the case here since each participant was tested on both the Opti keyboard and the Qwerty keyboard. By switching the order of testing for half the participants, order effects should cancel out. You will learn more about counterbalancing, order effects, and within-subjects experiment designs in PSYC 2030 (Research Methods).
Download the file and place it in your MATLAB workspace. Note that the data contain a mix or text and numeric information.
Write a MATLAB program (a4q5.m) that uses the readtable function to read the data in the file into a table T. Your program should analyse and summarize the data and produce a nicely formatted output table as described below. Replace each XXX with the value computed from the data in the file.
As a tip, organize your script to do the data manipulations and calculations first – at the beginning of the script. Position all the code to create the table at the end of the script. For the general idea, see the solution for Question 5 in Assignment #3.
(a) Begin by outputing three header lines:
======================================================== Keyboard Experiment Summary ——————————————————–
(b) Compute and output the number of participants. Also, compute and include the number of males and females.
Number of participants: XXX (XXX male, XXX female)
(c) Compute and output the mean age of the participants. Format the mean with one decimal place. Also, include the age range.
Mean age: XXX yrs (range: XXX-XXX))
(d) Compute and output the total number of trials. Recall that each measurement in the data table is the mean over five trials.
Number of trials: XXX
(e) Compute and output the grand mean for text entry speed (TES) over the entire experiment. Format the mean with two decimal places.
Grand mean text entry speed (TES): XXX wpm
(f) Determine the fastest and slowest participant. Output the participant code, the participant’s initials in parentheses, and the mean TES with two decimal places.
Fastest participant: XXX (XXX), TES = XXX wpm Slowest participant: XXX (XXX), TES = XXX wpm
(g) Compute and output the mean TES for each keyboard. Format the mean with two decimal places.
Mean TES by keyboard: Opti: XXX wpm Qwerty: XXX wpm
(h) Compute and output the mean TES by gender. Format the mean with two decimal places.
Mean TES by gender: Males: XXX wpm Females: XXX wpm
(i) Compute and output the mean TES by group. Format the mean with two decimal places.
Mean TES by group: AB group: XXX wpm BA group: XXX wpm
(j) In this part, let’s explore the relationship between age and typing speed. Do people type faster or slower as they age? Let’s see. Compute and output the correlation coefficient (r) between age and typing speed. Format the correlation with 4 decimal places. Include an interpretation of the correlation as “Strong”, “Modest”, or “Weak”, according to the following criteria:
Include the appropriate interpretation label for YYY, shown below.
Correlation between age and typing speed r = XXX (YYY)
(k) End with a footer line:
What to hand in Submit your assignment electronically via the course Moodle. Please submit six (6) files:
a4q1.m (for Question 1) word2piglatin.m (for Question 1) mypalindrome.m (the function file for Question 2) a4q3.m (for Question 3) a4q4.m (for Question 4) a4q5.m (for Question 5)