 Matrix Problems Using Matlab

Subject Computer Science Programming (Dynamic, Linear, Non-linear, etc.)

Question

clear;
clc;

A = [1 3 5 2;2 4 6 5;-1 7 1 10];

[m n] = size(A);

for i = 1:n %columns
for j = i+1:m %rows (starts on second row because the first row remains unchanged.)
A(j,:) = A(j,:)-A(j,i)/A(i,i)*A(i,:);
end
end

Modify the given code to create a function that returns the inverse of a matrix when that matrix is passed in. Return an error if the matrix is not square, or if it is not full rank. The code must handle the situation where there is a zero in the pivot POSITION. You may use for loops, if statements, and the following commands: rank, and size. Make a pdf file that demonstrates that the code works when under the following test cases:

1. Matrix is square and full rank, no zeros in pivots.
2. Matrix is not square.
3. Matrix is square but not full rank.
4. Matrix is square and full rank and has a zero in a pivot and a zero immediately under the zero in the pivot.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

clear; clc; close all;%Clear console, memory and screen
%%
%Generate user test case matrices
C1=[1    4    2; 3    1    2; 6    4    5]; %Case 1:Square Matrix with Full rank
C2=[1    0    0; 3    1    2];                %Case 2: Non-Square Matrix
C3=[1    2    3; 2    4    6; 3    1    2]; %Case 3:Rank Deficient Matrix
C4=[2    -1    0;-1    0    -1; 0    -1    2]; %Case 4:Matrix with zero pivot and Full Rank
%%
%Code check and output saving for cases with existing inverse
fprintf('\nCase 1:Square Matrix with Full rank');
C1_inv=matinverse(C1);
fprintf('\nCase 2: Non-Square Matrix');
matinverse(C2);
fprintf('\nCase 3:Rank Deficient Matrix');
matinverse(C3);
fprintf('\nCase 4:Matrix with zero pivot and Full Rank');
C4_inv=matinverse(C4);...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Linear Programming Questions \$50.00
Linear Programming
Equations
Infeasible
Unbounded
Regions
Finite Values
Dual Problems
Optimization
Variables
Statements
Matrices
Vectors
Duality Theorem
Conversion of Decimal Numbers Using Assembly Language \$10.00
Programming
Assembly Language
Decimal Numbers
ASCII Digits
Packets
Procedures
Buffers
Input
Output
Pointers
Strings
Variables
Database Development Questions \$40.00
Computer Science
Database Development
SQL Queries
Models
Tables
Relational Calculus
Relational Algebra
Flights
Employees
Airline Information
Foreign Key
Primary Key
Constraints
Unsafe Queries
Database Developments & SQL Queries \$20.00
Computer Science
Database Development
Relationships
SQL Queries
MS Access
Relational Schema
Referential Integrity
Books
Authors
Orders
Sales
Data Sets
Tables
Database Development Questions \$25.00
Computer Science
SQL
Database Development
Suppliers
Parts
Catalog
Tables
DBMS
Names
Queries
Statements
Test Results
Average Costs
Prices
Finance
Management
Automation Theory Questions \$38.00
Computer Science
Automation Theory
Numbers
Strings
Finite State
Free Grammar
Language
Series
Derivation
Mathematics
Instances
Letters
Live Chats