## Contents

```% An example of recovery a sparse solution x from Ax = b using linearized Bregman iteration with line search
% The nonzero entries of x have iid Gaussian random values
```

## Generate problem data

```rand('seed', 0); randn('seed', 0);

m = 250; n = 500; % matrix dimension m-by-n
k = 25; % sparsity

A = randn(m,n); % random matrix
x_ref = zeros(n,1); % true vector
x_ref(randsample(n,k)) = randn(k,1); % Gaussian random values
b = A*x_ref; % finish generating equations Ax = b
```

## Solve problem

```alpha = 5*norm(x_ref,inf); % don't need to be exact, roughly 1 - 10 times norm(x_ref,inf) is fine
opts.stepsize = 2/alpha/normest(A*A',1e-2); % roughly 2/alpha/norm(A)^2
opts.tol = 1e-4; % stop once norm(Ax-b)<tol*norm(b)
opts.x_ref = x_ref;

t0 = tic;
[x,out] = lbreg_bbls(A,b,alpha,opts);
time = toc(t0);
```

## Reporting

```fprintf('time = %4.2e, ', time);
fprintf('solution relative error = %4.2e\n\n', norm(x - x_ref)/norm(x_ref));

figure;
plot(1:out.iter, out.hist_obj, 'k-', 'LineWidth', 2);
title('Dual objective')
xlabel('iteration'); ylabel('dual objective');

figure;
semilogy(1:out.iter, out.hist_err/norm(x_ref), 'k-', 'LineWidth', 2);
title('Primal solution relative error')
xlabel('iteration'); ylabel('||x - x_{ref}||_2/||x_{ref}||_2');
```
```time = 2.09e-002, solution relative error = 3.31e-005

```