Hi,
To find the values of 'pa' and 'pb' that maximize the equation "pi = (pa + pb) * na * nb", where 'na' is a function of 'pa' and 'nb' is a function of 'pb', and to understand how the optimal combination changes with parameters 'ba' and 'bb', you can use MATLAB's Global Optimization Toolbox.
All of these objectives can be achieved by using this toolbox along with functions like 'plot' and 'surf', which would eliminate the need for redundant code as well.
Refer to the following MathWorks documentation for detailed information regarding Global Optimization Toolbox: