Here is my problem:

I have a set of 'n' colors including the primary colors and their codes in hexadecimal. Now given another color 'x' I wonder if it's actually possible to come up with a mix between two or more of the colors of the set that will produce 'x'. The mix should be subtractive.

Here is an example of the result of the algorithm:

My set of colors is: c1, c2, c3, c4, c5, c6. I am trying to find the mix to produce the color x. The result could be: 50% of c1, 25% of c4 and 25% of c5.

If anyone could point me in the right direction (or at least tell me if it is unfeasible), any help would be gladly appreciated!


1 Answer 1


This is a basic linear algebra problem. Let b = [ b1, b2, b3 ] be your mixed colour, x = [ x1, x2, ... xn ] be your solution, I = [ 1, 1, 1 ] (or whatever your white value is), and A = [ c1, c2, ..., cn ] be your colour set where each ci is a column vector in the matrix A. You must solve for x in the the equation I - Ax = b or Ax = I - b. You can check out the Khan Academy video about how to do that here if you do not already know how.

If there is no solution to this equation there is also no subtractive mix (obviously), but there is also no subtractive mix if there is a value in x, xi, that is negative or greater than one. If there is a negative value then you are actually adding the colour, and if there is one greater than one, you are subtracting the colour more than once. Otherwise your solution is the vector x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.