Write a working matlab function

  • Thread starter Thread starter tuablink
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary
A Matlab function is needed to create a 2n by 2n matrix with specific block configurations: the top left and bottom right blocks must be zero, the top right block should be an identity matrix, and the bottom left block filled with uniform random numbers. The initial code attempts to define the matrix but fails to properly create and store the required blocks. It is essential to use assignment statements to store the identity matrix and random numbers in variables. Finally, the four n by n matrices must be concatenated to form the desired 2n by 2n matrix. Proper understanding of matrix operations and concatenation in Matlab is crucial for completing this task.
tuablink
Messages
24
Reaction score
0

Homework Statement


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.


Homework Equations





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)
 
Physics news on Phys.org
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

Comments on your code
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.
 
Question: A clock's minute hand has length 4 and its hour hand has length 3. What is the distance between the tips at the moment when it is increasing most rapidly?(Putnam Exam Question) Answer: Making assumption that both the hands moves at constant angular velocities, the answer is ## \sqrt{7} .## But don't you think this assumption is somewhat doubtful and wrong?

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
49
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K