Question: PLEASE REVIEW OPERATORS AND ELEMENTARY OPERATIONS AT http://www.mathworks.com/help/matlab/operators-and-elementary-operations.html In this exercise, you will create, when possible, an m by n matrix A, which we will
PLEASE REVIEW OPERATORS AND ELEMENTARY OPERATIONS AT http://www.mathworks.com/help/matlab/operators-and-elementary-operations.html In this exercise, you will create, when possible, an m by n matrix A, which we will call here a Generalized Hilbert matrix, such that its (i, j)-entry, A(i,j), is calculated by means of the formula A(i,j) = 1/( i + j 1), where i runs from 1 to m and j runs from 1 to n. To decide whether A can be created, you will first check in your code if the variables m and n are integers. You can use a conditional if statement (see for help http://www.mathworks.com/help/matlab/ref/if.html ) and a MATLAB built-in function such as mod, floor, or fix. 1) If either m or n is not integer, the outputs have to be an empty matrix (assign A = [ ]) and the message Error: both m and n must be integers, and then the program terminates (the command return will terminate it). 2) If both m and n are integers, proceed to calculation of the entries of A as (1) A(i,j) = 1/( i + j 1) when m n (by using double for loop), and (2) employ a MATLAB built-in function A = hilb(m) when m = n. In the case when m = n, also compute the inverse of 7 A, a matrix B = invhilb(m). To output B, do not put semicolon after the command B = invhilb(m). Also, use format rat in your code to output the matrix A with rational entries when A is not empty. Please follow the following steps: **Create the function genhilb in MATLAB using the Instructions above: A=genhilb(m,n) **Call your diary file Project0 in the Command Window (see Exercise 1 in this project). **Type the function in your diary file using the command type genhilb **Run the function A=genhilb(m,n) on each of the following sets of variables: (a) m = 3.5, n = 4 (b) m = 5, n = 1.6 (c) m = 3, n = 4 (d) m = 4, n = 4 (e) m = 3, n = 3 See below an example of the part in your diary file corresponding to part (e) (when m = 3 and n = 3): >> % (e) >> m=3,n=3 m = 3 n = 3 >> A=genhilb(m,n) B = 9 -36 30 -36 192 -180 30 -180 180 A = 1 1/2 1/3 1/2 1/3 1/4 1/3 1/4 1/5 IMPORTANT NOTE: If you had received an error message that was not expected, edit the code and re-run the function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
