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
Amust be a nonempty 2-D numeric design matrix.Bmust be a vector with one value per row ofA, or a matrix with the same number of rows asA.- The primary output has shape
size(A,2) x size(B,2)for matrix right-hand sides, andsize(A,2) x 1for vector right-hand sides. Vmay 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.stdxmatches the coefficient shape,mseis a1 x size(B,2)row, andSis available only whenBis a vector. - Real and complex dense
A/Bare 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.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how lscov is executed, line by line, in Rust.
- View the source for lscov in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.