Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help writing this program using Matlab. To solve a system of equations AX=

ID: 2268370 • Letter: N

Question

Need help writing this program using Matlab.

To solve a system of equations AX= b, write a program that uses matlab function svd to create rotation matrices U and V and diagonal scale matrix S so that A is factored into A=USVT.

• Since U and V are rotation matrices, they are invertible and the inverse of a rotation matrix is its transpose.

• Inverse of a scale matrix is its transpose with reciprocals of non-zero entries.

To solve for AX= b,   we can write USVT X = b

Or        SVT X = UTb,

S is a diagonal matrix, the inverse of scale matrix is reciprocal of non-zero scale factors. So

            VT X = S-T UTb

Now V is rotation matrix, multiply by V and we have the solution to the system AX= b

            X = VS-T UTb

Here are some tests for the program to solve:

1.
x + y = 2
x + 2y = 3

2.
x + y = 2
x + 2y = 3
2x + y = 3

Explanation / Answer

clc
clear all
A=input('Enter matrix A:'); %[1 1; 1 2; 2 1];
b=input('Enter constants: '); %[2;3;3];
[U S V]=svd(A);
A1=U*S*V';
disp('USVT gives A')
disp(A1)
fprintf('Rotational matrix U is ')
disp(U)
fprintf('Rotation matrix V is ')
disp(V)
fprintf('Diagonal scale matrix ')
disp(S)
fprintf('Transpose of U Matrix is ')
disp(U')
fprintf('Inverse of U matrix is ')
disp(inv(U))
fprintf('Transpose of V Matrix is ')
disp(V')
fprintf('Inverse of V matrix is ')
disp(inv(V))
S1=1./S; %inverse of S (S^-1)
S1(isinf(S1))=0; % Making all infinite values to zero after finding inverse of S

X=((V*(S1'))*U')*b; %Solution
fprintf('Solution of X is X =')
disp(X)

Output:

Enter matrix A:[1 1;1 2;2 1]
Enter constants: [2;3;3]
USVT gives A
1.0000 1.0000
1.0000 2.0000
2.0000 1.0000

Rotational matrix U is
-0.4264 -0.0000 -0.9045
-0.6396 -0.7071 0.3015
-0.6396 0.7071 0.3015

Rotation matrix V is
-0.7071 0.7071
-0.7071 -0.7071

Diagonal scale matrix
3.3166 0
0 1.0000
0 0

Transpose of U Matrix is
-0.4264 -0.6396 -0.6396
-0.0000 -0.7071 0.7071
-0.9045 0.3015 0.3015

Inverse of U matrix is
-0.4264 -0.6396 -0.6396
-0.0000 -0.7071 0.7071
-0.9045 0.3015 0.3015

Transpose of V Matrix is
-0.7071 -0.7071
0.7071 -0.7071

Inverse of V matrix is
-0.7071 -0.7071
0.7071 -0.7071

Solution of X is
X = 1.0000
1.0000

Output:

Enter matrix A:[1 1;1 2]
Enter constants: [2;3]
USVT gives A
1.0000 1.0000
1.0000 2.0000

Rotational matrix U is
-0.5257 -0.8507
-0.8507 0.5257

Rotation matrix V is
-0.5257 -0.8507
-0.8507 0.5257

Diagonal scale matrix
2.6180 0
0 0.3820

Transpose of U Matrix is
-0.5257 -0.8507
-0.8507 0.5257

Inverse of U matrix is
-0.5257 -0.8507
-0.8507 0.5257

Transpose of V Matrix is
-0.5257 -0.8507
-0.8507 0.5257

Inverse of V matrix is
-0.5257 -0.8507
-0.8507 0.5257

Solution of X is
X = 1.0000
1.0000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote