Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Solve the linear least absolute value problem
ResourceFunction["L1Solve"][m,b] finds an x that solves the linear least absolute value problem for the matrix equation m.x==b. |
Solve a simple least absolute value problem:
| In[1]:= |
| Out[1]= |
Create a 4×3 matrix, and b is a length-4 vector:
| In[2]:= |
Use exact arithmetic to find a vector x that minimizes
:
| In[3]:= |
| Out[3]= |
Use machine arithmetic:
| In[4]:= |
| Out[4]= |
Use 20-digit-precision arithmetic:
| In[5]:= |
| Out[5]= |
Use a sparse matrix:
| In[6]:= |
| Out[7]= |
Here is some data:
| In[8]:= |
Find the line that best fits the data in the least absolute deviation sense:
| In[9]:= |
| Out[9]= |
Find the quadratic that best fits the data in the least absolute deviation sense:
| In[10]:= |
| Out[10]= |
Show the data with the two curves:
| In[11]:= |
| Out[11]= | ![]() |
For a vector b, L1Solve is equivalent to ArgMin[Norm[m.x-b,1],x]:
| In[12]:= | ![]() |
| In[13]:= |
| Out[13]= |
Create a 5×2 matrix and a length-5 vector:
| In[14]:= |
Solve the least absolute value problem:
| In[15]:= |
| Out[15]= |
This is the minimizer of
:
| In[16]:= | ![]() |
| Out[16]= | ![]() |
It also gives the coefficients for the line with least absolute deviation from the points:
| In[17]:= |
| Out[17]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License