Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve parts A and B. Use matlab or octave to code. DO NOT USE if statements, while or for loops, reshape or randperm commands. USE
Solve parts A and B. Use matlab or octave to code. DO NOT USE if statements, while or for loops, reshape or randperm commands. USE ONLY vectors, matrices, and functions.
(Paths in Graphs) Graph theory studies sets of vertices connect by edges. A very simple way to store the connectivity information about a graph is using what is called an adjacency matrix. In an adjacency matrix A, entry oij is 1 if nodes i and j are connected by an edge and is 0 otherwise. For example, the graph below has adjacency matrix 1 1 07 1 0 1 0 A= 1 1 0 1 0 0 1 0 1 2 3 4 4 One interesting calculation that can easily be done using an adjacency matrix is that we can count the number of paths between two nodes in the graph by calculating powers of the matrix. For example, because r2 1 1 17 A? 1 2 1 1 1 1 3 0 1 1 0 11 we know that there are 0 paths of length 2 from node 3 to node 4 because the entry in row 3, column 4 of A2 is a 0. find_num_paths Function: Input parameters: a square adjacency matrix 2 3 4 One interesting calculation that can easily be done using an adjacency matrix is that we can count the number of paths between two nodes in the graph by calculating powers of the matrix. For example, because A 2 1 1 11 1 2 1 1 1 1 3 0 1 1 0 1 3 we know that there are 0 paths of length 2 from node 3 to node 4 because the entry in row 3, column 4 of A2 is a 0. . find_num_paths Function: Input parameters: a square adjacency matrix a scalar representing the desired path length two scalars representing the two nodes Output parameters: a scalar representing the number of paths connecting the two desired nodes of the desired length . A possible sample case is: >> num_paths = find_num_paths([ 0 1 1 0 ; 1 010 ; 1101; 0010], 2, 3, 4) num_paths 0 (Row Swaps) One very common row operation from linear algebra is the row swap operation. With this operation, we begin with an original matrix and produce a new matrix where two rows have interchanged locations. row_swap Function: . Input parameters: an m x n matrix A (note: the dimensions are not passed in) two scalars which represent the rows which are two be swapped Output parameters: a new matrix representing the resulting matrix from performing the de- sired row swap operation on A A possible sample case is: >> mat_B = row_swap([1:4 ; 2:5 ; 3:6; 4:7], 2, 3) mat B = 1 3 2 4 2 4 3 5 3 5 4 6 4 6 5 7Step 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