Question

Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered that takes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

---------------------------------------------------------------------------------------------------------------

(a) % Code below

function matrx = makeLayered(n)
%   
% make a matrix of (2*n-1)x(2*n-1)
matrx = ones(2*n-1,2*n-1);
if( n > 1)
% recursively call makeLayered(n-1)
mat = makeLayered(n-1);
% fill the first row, last row, first column and last column
% with n
for i=1:2*n-1
matrx(1,i) = n;
matrx(i,1) = n;
matrx(2*n-1,i) = n;
matrx(i,2*n-1) = n;
end
for i=2:2*n-2
for j=2:2*n-2
matrx(i,j) = mat(i-1,j-1);
end
end
end
  
end

---------------------------------------------------------------------------------------------------------------

(b) Screenshots of test cases :-

(i) For n = 1

= makeLayered (1) >>m 1(ii) For n = 3makeLayered (3) >>m m = 3 3 3 2 2 3 3 1 2 3 3 2 2 2 3 3 3 3 N N CO(iii) For n = 8

(8) makeLayered >>m m = 8 8 8 8 8 8 7 7 7 7 7 7 6 6 6 6 8 5 5 6 7 4 4 4 4 4 4 4 6 7 7 6 4 3 3 3 3 4 7 8 7 6 3 2 2 4 6 2 5 6 7

---------------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Special Problem: Automated Factorial Create a MATLAB function called xfact that uses a loop to calculate...

    Special Problem: Automated Factorial Create a MATLAB function called xfact that uses a loop to calculate the factorial of an integer. Your function should take a single integer input. Your function should compute the factorials of every integer from 1 to the integer provided by the input. Test your function by prompting the user to enter an integer N and, using a loop create an array named X of length N that contains the factorials of the numbers 1 to...

  • Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called...

    Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called isright, that takes three inputs, a, b, and c, and determines whether they are could be the lengths of the sides of a right triangle; the output, y, will be set equal to the following: i). -1 if at least one of the values is not positive. Also, only for this case, have the function print out an error message, which states "At least...

  • QUESTION 5: Write a C++ function called layers which takes an NxN integer array (for some...

    QUESTION 5: Write a C++ function called layers which takes an NxN integer array (for some constant N) and populates the entries 0..N2-1 as follows: The upper left entry (row-0, col-0) is 0. Subsequent numbers are assigned along Southwest-to-Northeast diagonals, layer-by-layer. For example, if N=4, your function would result in the following assignment to entries in the array: 0 2 5 9 1 4 8 12 3 7 11 14 6 10 13 15 (the individual “layers” are shown by...

  • ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for...

    ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for a class. Student marks are stored as a 2D array. Each row represents the marks of one student. Each column represents one assessment. For example, if we have two students and 3 assessment items with the marks for student1 being (67.6,88.5, 75.4} and student2 being (77.5, 76.2,78.3} our 2D array would look like: 67.6, 38.5,75.4 77.5, 76.2,78.3 You are to write a script/main function...

  • MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demo...

    MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased...

  • Matlab Question 2. For this problem you have to create a program that defines two vectors...

    Matlab Question 2. For this problem you have to create a program that defines two vectors of numbers: A and B and uses a for-loop to combine the values of A and B. Note that different parts of the question below specify different orders for combining the elements. To start this exercise start a MATLAB script called q2.m and put, at the top, the vector definition: B [11:20] Question 2a: Problem definition Copy the file q2.m to q2a.m. For this...

  • Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) Matlab question Matrix Notation Interpreter (matrix elements to cell array of formatted character...

    Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) Matlab question Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) A system of linear algebraic equations can be writen in matrx notation by applying the definizion of matrix multiplication. For example, the linear system Can be writen as or where and x = 2 matrix input ror the variable A and a × T e function command dennes the output variable linearSystem Code has...

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • please be thorough with explanations. thank you Question 2 Consider the implementation we made in class...

    please be thorough with explanations. thank you Question 2 Consider the implementation we made in class for ArrayList, and its extensions you did in the lab. In this question, we will add two more methods to this class: the insert method and the pop method. For this question, please submit the modified ArrayList class. a) Implement the method insert (self, index, val) that inserts val before index (shifting the elements to make room for val). For example, your implementation should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT