How can I model a system in Matlab consisting of Solar PV, Several Batteries from Electrical vehicles, and a grid altogether so that the load demand is fulfilled in such a way that the cost of energy is minimum? I want to model a controller that generates different switching signals which indicates what sources to use to serve the load according to the availability of the sources and load demand? I want to minimize the total energy cost.