2016年05月30日
Introduction to Programming with MATLAB Lesson 4
COURSERAのクラスでMATLABの復習を継続中。今週のテーマはProgrammer's Toolboxということで、MATLABの行列演算の方法、入出力、グラフプロット、デバッギングを学んだ。
宿題の中でちょっと手こずったのが、以下の問題。
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that using the built-in functions eye and diag are not allowed. (Hint: you can index into a matrix with a single index and MATLAB will handle it as if it was a vector using column-major order. Note that the grader will not test for n = 1, but try to solve it for that case too.)
Hintがあるが、この意味がわからない。クラスのDiscussionページを見ると、このHintの意味を質問している人が!そしてその回答は、以下のような行列操作を意味しているとのこと。
>> A = [1,2,3; 4,5,6; 7,8,9]
A =
1 2 3
4 5 6
7 8 9
>> A(3,2)
ans =
8
>> A(6)
ans =
8
>> A(2:5)
ans
4
7
2
5
なるほどと試してみると、たった2行のスクリプトで書けてしまうではないか!これは覚えておきたいテクニック。Lesson4を無事完了。
Homework 4 Grader (v4.16.7.5)
Type the number of the problem that you would like to check
or choose the last option to check all problems and compute
a score and a submission code. (Nothing is submitted.)
0. EXIT
1. intquad
2. sindeg
3. simple_stats
4. odd_rms
5. fence
6. zero_stat
7. reverse_diag
8. sum3and5muls
9. ALL PROBLEMS (gives score and submission code)
Your selection: 9
Grading all problems ...
Problem 1 (intquad):
Feedback: Your function performed correctly for argument(s) 2, 3
Feedback: Your function performed correctly for argument(s) 4, 4
Feedback: Your function performed correctly for argument(s) 1, 5
Feedback: Your function performed correctly for argument(s) 3, 1
Feedback: Your function performed correctly for argument(s) 1, 1
Feedback: Your function performed correctly for argument(s) 5, 2
Feedback: Your function performed correctly for argument(s) 5, 5
Feedback: Your function performed correctly for argument(s) 5, 1
Feedback: Your function performed correctly for argument(s) 4, 5
Feedback: Your function performed correctly for argument(s) 3, 4
Feedback: Your function performed correctly for argument(s) 5, 5
Your solution is correct.
Problem 2 (sindeg):
Feedback: Your function performed correctly for argument(s) [0 90 180]
Feedback: Your function performed correctly for argument(s) [30 60;90 120]
Feedback: Your function performed correctly for argument(s) 180
Feedback: Your function performed correctly for argument(s) [360;270;90]
Feedback: Your function performed correctly for argument(s) [342 668;589 105;397 305]
Feedback: Your function performed correctly for argument(s) [563 551 501;10 669 287]
Feedback: Your function performed correctly for argument(s) [450 120 441 564 475 649 148 452 603 286;337 579 195 392 207 261 647 167 676 676;548 557 149 56 279 90 715 160 3 505;6 70 594 233 505 541 691 404 331 594]
Feedback: Your function performed correctly for argument(s) [138 58 615;522 163 305;403 195 145;302 214 427;294 82 494]
Feedback: Your function performed correctly for argument(s) [80 682 627 41;272 356 51 341;44 466 77 57;66 429 63 213]
Feedback: Your function performed correctly for argument(s) [364 222 478 124 364;120 61 345 181 296;499 658 599 645 371;390 100 604 69 129]
Your solution is correct.
Problem 3 (simple_stats):
Feedback: Your function performed correctly for argument(s) [1 1 1;1 1 1]
Feedback: Your function performed correctly for argument(s) [1 2;3 4]
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) [1 2 3 4 5 6 7 8 9 10]
Feedback: Your function performed correctly for argument(s) [18 3 18;18 2 10;18 16 6;8 3 17;2 9 7;20 9 9;1 20 12;18 6 2]
Feedback: Your function performed correctly for argument(s) [7 13 4 10;4 3 17 3;2 14 15 3;17 7 8 18;20 7 14 1;7 14 8 1]
Feedback: Your function performed correctly for argument(s) [11 3 18 11 17;9 16 20 4 4;2 7 4 1 8;1 7 3 17 3;16 7 13 5 16;11 10 15 13 20]
Feedback: Your function performed correctly for argument(s) [10 13 10 10 8 1 20;19 4 7 4 9 11 16]
Feedback: Your function performed correctly for argument(s) [15 12 7 7 8 8 1;2 2 6 15 4 15 1;17 17 7 3 20 19 4;7 11 5 16 12 11 6;15 16 10 16 19 12 8;14 12 20 12 8 10 7]
Feedback: Your function performed correctly for argument(s) [5 17 5 8 13 13 13 15;2 9 6 10 9 3 20 6;9 19 6 20 12 5 12 5;18 12 16 16 14 13 17 8;13 15 15 19 12 1 10 2;15 8 16 18 4 7 7 12;6 8 16 9 8 12 20 1;20 12 13 3 17 19 10 3]
Feedback: Your function performed correctly for argument(s) [12 14 8 18 17 18 12;13 17 18 4 6 2 5;11 9 13 12 1 14 2;4 2 1 9 11 19 17;6 4 14 6 19 15 13]
Your solution is correct.
Problem 4 (odd_rms):
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 6
Feedback: Your function performed correctly for argument(s) 7
Feedback: Your function performed correctly for argument(s) 8
Feedback: Your function performed correctly for argument(s) 87
Feedback: Your function performed correctly for argument(s) 17
Feedback: Your function performed correctly for argument(s) 34
Feedback: Your function performed correctly for argument(s) 17
Feedback: Your function performed correctly for argument(s) 90
Feedback: Your function performed correctly for argument(s) 65
Your solution is correct.
Problem 5 (fence):
Feedback: Your function performed correctly for argument(s) 100, 10
Feedback: Your function performed correctly for argument(s) 100, 9
Feedback: Your function performed correctly for argument(s) 100, 11
Feedback: Your function performed correctly for argument(s) 99, 9
Feedback: Your function performed correctly for argument(s) 99, 11
Feedback: Your function performed correctly for argument(s) 10, 11
Feedback: Your function performed correctly for argument(s) 348, 1
Feedback: Your function performed correctly for argument(s) 56, 17
Feedback: Your function performed correctly for argument(s) 749, 20
Feedback: Your function performed correctly for argument(s) 261, 15
Feedback: Your function performed correctly for argument(s) 206, 19
Feedback: Your function performed correctly for argument(s) 658, 12
Your solution is correct.
Problem 6 (zero_stat):
Feedback: Your function performed correctly for argument(s) [1 0;0 1]
Feedback: Your function performed correctly for argument(s) [1 1 0 1 0 0 0 1 0]
Feedback: Your function performed correctly for argument(s) [0 0 0 0]
Feedback: Your function performed correctly for argument(s) [1 1 1 1 1]
Feedback: Your function performed correctly for argument(s) [1;0;0;1;0;0;0;1;0;0]
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 0
Feedback: Your function performed correctly for argument(s) [0 1 1 1 1 0 0 0;1 0 0 1 0 0 0 0;1 1 1 1 0 0 0 0;0 1 0 0 1 1 1 1]
Feedback: Your function performed correctly for argument(s) [0 0;0 1;1 1]
Feedback: Your function performed correctly for argument(s) [1 0 0 1 1 0]
Feedback: Your function performed correctly for argument(s) [0 0 0 0;0 1 0 1;1 0 0 0;1 1 0 0;0 1 1 1;1 1 1 1;1 0 0 1;1 1 1 1]
Feedback: Your function performed correctly for argument(s) [0 0;1 1;1 0;1 0;0 1]
Feedback: Your function performed correctly for argument(s) [0 1 0 0 0]
Your solution is correct.
Problem 7 (reverse_diag):
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 13
Feedback: Your function performed correctly for argument(s) 11
Feedback: Your function performed correctly for argument(s) 24
Feedback: Your function performed correctly for argument(s) 36
Feedback: Your function performed correctly for argument(s) 46
Feedback: Your function performed correctly for argument(s) 48
Feedback: Your function performed correctly for argument(s) 37
Your solution is correct.
Problem 8 (sum3and5muls):
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 6
Feedback: Your function performed correctly for argument(s) 7
Feedback: Your function performed correctly for argument(s) 8
Feedback: Your function performed correctly for argument(s) 9
Feedback: Your function performed correctly for argument(s) 10
Feedback: Your function performed correctly for argument(s) 12
Feedback: Your function performed correctly for argument(s) 15
Feedback: Your function performed correctly for argument(s) 29
Feedback: Your function performed correctly for argument(s) 30
Feedback: Your function performed correctly for argument(s) 31
Feedback: Your function performed correctly for argument(s) 401
Feedback: Your function performed correctly for argument(s) 973
Feedback: Your function performed correctly for argument(s) 771
Feedback: Your function performed correctly for argument(s) 520
Feedback: Your function performed correctly for argument(s) 483
Feedback: Your function performed correctly for argument(s) 814
Feedback: Your function performed correctly for argument(s) 254
Feedback: Your function performed correctly for argument(s) 127
Your solution is correct.
Score: 8/8
Alphanumeric Code: XXXXXX
Code XXXXXX was stored in file HW4.MOOC. Submit this file on Coursera!
宿題の中でちょっと手こずったのが、以下の問題。
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that using the built-in functions eye and diag are not allowed. (Hint: you can index into a matrix with a single index and MATLAB will handle it as if it was a vector using column-major order. Note that the grader will not test for n = 1, but try to solve it for that case too.)
Hintがあるが、この意味がわからない。クラスのDiscussionページを見ると、このHintの意味を質問している人が!そしてその回答は、以下のような行列操作を意味しているとのこと。
>> A = [1,2,3; 4,5,6; 7,8,9]
A =
1 2 3
4 5 6
7 8 9
>> A(3,2)
ans =
8
>> A(6)
ans =
8
>> A(2:5)
ans
4
7
2
5
なるほどと試してみると、たった2行のスクリプトで書けてしまうではないか!これは覚えておきたいテクニック。Lesson4を無事完了。
Homework 4 Grader (v4.16.7.5)
Type the number of the problem that you would like to check
or choose the last option to check all problems and compute
a score and a submission code. (Nothing is submitted.)
0. EXIT
1. intquad
2. sindeg
3. simple_stats
4. odd_rms
5. fence
6. zero_stat
7. reverse_diag
8. sum3and5muls
9. ALL PROBLEMS (gives score and submission code)
Your selection: 9
Grading all problems ...
Problem 1 (intquad):
Feedback: Your function performed correctly for argument(s) 2, 3
Feedback: Your function performed correctly for argument(s) 4, 4
Feedback: Your function performed correctly for argument(s) 1, 5
Feedback: Your function performed correctly for argument(s) 3, 1
Feedback: Your function performed correctly for argument(s) 1, 1
Feedback: Your function performed correctly for argument(s) 5, 2
Feedback: Your function performed correctly for argument(s) 5, 5
Feedback: Your function performed correctly for argument(s) 5, 1
Feedback: Your function performed correctly for argument(s) 4, 5
Feedback: Your function performed correctly for argument(s) 3, 4
Feedback: Your function performed correctly for argument(s) 5, 5
Your solution is correct.
Problem 2 (sindeg):
Feedback: Your function performed correctly for argument(s) [0 90 180]
Feedback: Your function performed correctly for argument(s) [30 60;90 120]
Feedback: Your function performed correctly for argument(s) 180
Feedback: Your function performed correctly for argument(s) [360;270;90]
Feedback: Your function performed correctly for argument(s) [342 668;589 105;397 305]
Feedback: Your function performed correctly for argument(s) [563 551 501;10 669 287]
Feedback: Your function performed correctly for argument(s) [450 120 441 564 475 649 148 452 603 286;337 579 195 392 207 261 647 167 676 676;548 557 149 56 279 90 715 160 3 505;6 70 594 233 505 541 691 404 331 594]
Feedback: Your function performed correctly for argument(s) [138 58 615;522 163 305;403 195 145;302 214 427;294 82 494]
Feedback: Your function performed correctly for argument(s) [80 682 627 41;272 356 51 341;44 466 77 57;66 429 63 213]
Feedback: Your function performed correctly for argument(s) [364 222 478 124 364;120 61 345 181 296;499 658 599 645 371;390 100 604 69 129]
Your solution is correct.
Problem 3 (simple_stats):
Feedback: Your function performed correctly for argument(s) [1 1 1;1 1 1]
Feedback: Your function performed correctly for argument(s) [1 2;3 4]
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) [1 2 3 4 5 6 7 8 9 10]
Feedback: Your function performed correctly for argument(s) [18 3 18;18 2 10;18 16 6;8 3 17;2 9 7;20 9 9;1 20 12;18 6 2]
Feedback: Your function performed correctly for argument(s) [7 13 4 10;4 3 17 3;2 14 15 3;17 7 8 18;20 7 14 1;7 14 8 1]
Feedback: Your function performed correctly for argument(s) [11 3 18 11 17;9 16 20 4 4;2 7 4 1 8;1 7 3 17 3;16 7 13 5 16;11 10 15 13 20]
Feedback: Your function performed correctly for argument(s) [10 13 10 10 8 1 20;19 4 7 4 9 11 16]
Feedback: Your function performed correctly for argument(s) [15 12 7 7 8 8 1;2 2 6 15 4 15 1;17 17 7 3 20 19 4;7 11 5 16 12 11 6;15 16 10 16 19 12 8;14 12 20 12 8 10 7]
Feedback: Your function performed correctly for argument(s) [5 17 5 8 13 13 13 15;2 9 6 10 9 3 20 6;9 19 6 20 12 5 12 5;18 12 16 16 14 13 17 8;13 15 15 19 12 1 10 2;15 8 16 18 4 7 7 12;6 8 16 9 8 12 20 1;20 12 13 3 17 19 10 3]
Feedback: Your function performed correctly for argument(s) [12 14 8 18 17 18 12;13 17 18 4 6 2 5;11 9 13 12 1 14 2;4 2 1 9 11 19 17;6 4 14 6 19 15 13]
Your solution is correct.
Problem 4 (odd_rms):
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 6
Feedback: Your function performed correctly for argument(s) 7
Feedback: Your function performed correctly for argument(s) 8
Feedback: Your function performed correctly for argument(s) 87
Feedback: Your function performed correctly for argument(s) 17
Feedback: Your function performed correctly for argument(s) 34
Feedback: Your function performed correctly for argument(s) 17
Feedback: Your function performed correctly for argument(s) 90
Feedback: Your function performed correctly for argument(s) 65
Your solution is correct.
Problem 5 (fence):
Feedback: Your function performed correctly for argument(s) 100, 10
Feedback: Your function performed correctly for argument(s) 100, 9
Feedback: Your function performed correctly for argument(s) 100, 11
Feedback: Your function performed correctly for argument(s) 99, 9
Feedback: Your function performed correctly for argument(s) 99, 11
Feedback: Your function performed correctly for argument(s) 10, 11
Feedback: Your function performed correctly for argument(s) 348, 1
Feedback: Your function performed correctly for argument(s) 56, 17
Feedback: Your function performed correctly for argument(s) 749, 20
Feedback: Your function performed correctly for argument(s) 261, 15
Feedback: Your function performed correctly for argument(s) 206, 19
Feedback: Your function performed correctly for argument(s) 658, 12
Your solution is correct.
Problem 6 (zero_stat):
Feedback: Your function performed correctly for argument(s) [1 0;0 1]
Feedback: Your function performed correctly for argument(s) [1 1 0 1 0 0 0 1 0]
Feedback: Your function performed correctly for argument(s) [0 0 0 0]
Feedback: Your function performed correctly for argument(s) [1 1 1 1 1]
Feedback: Your function performed correctly for argument(s) [1;0;0;1;0;0;0;1;0;0]
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 0
Feedback: Your function performed correctly for argument(s) [0 1 1 1 1 0 0 0;1 0 0 1 0 0 0 0;1 1 1 1 0 0 0 0;0 1 0 0 1 1 1 1]
Feedback: Your function performed correctly for argument(s) [0 0;0 1;1 1]
Feedback: Your function performed correctly for argument(s) [1 0 0 1 1 0]
Feedback: Your function performed correctly for argument(s) [0 0 0 0;0 1 0 1;1 0 0 0;1 1 0 0;0 1 1 1;1 1 1 1;1 0 0 1;1 1 1 1]
Feedback: Your function performed correctly for argument(s) [0 0;1 1;1 0;1 0;0 1]
Feedback: Your function performed correctly for argument(s) [0 1 0 0 0]
Your solution is correct.
Problem 7 (reverse_diag):
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 13
Feedback: Your function performed correctly for argument(s) 11
Feedback: Your function performed correctly for argument(s) 24
Feedback: Your function performed correctly for argument(s) 36
Feedback: Your function performed correctly for argument(s) 46
Feedback: Your function performed correctly for argument(s) 48
Feedback: Your function performed correctly for argument(s) 37
Your solution is correct.
Problem 8 (sum3and5muls):
Feedback: Your function performed correctly for argument(s) 1
Feedback: Your function performed correctly for argument(s) 2
Feedback: Your function performed correctly for argument(s) 3
Feedback: Your function performed correctly for argument(s) 4
Feedback: Your function performed correctly for argument(s) 5
Feedback: Your function performed correctly for argument(s) 6
Feedback: Your function performed correctly for argument(s) 7
Feedback: Your function performed correctly for argument(s) 8
Feedback: Your function performed correctly for argument(s) 9
Feedback: Your function performed correctly for argument(s) 10
Feedback: Your function performed correctly for argument(s) 12
Feedback: Your function performed correctly for argument(s) 15
Feedback: Your function performed correctly for argument(s) 29
Feedback: Your function performed correctly for argument(s) 30
Feedback: Your function performed correctly for argument(s) 31
Feedback: Your function performed correctly for argument(s) 401
Feedback: Your function performed correctly for argument(s) 973
Feedback: Your function performed correctly for argument(s) 771
Feedback: Your function performed correctly for argument(s) 520
Feedback: Your function performed correctly for argument(s) 483
Feedback: Your function performed correctly for argument(s) 814
Feedback: Your function performed correctly for argument(s) 254
Feedback: Your function performed correctly for argument(s) 127
Your solution is correct.
Score: 8/8
Alphanumeric Code: XXXXXX
Code XXXXXX was stored in file HW4.MOOC. Submit this file on Coursera!
【このカテゴリーの最新記事】
-
no image
-
no image
-
no image
-
no image
この記事へのコメント
コメントを書く
この記事へのトラックバックURL
https://fanblogs.jp/tb/5112912
※ブログオーナーが承認したトラックバックのみ表示されます。
この記事へのトラックバック