lscov — Solve linear least-squares systems with observation covariance weighting.

lscov(A,B) solves the linear least-squares system A*x = B. lscov(A,B,V) treats V as an observation covariance matrix, or as a vector of observation weights. lscov(A,B,V,alg) accepts "chol" and "orth" algorithm selectors.

Syntax

lscov(A,B)

How lscov works

  • A must be a nonempty 2-D numeric design matrix. B must be a vector with one value per row of A, or a matrix with the same number of rows as A.
  • The primary output has shape size(A,2) x size(B,2) for matrix right-hand sides, and size(A,2) x 1 for vector right-hand sides.
  • V may be omitted, empty, a scalar weight, a weight vector with one value per observation, or a dense square covariance matrix matching the observation count. Weights must be finite and nonnegative with at least one positive value.
  • The default "chol" algorithm uses Cholesky transformation for positive-definite covariance matrices when possible. Singular positive semidefinite covariance matrices fall back to the SVD-backed "orth" transformation.
  • Requested outputs follow MATLAB's [x,stdx,mse,S] form. stdx matches the coefficient shape, mse is a 1 x size(B,2) row, and S is available only when B is a vector.
  • Real and complex dense A/B are supported. Sparse inputs and provider-native GPU solves are not implemented in this slice.

Examples

Fit an unweighted line

A = [ones(3,1) (0:2)']; B = [1;3;5]; [x,stdx,mse,S] = lscov(A,B)

Expected output:

x is approximately [1; 2] and mse is 0.

Use observation weights

A = [ones(3,1) (0:2)']; B = [1;2;10]; w = [1;1;100]; x = lscov(A,B,w)

Expected output:

The high-weight third observation has more influence on x.

Using lscov with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how lscov changes the result.

Run a small lscov example, explain the result, then change one input and compare the output.

FAQ

Does lscov add an intercept automatically?

No. Include a column of ones in A when the model should include an intercept.

Does lscov run on the GPU?

No. The current implementation gathers GPU inputs and runs the dense weighted least-squares solve on the host.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how lscov is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.