Question

In: Advanced Math

write a Matlab function file to solve system Ax=b by using the output of the function...

write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x


guideline


1.use the column access for the matrix entries


2. do not create any other matrix in your function-get your data directly from the matrix passed into your function


3.do not use Matlab command designed for solving system


function file LUFAC2A GIVEN BELOW


function [f, rp, flag] = lufac2a(a)


% The purpose of this function is to apply Gaussian elimination with


% partial pivoting to the input matrix a . (This follows the LINPACK


% algorithm except uses elementary Gaussian transformations from Matrix


% Computations). This function returns:


%


% f - matrix containing the information about the L and U matrices in the


% factorization PA=LU


%


% rp - array containing information about the row interchanges used in the


% elimination process


%


% flag - error flag (set to 0 if a is invertible, and set to k>0 if a


% nonzero pivot could not be found for column k)


%


% The calling sequence is [f, rp, flag] = lufac2(a)


[m,n] = size(a);


if m ~= n


disp('The matrix must be a square matrix.')


return


end


f = a;


rp = zeros(n,1);


for j=1:n-1


[mx,p] = max(abs(f(j:n,j)));


if mx == 0


flag = j;


return


end


p = p + j - 1;


rp(j) = p;


if p~=j


temp = f(j,j:n);


f(j,j:n) = f(p,j:n);


f(p,j:n) = temp;


end


i=(j+1):n;


f(i,j) = f(i,j)/f(j,j);


f(i,i) = f(i,i) - f(i,j)*f(j,i);


end


if f(n,n)==0


flag = n;


else


flag = 0;


end


return


Solutions

Expert Solution


a = input('Enter Input matrix a = \n')
[m,n] = size(a);


if m ~= n


disp('The matrix must be a square matrix.')


return


end


f = a;


rp = zeros(n,1);


for j=1:n-1


[mx,p] = max(abs(f(j:n,j)));


if mx == 0


flag = j;


return


end


p = p + j - 1;


rp(j) = p;


if p~=j


temp = f(j,j:n);


f(j,j:n) = f(p,j:n);


f(p,j:n) = temp;


end


i=(j+1):n;


f(i,j) = f(i,j)/f(j,j);


f(i,i) = f(i,i) - f(i,j)*f(j,i);


end


if f(n,n)==0


flag = n;


else


flag = 0;


end


return

%%%_____________________________________________

%% This code is LU

a = input('enter the a matrix a')
[m,n] = size(a);
L = eye(n,n);
%conditon chak...
if (m ~= n)
error('a is not a square matrix')
end
%partial_pivoting..
for i = 1:n-1
for j = i+1:n
[dummy,pos] = max(abs(a(i:n,i)));
if dummy~=0
     pos=pos+(i-1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
a([pos,i],:) = a([i,pos],:);
else
     break
end
%lover triangular matrix
multi = a(j,i)/a(i,i);
a(j,:) = a(j,:) - multi*a(i,:);
L(j,i) = multi ;
end
end
%disp('the upper tringular matrix');
disp(a);
disp(L)


Related Solutions

Write a function to solve a system of linear equations of the form Ax= b using...
Write a function to solve a system of linear equations of the form Ax= b using the iterative Gauss-Seidel method. You are free to use any basic MATLAB operation to implement the algorithm (i.e. you may use any combination of loops, indexing, math, etc.), but avoid “built-in” solution methods — you would not be allowed to use the GaussSeidel function if such a function existed. The function must also test for a number of possible issues. If an issue is...
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that...
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that begins with: function [C,N]=solvesys(A) [~,n]=size(A); b=fix(10*rand(n,1)) format long We are using format long to display a number in exponent format with 15 digit mantissas. If later on, you will need to switch back to the default format, type and run format The input is an matrix A. If A is invertible, the outputs are the matrix C, whose 3 columns x1, x2, x3 are...
Make the program(such as matlab) for solving the linear system Ax = b using the Naive-Gaussian...
Make the program(such as matlab) for solving the linear system Ax = b using the Naive-Gaussian elimination & also the Gaussian elimination with partial pivoting.
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). B) use...
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). B) use Gauss-siedel iteration. C)use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given. * A=[4,8,0,0;8,18,2,0;0,2,5,1.5;0,0,1.5,1.75] , B=[8;18;0.5;-1.75]. , (optimal w is 1.634.)
Write a MATLAB function function = pivGauss(.....) to solve linear equations using Gaussian Elimination with Partial...
Write a MATLAB function function = pivGauss(.....) to solve linear equations using Gaussian Elimination with Partial Pivoting. You'll need to employ Nested Loops. Thank you !
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi...
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi iteration. B) use Gauss-siedel iteration. 1) make sure to use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given. * A=[1,-2,0,0;-2,5,-1,0;0,-1,2,-0.5;0,0,-0.5,1.25]] , B=[-3;5;2;3.5]. , (optimal w is 1.5431.)
Write a .m function file on MATLAB that reads the parameters stored in the file missile...
Write a .m function file on MATLAB that reads the parameters stored in the file missile data.txt into MATLAB. The function should have the following declaration: function [X0, Y0, Z0, m0, mf, Thmag0, theta, phi, Tburn] = read input( input filename, M id) where input filename is a string variable denoting the name of the file to be read and M_id is an integer which denotes the missile ID. The outputs are the initial position (X0, Y0, Z0), initial and...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n. 2. C= A*B where A is of dimension m by p and B is dimension of p by n. So write matlab script to obtain Y and C in above problems.
Solve the linear system of equations Ax = b, and give the rank of the matrix...
Solve the linear system of equations Ax = b, and give the rank of the matrix A, where A = 1 1 1 -1 0 1 0 2 1 0 1 1 b = 1 2 3
Write a MATLAB script file to numerically solve any first order initial value problem using Rulers...
Write a MATLAB script file to numerically solve any first order initial value problem using Rulers method. Once code is working use it to solve the mixing tank problem below. Use a step size of 1 minute, and simulate the solution until the tank contains no more salt. Plot both the Euler approximation and the exact solution on the same set of axes. A tank contains 100 gallons of fresh water. At t=0 minutes, a solution containing 1 lb/gal of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT