# Coefficients of combination of matrices

**URL:** <https://discourse.julialang.org/t/coefficients-of-combination-of-matrices/98241>\
**Category:** Optimization (Mathematical)\
**Created:** [May 3, 2023, 9:04am UTC](https://discourse.julialang.org/t/coefficients-of-combination-of-matrices/98241 "2023-05-03T09:04:45Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 3, 2023, 12:13pm UTC](https://discourse.julialang.org/t/coefficients-of-combination-of-matrices/98241/3 "2023-05-03T12:13:53Z")

</div>

> [@microlifecc](#):
>
> Is there any efficient way to find the coefficients `x1, x2, x3` such the the combination is approximately equal to _D_?

You have to make more precise what what you mean by “approximately equal”. Typically, you would minimize \Vert x\_1 A - x\_2 B - x\_3 C - D \Vert in some norm \Vert \cdots \Vert, but which norm do yo want?

@albheim’s solution suggested the L\_2 (Euclidean) [“vectorized”](https://en.wikipedia.org/wiki/Vectorization_(mathematics)) ([Frobenius](https://mathworld.wolfram.com/FrobeniusNorm.html)) norm, which makes this a constrained least-squares problem. (If you let x\_3 = 1 - x\_1 - x\_2 to eliminate the equality constraint, then it is bound-constrained least-squares; see also this thread: [Suggestions needed for bound-constrained least squares solver](https://discourse.julialang.org/t/suggestions-needed-for-bound-constrained-least-squares-solver/35611)). If you use the L\_1 or L\_\infty vectorized norms, then it is equivalent to an LP (linear programming) problem. In any of these cases it is convex, and so it can be solved by lots of algorithms (e.g. via Convex.jl, JuMP.jl, StructuredOptimization.jl, …). With only 3 unknowns (or 2, if you eliminate x\_3) and 10^6 equations, it’s not a particularly big problem, so lots of algorithms should be fine.

---

_[View the full topic](https://discourse.julialang.org/t/coefficients-of-combination-of-matrices/98241)._
