Page 1 of 2

math

Posted: Thu Aug 30, 2018 9:32 am
by avivchen64
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.
Thanks for your help,
Aviv

Re: math

Posted: Thu Aug 30, 2018 9:44 am
by Klaus
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

Re: math

Posted: Thu Aug 30, 2018 12:12 pm
by richmond62
Just possibly "1+10%" should be 1.1 and "10%" should be 0.1

although the whole thing is hard to understand.

Re: math

Posted: Thu Aug 30, 2018 2:22 pm
by [-hh]
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".

Re: math

Posted: Thu Aug 30, 2018 2:26 pm
by dunbarx
Only Hermann could have seen through all those nested parentheses...

Craig

Re: math

Posted: Thu Aug 30, 2018 5:11 pm
by avivchen64
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.
Thanks of your help,
Aviv

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

Re: math

Posted: Thu Aug 30, 2018 5:46 pm
by dunbarx
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

Re: math

Posted: Thu Aug 30, 2018 6:30 pm
by bogs
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.

Re: math

Posted: Fri Aug 31, 2018 1:10 pm
by [-hh]
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

Re: math

Posted: Wed Sep 05, 2018 1:50 pm
by avivchen64
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!

Re: math

Posted: Wed Sep 05, 2018 2:13 pm
by avivchen64

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

Re: math

Posted: Wed Sep 05, 2018 2:41 pm
by Klaus
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. 8)


Best

Klaus

Re: math

Posted: Wed Sep 05, 2018 2:55 pm
by dunbarx
Hi.

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

Craig

Re: math

Posted: Wed Sep 05, 2018 3:05 pm
by Klaus
Hi Craig,

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

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


Best

Klaus

Re: math

Posted: Wed Sep 05, 2018 6:36 pm
by avivchen64
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