Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Numerical methods for solving partial differential equations typically require that the geometry be subdivided into a mesh of simple shapes such as rectangles. By doing
Numerical methods for solving partial differential equations typically require that the geometry be subdivided into a mesh of simple shapes such as rectangles. By doing so a complex problem can be reduced to a collection of simple problems defined on each of the simple shapes. In formulating the solution for a particular simple shape, the algorithms typically need to identify the neighboring shapes. Consider the mesh comprising a grid of rectangles shown below. The neighbors of rectangle are rectangles and Likewise the neighbors of rectangle are rectangles and
Your task is to write a MATLAB function that enumerates the neighbors of a rectangle in an mesh of rectangles. Assume that the rectangles are numbered starting at the upper left corner and increasing from left to right and top to bottom as shown in the example.
Your function should be called getNeighbors. It should take exactly three input arguments in this order: and Here is the number of rows in the mesh, is the number of columns, and is the rectangle whose neighbors must be identified. The function should return exactly one argument, an array containing the numbers of the neighbors in increasing order. Write your code so that the array is directly generated in the correct order; do not use the sort function. For example, getNeighbors should return the array
Your program should validate the input arguments and return and empty array ie if any of the inputs are invalid. More specifically, your program must check that and are not less than is the number of a rectangle that exists in the mesh, and all input values are integers. For example, the following should return an empty array because there is no rectangle with number for the given mesh size: getNeighbors
Test your function using the testGetNeighbors test stub.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started