• Support PF! Buy your school textbooks, materials and every day products Here!

A large matrix in matlab

  • #1

Homework Statement



I need to create a 121*121 matrix in matlab. Forty of the rows have to contain the sequence 0 1 0 0 1 -4 1 0 0 1. and the rest of the rows will have 0's and "one 1" per row. The sequence has to be pushed one step to the right from row 1 to 121, the result should be a matrix with only -4's and 1's on the diaogonal.

The first 12 rows will have the form:
1 0 0 0 0 0 0 0 0 0 0........
0 1 0 0 0 0 0 0 0 0 0.......
0 0 1 0 0 0 0 0 0 0 0........

Then the rows with the -4's appear 9 times being separated by only two rows of type 1 and 0.
example:
1 0 0 0 0 0 0 0 0 0 0........
0 1 0 0 0 0 0 0 0 0 0.......
0 0 1 0 0 0 0 0 0 0 0........
11 rows
then
9 rows of
0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 0 0........
0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 ......
0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 ......
after the 9 rows then two of only 1 and 0 again. and it continues like that for 110 rows down, with the remaining being like the twelve first with only 1 and zeros.

phew! Hope this is possible to understand. I have very little experience with programing, so I find this really hard.

Homework Equations


please ask for expanation if you don't understand.

The Attempt at a Solution



Mons
 

Answers and Replies

  • #2
272
0
You may want to investigate the use of the functions "diag" and "eye" . If you could clarify that second matrix you've posted (since it looks the same as the one above it), I could give a little bit more direction.
 
  • #3
hi. thank you for helping me.

The pattern is as follows


1 0 0 0 0 0 0 0 0 0 0........
0 1 0 0 0 0 0 0 0 0 0.......
0 0 1 0 0 0 0 0 0 0 0........
0 0 0 1 0 0 0 0 0 0 0 0 0 0........
0 0 0 0 1 0 0 0 0 0 0 0 0 0.......
0 0 0 0 0 1 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 0 1 0 0 0 0.......
0 0 0 0 0 0 0 0 1 0 0 0....
0 0 0 0 0 0 0 0 0 1 0 0 0........
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0.......
0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 ......
0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 ......
0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 ......
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 ......
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 0 0........
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 0 0 0 0 ......
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 -4 1 0 0 1 0 0 0 ......
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0........
then 9 rows with -4 in them, then two with only 1 and 0 again......
this continues until row 110, and the 11 are with only 1 and 0.

hope this is possible to understand=).
 
  • #4
the diagonal should only consist of 4s and 1s.
 

Related Threads on A large matrix in matlab

  • Last Post
Replies
1
Views
1K
Replies
1
Views
6K
  • Last Post
Replies
10
Views
1K
Replies
1
Views
6K
Replies
11
Views
8K
Replies
1
Views
4K
  • Last Post
Replies
1
Views
1K
Replies
1
Views
3K
Replies
1
Views
716
Replies
1
Views
1K
Top