Reference no: EM132245466
Introduction to Computing for Psychology Assignment Questions -
Q1. Write a MATLAB program that computes the amount of income tax a person needs to pay according to the following table:
Income Range ($)
|
Base Tax ($)
|
Percentage of Excess
|
0.00 - 14,999.99
|
0.00
|
15
|
15,000.00 - 29,999.99
|
2,250.00
|
18
|
30,000.00 - 49,999.99
|
5,400.00
|
22
|
50,000.00 - 79,999.99
|
11,000.00
|
27
|
80,000.00 - 149,999.99
|
21,600.00
|
33
|
150,000.00 - 199,999.99
|
49,500.00
|
36
|
>= 200,000.00
|
72,000.00
|
40
|
For example, if a person's income is $20,000.00, the income tax the person needs to pay is $2,250.00 (base tax for the second range) plus 18% of the excess income over $15,000.00 (that is, 18% of $5,000). Therefore, the total tax due is $2,250.00 plus $900.00, which is $3,150.00.
Your program should first prompt the user to input an income (with the prompt of "Please enter your income for 2018: "), then based on the amount and the above table calculate the total amount of income tax. Your program should output to the command window the total amount of tax as follows:
Your total 2018 income tax is: x
where x is the calculated total amount of tax with two digits after the decimal point. For example, if the calculated amount is $3,150, the value should be displayed as 3150.00. If the income entered by the user is negative, your program should output to the command window: invalid income.
Q2. A vector is given by: v=[6, 3, -9, 10, 5, 0, -8, 11, -5]. Write a MATLAB program that uses a for loop and nested if statements to divide each positive even element of v by 2, multiply each positive odd element of v by 2, and square (i.e. raise to power 2) each of its negative elements. Then it should output the new vector to the screen as:
The new vector is: 3 6 81 5 10 0 64 22 25
Q3. Write a Matlab function, called testprime, that takes one input argument and uses a for-loop and rem function to check whether its argument is a prime number. testprime(x) should return 1 if x is a prime number and 0 otherwise. Your testprime function must behave as shown below:
>> help testprime
testprime checks if its argument is a prime
testprime(x) is 1 if x is a prime, 0 otherwise.
Author:<your name, student #, email>
>> testprime(12)
ans =
logical
0
>> testprime(7)
ans =
logical
1
>>
Hint: To get a logical 1 and logical 0 as output of your function, see 'help true' and 'help false'.
Q4. A vector is given by x = [49 7 59 87 65 13 5 22 11 77 23 97 44 99]. Using conditional statements, loops and your testprime function from previous step write a MATLAB program that creates two vectors from x. The first vector (call it P) contains elements of x which are prime numbers, and the second vector (call it N) contains the non-prime elements of x. In both P and N, the elements are in the same order as in x. At the end of the program, display P and N as follows:
The prime vector is: 7 59 13 5 11 23 97
The non-prime vector is: 49 87 65 22 77 44 99
Q5. Consider the following table that contains the midterm and final exam marks of a group of students and their student IDs:
Student ID
|
Test 1
|
Test 2
|
Final
|
1201
|
66
|
75
|
70
|
1210
|
69
|
60
|
77
|
1215
|
82
|
85
|
68
|
1220
|
92
|
89
|
95
|
1235
|
49
|
58
|
54
|
1238
|
75
|
87
|
90
|
1239
|
81
|
65
|
62
|
1240
|
40
|
39
|
30
|
1255
|
65
|
70
|
55
|
1257
|
67
|
83
|
80
|
1270
|
48
|
53
|
60
|
1271
|
68
|
78
|
55
|
The above data are stored in an Excel file (named scores.xls), which can be downloaded from the Assignment page of the course moodle site.
All term tests and final marks are out of 100. The total mark of a student is a weighted sum of the student's term tests and final marks. The weights of Test 1, Test 2, and Final are 25%, 30%, and 45% respectively.
Write a MATLAB program that does all of the following in the specified order:
a) Read the student IDs, Test 1, Test 2 and Final marks in the scores.xls file into a matrix (named M) in MATLAB. Note that you are not allowed to type the values into a matrix.
b) Compute the total score of each student using the weighted sum of the student's term tests and final marks as described above. Then display all the marks in the command window as follows:
StudentID
|
Test 1
|
Test 2
|
Final
|
Total
|
1201
|
66
|
75
|
70
|
70.5
|
1210
|
69
|
60
|
77
|
69.9
|
1215
|
82
|
85
|
68
|
76.6
|
1220
|
92
|
89
|
95
|
92.5
|
1235
|
49
|
58
|
54
|
54.0
|
1238
|
75
|
87
|
90
|
85.3
|
1239
|
81
|
65
|
62
|
67.7
|
1240
|
40
|
39
|
30
|
35.2
|
1255
|
65
|
70
|
55
|
62.0
|
1257
|
67
|
83
|
80
|
77.7
|
1270
|
48
|
53
|
60
|
54.9
|
1271
|
68
|
78
|
55
|
65.2
|
Note that the student IDs, term test marks and final marks are displayed as integers, but total marks are displayed with one digit after the decimal point. Note that you are not allowed to type the total marks into your program. The values must be computed. This also applies to the following steps.
c) Compute the average of the total scores over all the students, and display the computed average to the command window as follows: The average total score is: 67.6
Note that the average score is displayed in the same line as the string "The average total score is", and one and only one digit after the decimal point is displayed.
d) Compute the number of students whose final marks are better than their Total, and display the result in the command window as follows: The number of students whose final mark is better is: 6
e) Compute the number of students whose final marks are worse than their Total, and display the result in the command window as follows: The number of students whose final mark is worse is: 6
f) Compute the number of students whose total mark is above the average total mark calculated in Step c), and display the result in the command window as follows: The number of students above total average is: 7
g) Compute the number of students in each letter grade. The letter grades and their corresponding numeric total scores are described in the following table:
F
|
E
|
D
|
C
|
B
|
A
|
A+
|
[0, 40)
|
[40, 50)
|
[50, 60)
|
[60, 70)
|
[70, 80)
|
[80, 90)
|
[90, 100]
|
The results should be displayed as follows:
The number of A+ students is: 1
The number of A students is: 1
The number of B students is: 3
The number of C students is: 4
The number of D students is: 2
The number of E students is: 0
The number of F students is: 1
What to hand in - You need to submit your assignment electronically. Please submit four MATLAB script files:
a3q1.m (the script file for Question 1)
a3q2.m (the script file for Question 2)
testprime.m (the function file for Question 3)
a3q4.m (the script file for Question 4)
a3q5.m (the script file for Question 5)
For Question 3, testprime function, include your name, student number, and email as indicated in the problem.
For questions with multiple parts use comments to indicate which part(s) of the question the commands that follow are addressing.
Attachment:- Assignment File.rar