Matlab Programming help! Please provide the code for following question. Write a
ID: 2081139 • Letter: M
Question
Matlab Programming help! Please provide the code for following question.
Write a program that finds the solution of an n-by-n system of linear equations, represented by Ax = b, when A is an upper triangular matrix. Your program should use backsolving to find unknowns from x(n) to x(1). For example, for n = 4, the solution for unknowns x(4) to x(1) is obtained as x(4) = b(4)/A(4, 4) x(3) = [b(3) - A(3, 4)*x(4)]/A(3, 3) x(2) = [b(2) - A(2, 3)*x(3) - A(2, 4)*x(4)]/A(2, 2) x(1) = [b(1) - A(1, 2)*x(2) - A(1, 3)*x(3) - A(1, 4)*x(4)]/A(1, 1) (A_11 0 0 0 A_12 A_22 0 0 A_13 A_23 A_33 0 A_14 A_24 A_34 A_44) (x_1 x_2 x_3 x_4) = (b_1 b_2 b_3 b_4) You are ALLOWED to use the "dot" command of MATLAB. x(n) = b(n)/A(n, n); % The last unknown is obtained first separately. The rest of unknowns can be obtained in one loop.Explanation / Answer
code
clc
clear all;
n= input('size of the matrix=');
At=rand(n);%choose the random value for square matrix of size n
b=rand(n,1);%choose the column matrix b of size n *1
A=triu(At);%upper triangular matrix of At
x=zeros(n,1);%choose x matrix of n by 1
x(n)=b(n)/A(n,n); %calculation of last element of x matrix
p=zeros(1,n-1);
for mm=(n-1):-1:1
for nn=(n-1):-1:1
p(1,nn)=A(mm,nn+1)*x(nn+1);
pp=sum(p);
end
x(mm) =(b(mm)-pp)/A(mm,mm);%finding the value of x by the iterative back solving method
end
c=A%verifying the result x with c they should be the same
%paste as it is