Home projects readings blog about

System of Equations

Published on Saturday, 23 January, 2016 general

System of Equations

A fishmonger sold 50 cods and 30 haddocks in one day for $1,050 dollars. The next day he sold 41 cod and 66 haddocks for 1,500. If the prices of the fish remained unchanged on both the days, what was the price of one cod and one haddock?

Let's solve this with a system of two linear equations.

Let's say the price of one cod is $p_1$ and the price of one haddock is $p_2$. The above problem can be converted like this:

$50p_1+30p_2=1,050$

$41p_1+66p_2=1,500$


    import numpy as np


A = np.array([[50,30],[41,66]])
B = np.array([1050, 1500])
X = np.linalg.inv(A).dot(B)


print(X)
[11.73913043 15.43478261]

The price of cod is $\approx$ $11.74.

The price of haddock is $\approx$ $15.43.