# Regularised Linear least squares via SVD in Matlab

enter image description here

Basically I'm trying to create a Matlab script where I can create the the Matrix S with diagonal entries as shown in equation 4 of the picture for different sizes n. However, I'm really struggling to do this. I can find the reduced SVD completely fine, it's just the creation of this 'S' matrix that I can't work out

Given $$\Sigma_1$$, you can use the MATLAB's command $$\texttt{diag()}$$ to extract the diagonal elements of the matrix. After that, use element-wise operations to calculate the diagonal elements of $$S$$, and finally, use $$\texttt{diag()}$$ again to form the matrix $$S$$. It would look something like this:
[U1,Sigma,V] = svd(A,0);