I'm no computer scientist but I'd have thought something using Newton-Raphson would work.
Otherwise I'm sure there are solvable simultaneous equations there which if it wasn't 11pm I could write down.
edit:
720*x + A*y + B*z = 600
(A + 720)/45 = B/55
where prices are x y & z.
Solve by substitution and you get your answer.
Wow, thanks! I'm not quite sure how I'll represent this in code, but I'll have a play around with it. Much appreciated.![]()
See if this works. I've probably made a mistake somewhere.
edit:
Yep I can see a mistake.
rho = daytime %.
Looks like out of contract prices, i do think people are over complicating this, post up the cyarge period and the kwh used as shown on the bill please
From the information you've given us we have estimated you'll use 4865 kWh in a year
The first 720 kWh of daytime usage will be charged at 25.868p per kWh: £186.25
The next 1469 kWh of daytime usage will be charged at 17.661p per kWh: £259.44
The remaining 2676 kWh will be charged at 6.123p per kWh: £163.85
Discount (I can ignore this for now): 1.78p/kWh off tier 2 rates for Economy 7 customers paying by Monthly Direct Debit up to a maximum of £38.09 a year
VAT: £28.57
Total: £600.02
However the numbers are slightly off because they're also applying a discount of 1.78p/kWh up to £38.09 on the 2nd tier.
What this is an actual bill?
If so it will tell you what Kwh you use in each tier and no maths is needed.
Step away from uswitch and other comparison sites, they are less than useless and you'll end up paying through the rough.
They cant calculate tariffs other than tariffs with one single rate, as well as applying discounts you may not get.
If you know how much you use, make a spreadhseet yourself, yes its more work, but its worth it.
Think I've done it, including the discount for DD payment. I couldn't get it to work until i realised that VAT is only 5% on electricity.....
Fill in all the green cells and then press the "Calculate Usage" button.
You'll have to enable macros to use the button, or you can just goal seek manually.
If you do it manually you need to Goal Seek
Set Cell : E29
To Value : Whatever is in C2
By changing cell : C32
That gives you the exact numbers created by USwitch.
https://dl.dropboxusercontent.com/u/47824599/Elec Calc.xlsm
Sub FindUseage()
wsTargetCost = Range("c2").Value
wsDayUsePerc = Range("c4").Value
wsNightUsePerc = 1 - Range("c4").Value
wsDayTier1Thresh = Range("c8").Value
wsTier2DiscRate = Range("c10").Value
wsTier2MaxDis = Range("c12").Value
wsDayTier1Rate = Range("c21").Value
wsDayTier2Rate = Range("c23").Value
wsNightRate = Range("c25").Value
wsGuess = 0
wsFineTune = 1
Do
wsGuess = wsGuess + 1 / wsFineTune
wsDayUseUnits = wsGuess * wsDayUsePerc
wsNightUseUnits = wsGuess * wsNightUsePerc
wsDayTier1Units = WorksheetFunction.Min(wsDayTier1Thresh, wsDayUseUnits)
wsDayTier2Units = WorksheetFunction.Max(wsDayUseUnits - wsDayTier1Units, 0)
wsDayTier1Cost = wsDayTier1Units * wsDayTier1Rate / 100
wsDayTier2Cost = wsDayTier2Units * wsDayTier2Rate / 100
wsNightCost = wsNightUseUnits * wsNightRate / 100
wsDiscount = WorksheetFunction.Max(wsDayTier2Units * wsTier2DiscRate / 100, wsTier2MaxDis)
wsCalcedCost = (wsDayTier1Cost + wsDayTier2Cost + wsNightCost - wsDiscount) * 1.05
If Round(wsCalcedCost, 2) < Round(wsTargetCost, 2) Then
wsLowLimit = wsGuess
Else
If Round(wsCalcedCost, 2) > Round(wsTargetCost, 2) Then
wsHighLimit = wsGuess
wsFineTune = 10
wsGuess = wsLowLimit
Else
wsResult = wsGuess
Exit Do
End If
End If
Loop
Range("C32").Value = wsGuess
End Sub