# Homework Help: Write a working matlab function

1. Nov 20, 2009

1. The problem statement, all variables and given/known data
Write a working Matlab function that takes as input a positive integer n and outputs a
2n by 2n matrix whose top left n by n block and bottom right n by n block are zero,
whose top right n by n block is the n by n identity matrix and whose bottom left n by n
block is filled with uniform [0,1] random numbers.

2. Relevant equations

3. The attempt at a solution
function MatrixMul
n = input('Please enter a positive integer: ');
A(2*n,2*n)=0;
rand(n,n);
eye(n)
display(A)
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

2. Nov 21, 2009

### Staff: Mentor

That's a start, but it's nowhere near what you want. Your function needs to create four nxn matrices of specific types, and then concatenate (join) them together to create the 2n x 2n matrix specified in your problem. To learn about matrices, see the section titled Working with Matrices in Ch. 2 in the link below. Also see the section titled Concatenation in Ch. 2 in the link below.

Here's a link to the Getting Started documentation for matlab: http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf

A(2*n,2*n) = 0;
Sets one entry in matrix A to 0 and does nothing to any of the other entries. I'm sure that's not what you intended.

rand(n, n);
I believe this will create an nxn matrix of random numbers, but it needs to be an assignment statement to store them in a matrix variable. Here's how to do that.
Random_matrix = rand(n, n);

eye(n)
As above, this statement doesn't store the matrix variable anywhere. You can do it this way.
I_matrix = eye(n);

Now all you have to do is concatenete the n x n matrices that have created into the big 2n x 2n matrix.