So there's this thing called fminsearch In Matlab, which allows you to just give it an expression, and it will try to minimize, and you give it some initial values, to try to say, hey, try these and then go find me a minimum solution. 