Posts: 203
Threads: 41
Joined: Mar 2019
I totally understand what you are writing, and that's what I do if I already have all four values
and want to find out the balance after n years.
But now I need to calculate A, so I cannot write what it is if the code is supposed to find out.
So the question is: how do I calculate A?
Posts: 4,229
Threads: 97
Joined: Sep 2016
(Apr-07-2019, 12:00 PM)mcgrim Wrote: All I am trying to do is to calculate A, how large does it need to be in order for the last element
of the list to be either 0 or a negative number?
This will tell you the balance after n years:
def f(balance, r, A, n):
for year in range(n):
balance = balance * (r / 100.0 + 1) - A
return balance If you want to calculate A such that the balance is positive using this, you would need to run it with different values of A until you got a positive balance.
Posts: 2,344
Threads: 62
Joined: Sep 2016
I think ichabod's post is very useful, but I will also say that you may want to Google "binary search" as it seems well-suited to your problem.
Posts: 4,229
Threads: 97
Joined: Sep 2016
Well, there's also a simple formula that solves this problem.
Posts: 203
Threads: 41
Joined: Mar 2019
to ichabod801:
The code you wrote above is the one I already had.
I totally understand what you are saying but perhaps you misunderstood my question.
I am actually looking to write a code where A is an output.
Makes sense?
Posts: 203
Threads: 41
Joined: Mar 2019
what would be the formula for A ? If you believe you cannot give me a straight answer, may you perhaps write a code concerning something similar ?
Posts: 4,229
Threads: 97
Joined: Sep 2016
It's a load calculation. Do a web search for the formula for loan payments and you'll find it.
Posts: 203
Threads: 41
Joined: Mar 2019
I don't need a new formula, I am using the one I have, I just have to change it in a way so A is the output, but I don't know how.
On the interned I can only find different formulas for the loan payment, not exactly this one, and no formula found returns A. If you are aware of a website that has what I need, please share.
Posts: 4,229
Threads: 97
Joined: Sep 2016
(Apr-08-2019, 08:48 PM)mcgrim Wrote: On the interned I can only find different formulas for the loan payment, not exactly this one, and no formula found returns A.
'A' is the loan payment.
Posts: 203
Threads: 41
Joined: Mar 2019
not exactly.
A is a fixed amount that is paid every year.
Every year you pay something from which A is subtracted (see formula on the code)
|