## math

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### math

Hi there,
I'm trying to make a function to process a number through a formula:

1000000/((((1+10%)^(67- {the number} ))-1)/10%)

btw this number can be changed by the user, and then there'll be a different result.
Aviv

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

Hi Aviv,

welcome to the forum!

Hm, I don't see a question!?
And what is the 10% of? -> ...1+10%...
10% of what?

Best

Klaus

richmond62
Livecode Opensource Backer
Posts: 2792
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

### Re: math

Just possibly "1+10%" should be 1.1 and "10%" should be 0.1

although the whole thing is hard to understand.

[-hh]
VIP Livecode Opensource Backer
Posts: 1811
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

### Re: math

Yes "%" is here percent of one, so 10%=0.1, 1+10%=1.1
Your divisor is an annuity, LC has an own function for that. See the dictionary for "annuity".
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
Posts: 5625
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: math

Only Hermann could have seen through all those nested parentheses...

Craig

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

This formula's result is how much money you need to invest in the NASDAQ per year to have 1M dollars by retirement, this is not something that I can change, the number that changes by user of the app is his age. his age the part of the formula that changes I need to insert a number that the user gave and run it in this formula and show the result.
Aviv

btw I dont hv a clue what the 10% is of.

dunbarx
VIP Livecode Opensource Backer
Posts: 5625
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: math

Conceptually, there must be a reason.

Programmatically, know that the function will fail, due to the "%" as part of the argument. LC will not allow:

Code: Select all

``put 4/10%``
How that should be changed (0.1?) is a question.

Craig

bogs
Posts: 2382
Joined: Sat Feb 25, 2017 10:45 pm

### Re: math

This is what -hh is referring to -
Lc Dictionary wrote: Use the annuity function to calculate the present or future value of an annuity or to calculate loan payments.

The formula for the value of an ordinary annuity is

(1 - (1 + *interestRate*)^(- *numberOfPeriods*))/ interestRate

The annuity function calculates this value.

The numberOfPeriods and the interestRate must use the same unit of time. For example, if the periods are months, the interest rate is the interest per month.

You can use the annuity function to calculate the amount of loan payments as follows:

paymentAmount = totalAmount/annuity(rate,periods)

For example, if the loan is for \$2500 at an interest rate of 2% per month and is to be repaid in a year, the monthly payment is 2500/annuity(.02,12) or \$236.40.

[-hh]
VIP Livecode Opensource Backer
Posts: 1811
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

### Re: math

To use exactly your formula (with the exorbitant interest rate):

Code: Select all

``````on mouseUp
put fld "input" into age -- contains the age in years
put max(1,67-age) into x -- avoid division by zero
put 1000000 into v -- the target amount
put 0.1 into r -- the interest rate 10% of one = 0.1
put yearlyAmount(x,r,v) into fld "output"
end mouseUp

function yearlyAmount x,r,v
put v/((((1+r)^x)-1)/r) into ann
return format("%.2f",ann) -- cash format = two digits
end yearlyAmount``````
shiftLock happens

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

oh my god! thank you very much! you're a life saver! <3
a big thanks to all of those who tried! you've helped me too!

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

Code: Select all

``put max(1,67-age) into x -- avoid division by zero``
sorry to bug, but I live code can't run this line and say there's an error here, I tried to figure out what's wrong but I don't seem to be able to. this is the error:
excution error at line 21 (Operators -: error in right operand), char 1

it worked a minute ago, I didn't change anything then it didn't work.

thanks again,
Aviv

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

Hi Aviv,

make sure -> age is a number, resp. check what is really in field "input".
If everything is OK, just quit Livecode and start again, helps most of the time.

Hint for the future:
If you do not know the task exactly (or have no idea whatsoever), it is hard to find a solution for it!
Unless you have Hermann in your crew.

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
Posts: 5625
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: math

Hi.

Perhaps "1,67" is not a number. (comma)

Craig

Klaus
Posts: 10483
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

Hi Craig,

this IS in fact a number, in most european countries, but please look up the MAX() function in the dictionary.

Aviv, maybe some parens will help:
...
put max(1,(67-age)) into x
...

Best

Klaus

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

hi Klaus,
I did as you suggested but still, no luck.
it didn't help,
do you have another way to solve problems like this?

Aviv