Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2026-02-07 04:54:06
Size: 469
Comment: Initial commit
Revision 3 as of 2026-02-07 05:11:02
Size: 686
Comment: Add appoximation notes
Deletions are marked like this. Additions are marked like this.
Line 21: Line 21:
This is effectively what [[MATLAB/Svd|pinv]] does. This is effectively what [[MATLAB/Pinv|pinv]] does.

To calculate the rank ''k'' [[LinearAlgebra/LowRankApproximation|approximation]] of a matrix `A`, try:

{{{
[U, S, V] = svd(A);
U_k = U(:, 1:k)
S_k = S(1:k, 1:k)
V_k = V(1:k, :)
A_k = U_k * S_k * V_k'
}}}

MATLAB svd

The svd function calculates the SVD decomposition of any matrix.

Contents

  1. MATLAB svd
    1. Usage


Usage

To solve the problem Ax = b for any size matrix A, try:

[U, S, V] = svd(A);
S_inv = diag(1./diag(S));
x = V * S_inv * U' * b;

This is effectively what pinv does.

To calculate the rank k approximation of a matrix A, try:

[U, S, V] = svd(A);
U_k = U(:, 1:k)
S_k = S(1:k, 1:k)
V_k = V(1:k, :)
A_k = U_k * S_k * V_k'

The original A can be returned by U*S*V'.


CategoryRicottone

MATLAB/Svd (last edited 2026-02-07 05:32:46 by DominicRicottone)