hello, can you help me develop a nxn matrix using Doolittle method displaying L,U,X while asking for matrix size, coefficient and the constant Thank you, I can't start it.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
format short g
A=input('Enter the elements of the coefficient
matrix in array:');
Asks the user to enter the
elements of A
b=input('Enter the elements of the constant
vector:');
Asks the user to enter the
elements of b
L(1,1)=1; L(2,2)=1; L(3,3)=1; Sets the diagonal entries
of L to 1.
U(1,1)=A(1,1); U(1,2)=A(1,2); U(1,3)=A(1,3); Solves all the first row
elements of U.
L(2:3,1)=A(2:3,1)/U(1,1); Solves the 1st col.
Elements of L except L11.
(L11 = 1)
U(2,2)=A(2,2)-L(2,1)*U(1,2); Solves the 2nd row elements
of U except U21. (U21 = 0) U(2,3)=A(2,3)-L(2,1)*U(1,3);
L(3,2)=(A(3,2)-L(3,1)*U(1,2))/U(2,2); Solves the 2nd column
elements of L except L12
and L22. (L12 = 0, L22 = 1)
U(3,3)=A(3,3)-sum([L(3,1:2)].*[U(1:2,3)]'); Solves the 3rd row elements
of U except U31 and U32.
(U31 = 0, U32 = 0)
Y=inv(L)*b; Solves for Y from LY=b
X=inv(U)*Y; Solves for X from UX=Y
disp('L = ') Displays L =
disp(L) Displays the elements of L
disp('U = ') Displays U =
disp(U) Displays the elements of U
disp('X = ') Displays X =
disp(X)
0 Commenti
Risposte (1)
Arif Hoq
il 12 Feb 2023
you defined your A matrix with at least 3 columns. So you need to specify your A matrix elements >= 3. then generate your matrix A.
format short g
A=input('Enter the elements of the coefficient matrix in array:');
A=randi(100,A,A);
% Asks the user to enter the elements of A
b=input('Enter the elements of the constant vector:');
% Asks the user to enter the elements of b
L(1,1)=1;
L(2,2)=1;
L(3,3)=1;
%Sets the diagonal entries of L to 1.
U(1,1)=A(1,1);
U(1,2)=A(1,2);
U(1,3)=A(1,3);
%Solves all the first row elements of U.
L(2:3,1)=A(2:3,1)/U(1,1);
%Solves the 1st col. Elements of L except L11.(L11 = 1)
U(2,2)=A(2,2)-L(2,1)*U(1,2);
% Solves the 2nd row elements of U except U21. (U21 = 0) U(2,3)=A(2,3)-L(2,1)*U(1,3);
L(3,2)=(A(3,2)-L(3,1)*U(1,2))/U(2,2);
% Solves the 2nd column elements of L except L12 and L22. (L12 = 0, L22 = 1)
U(3,3)=A(3,3)-sum((L(3,1:2)).*(U(1:2,3))');
% Solves the 3rd row elements of U except U31 and U32.(U31 = 0, U32 = 0)
Y=inv(L)*b; %Solves for Y from LY=b
X=inv(U)*Y; %Solves for X from UX=Y
disp('L = ') %Displays L =
disp(L) %Displays the elements of L
disp('U = ') %Displays U =
disp(U) %Displays the elements of U
disp('X = ') %Displays X =
disp(X)
0 Commenti
Vedere anche
Categorie
Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!