Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1. Write a function named blocks that takes two positive integers, n and

ID: 3672471 • Letter: P

Question

Problem 1. Write a function named blocks that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. The function needs to return a 2n-by-2m matrix where the upper right and lower left n-by- m sub matrices are all zeros and the rest of the matrix are all ones. For exam ple, here is an example run: >> blocks (2,3) ans - 0 0 0 0 0 0 The easiest solution utilizes the built-in function zeros and ones (use help zeros and help ones to see how to use them). However, there is a way to solve the problem with clever indexing. Do it both ways!

Explanation / Answer

function T = BlocksT(n,m)
T(1:n,1:m) = 0;
T(n+1:2*n,m+1:2*m) = 0;
T(1:n,m+1:2*m) = 1; %instead of T(n:1,m+1:2*m) = 1;  
T(n+1:2*n,1:m) = 1;
return;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote