Example uses of autorej, and matrix solvers in general.

Around the garden: fertilizer calculation

I have a small garden that gets a lot attention. I was concerned about proper fertilization, as it seemed that various commercial fertilizers used very different formulas for their products. So I studied the subject a bit and came up with this set of preferences for what a garden fertilizer should contain for each element, by pounds, for 250 square feet:

3.0

N

2.5

P

0.0

K

2.3

Ca

8.0

S

0.2

Fe

0.5

Mg

 

Now, my problem was that I didnít have access to individual chemicals, such as plan iron (Fe). What I had was various bags of commercial fertilizer with various compounds in various amounts. Here are photos of couple of them:

Note the percentages of each† element† (by weight). They have conveniently given percentages of each ELEMENT, not just per chemical, like iron sulfate. What I need is some combination of my on-hand fertilizers that would give me something close to the proportions I need. Here is a table of the things I had on hand when I was trying to figure this all out, with the stated amounts if, any, of Nitrogen(N), Phosphorus (P), Potassium (K), Calcium (Ca), Sulfur(S), Iron(Fe) and Magnesium (Mg) (see rightmost column).

Gypsum

Sulph90%

HypoN

3xP

AceStarter

Ironite

Copperas

Epsom

Mur_Of_K

MiraGro1

MiraGro2

Plantone

0

0

0.21

0

0.2

0.01

0

0

0

0.1

0.24

0.05

N

0

0

0

0.45

0.27

0

0

0

0

0.1

0.08

0.03

P

0

0

0

0

0.05

0.01

0

0

0.6

0.1

0.16

0.03

K

0.21

0

0

0

0

0.12

0

0

0

0

0

0.03

Ca

0.16

0.9

0

0

0

0.1

0.11

0.27

0

0.2

0

0.01

S

0

0

0

0

0.01

0.045

0.19

0

0

0

0

0

Fe

0

0

0

0

0

0.1

0

0.2

0

0

0

0.01

Mg

 

So here we have a nice linear algebra problem: the grid of numbers above (without the labels) is the matrix, and the red column in the earlier table is the desired right hand side. Solving this problem will give us the amount of each of these commercial products that we should use to achieve exactly the amount of each element I needÖ a proper balance of seven elements, not just two or three.

Note that it turns out this is NOT an ill-conditioned problem for which we need regularization. But there can still be problems. Here is the solution I got from autorej (presented as a column vector, as is traditional):

8.368921

6.140388

3.679031

1.521761

4.197724

4.043942

-0.12608

0.382606

-2.07644

3.108546

3.921425

1.908453

 

So we do have a problem. There is no way possible to add a NEGATIVE amount of the 7th and 9th fertilizers.† How should we solve this situation? We could be more careful and delete just the most negative fertilizer.† But letís try just deleting those two fertilizers, leaving 10 columns. Any reasonable solver will give this answer:


 

9.066108

6.988927

10.1148

2.198512

6.467905

3.007132

0.937665

-1.53124

-1.47252

1.17538

 

So now we have TWO MORE fertilizers that need to be deleted. This is a common problem in real life. The proportions of the elements that I want are not easily obtained from the products on my shelf.

But autorej has a non-negative solution. Letís let it worry about the algorithmic issues. Here is its solution:

10.95238

6.063144

14.28571

5.555556

0

0

1.052632

2.5

0

0

0

0

 

For a few years now I have used this or a similar combinationÖ depending on what new products I have, or what products I had to delete due to being out of it. The vegetable garden has done well with it. And the grass has done fantastic. But this particular formula is not right for everything: fruit trees should not have this much Nitrogen. So I have to reformulate a bit to cut the Nitrogen down when making fertilizer for my small orchard (20 modest trees).