nxn matrix as an input argument in function
87 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
function x = matrix(b, L, U)
A= L * U
x= inv(A)*b
end
I am trying to write a function that solves for A an matrix, b a known vector and x an unknown vector. How can I make the above work? In what form am I to input b, L and U into the function arguments?
For
b = $ \begin{pmatrix}a\\ b \\ c \end{pmatrix} $.
L =$ \begin{pmatrix} d & e & f\\ g & h & i \\ j & k & l\end{pmatrix} $
U=$ \begin{pmatrix} m & n & o\\ p & q & r \\ s & t & u\end{pmatrix} $
would my input be like this: matrix([a][b][c], [d,e,f][g,h,i][j,k,l], [m,n,o][p,q,r][s,t,u]) ??
0 Kommentare
Antworten (1)
Adriano Filippo Inno
am 17 Nov. 2020
Bearbeitet: Adriano Filippo Inno
am 17 Nov. 2020
I'm a bit confused by your question. Do you need to solve a linear system with the LU method?
If yes, this function will work:
function x = linSys(A, b)
[L,U,P] = lu(A); % LU decomposition
y = L\(P*b);
x = U\y;
end
To use it:
A = magic(5); % define your A here
b = ones(5, 1); % define your b here
x = linSys(A, b);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!