HERE IS THE CODE I FIXED BUT STILL DOESN'T WORK
NOTE: THE VARIABLE x = zeros(size(b)) CAN'T BE CHANGED CAUSE HAS BEEN SET BY ASSESSOR
HI EXPERTS I NEED HELP TO SOLVE THIS HOMEWORK PROBLEM FOR MATLAB CODE
A COUPLE OF TIMES I TRIED LAST TIME TO ASK BUT ALL OF THE ANSWERS WERE WRONG
PLEASE KINDLY HELP ME FIND THE RIGHT SOLUTION, ANY HELP WILL BE VERY APPRECIATE
Ok, your algorithm is a bit off the mark. You were thinking along the right paths, however. For these kinds of problems, the best way to learn is to do the steps by hand and then thinking about how you will implement them via code.
I have provided both the text and the screenshot for your better
understanding. The screenshot also has some comments for your help.
Please note that this is a script file which is to be saved as
backsub.m in your MATLAB root directory.
The script backsub.m gives the value of the
variable matrix as output. The input must be a square upper
triangular non-singular matrix with none of the diagonal elements
as 0.
backsub.m
function x = backsub(U,b)
n = length(b); %calculating size of solution vector
x = ones(size(b)); %initializing solution vector
for i=n:-1:1
x(i) = b(i)/U(i,i); %solving the last row of the matrix
b(1:i-1) = b(1:i-1) - U(1:i-1,i)*x(i); %updating the constant
values so that the previous row can now be treated as the last row
of the matrix
end
fprintf("result of backward substitution\n");
disp(x);
end
OUTPUT
I have attached screenshots for 3 random test cases, one of them in the question and the other 2 from random sources.
Example matrix in question
3x3 matrix
4x4 matrix
*A humble request* - If you have any doubt, please use the
comment section to communicate. This will clarify your doubt, and
also help me to get better at answering your next questions. At the
same time, If my answer helped you, please consider leaving an
upvote. I hope you understand my viewpoint. Thank you :)
HERE IS THE CODE I FIXED BUT STILL DOESN'T WORK NOTE: THE VARIABLE x = zeros(size(b))...
Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function takes as input: U, an n x n upper triangular matrix b, an n x 1 vector for the right-hand-side of the matrix equation and returns as output: x, an n x 1 solution vector x function x = backsub(U,b) % Initialize the output vector. This will speed up computation by pre-allocating the memory. n = length(b); x = zeros(size(b)); % Do the backward...
Function LUfac_solver.m is provided here: function [x] = LUfac_solver(LU,b,piv) % % function [x] = LUfac_solver(lu,b) % % This program employs the LU factorization to solve the linear system Ax=b. % % Input % LU: lu matrix from GEpivot_new function % b: right side column vector (ordered corresponding to original vector % sent to GEpivot_new) % piv: vector indicating the pivoting (row interchanges that took place % during GE % % Output % x: solution vector % % Written by Steve...
(a) Suppose we want to solve the linear vector-matrix equation Ax b for the vector x. Show that the Gauss elimination algorithm may be written bAbm,B where m 1, This process produces a matrix equation of the form Ux = g , in which matrix U is an upper-triangular matrix. Show that the solution vector x may be obtained by a back-substitution algorithm, in the form Jekel (b) Iterative methods for solving Ax-b work by splitting matrix A into two...
In this exercise you will work with LU factorization of an matrix A. Theory: Any matrix A can be reduced to an echelon form by using only row replacement and row interchanging operations. Row interchanging is almost always necessary for a computer realization because it reduces the round off errors in calculations - this strategy in computer calculation is called partial pivoting, which refers to selecting for a pivot the largest by absolute value entry in a column. The MATLAB...
I need to create a MATLAB function, bvp_solve.m, to approximate the solution y(x). The function takes the number of grid points n as an input. The outputs are grid vector x and the solution vector y %% This is the function i have so far: function [xi, yi] = bvp_solve(n) % BVP_SOLVE computes the solution y(x) of a two-point boundary value problem % using finite difference method (FDM). % The governing equation is % y''' = -y + (x -...
I already solved part A and I just need help with part B 1. Matrix Multiplication The product of two n xn matrices X and Y is a third n x n matrix 2 = XY, with entries 2 - 21; = xixYk x k=1 There are n’ entries to compute, each one at a cost of O(n). The formula implies an algorithm with O(nº) running time. For a long time this was widely believed to be the best running...
In this exercise, you will work with a QR factorization of an mxn matrix. We will proceed in the way that is chosen by MATLAB, which is different from the textbook presentation. An mxn matrix A can be presented as a product of a unitary (or orthogonal) mxm matrix Q and an upper-triangular m × n matrix R, that is, A = Q * R . Theory: a square mxm matrix Q is called unitary (or orthogona) if -,or equivalently,...
I want to change this C code so that instead of prompting the user to enter the argument value, or requiring the argument be entered after by pressing the “enter” key, instead I want the code changed so that the program opens a file, (which include the input values) read in the elements and pass in the input file as a command line argument. (the input file includes the size of the matrix and the matrix values) Here's an example...
1. (All students!) For matrices with special properties, it is possible to create special versions of Gauss elimination. Suppose matrix A (nxn) is symmetric (which means that A-A). Suppose also that A is positive definite; this means that the scalar = xTAx is always 20 for every vector x , and J-0 only if x = 0 In this case it can be shown that the usual Gauss elimination process, which effectively creates the factorization A LU, can be simplified...