You would probably get more help if you posted in the EVE Technology Lab forum than here. But this thread might help you out some. This is where I went to figure out how to calculate waste.
Basically you add waste after you calculate the minerals and apply PE there. But there is a twist with how the mats are calculated from reprocessing. That's what the thread was about back when they changed to this new logic.
It can get confusing after a bit but if you decide you don't want to mess with it any more, there are several programs and spreadsheets out there that do this for you already. I wrote one (Here
), there is Dedaf's sheet, Akita T has one, and there is EVE Meep. I think there are others as well but those are the ones I know of.
Hope that helps.