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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

math

Post by avivchen64 » Thu Aug 30, 2018 9:32 am

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

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

Re: math

Post by Klaus » Thu Aug 30, 2018 9:44 am

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
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: math

Post by richmond62 » Thu Aug 30, 2018 12:12 pm

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
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: math

Post by [-hh] » Thu Aug 30, 2018 2:22 pm

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
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: math

Post by dunbarx » Thu Aug 30, 2018 2:26 pm

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

Craig

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

Re: math

Post by avivchen64 » Thu Aug 30, 2018 5:11 pm

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.

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

Re: math

Post by dunbarx » Thu Aug 30, 2018 5:46 pm

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: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: math

Post by bogs » Thu Aug 30, 2018 6:30 pm

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.
Image

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

Re: math

Post by [-hh] » Fri Aug 31, 2018 1:10 pm

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

Post by avivchen64 » Wed Sep 05, 2018 1:50 pm

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

Post by avivchen64 » Wed Sep 05, 2018 2:13 pm

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: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: math

Post by Klaus » Wed Sep 05, 2018 2:41 pm

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

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

Re: math

Post by dunbarx » Wed Sep 05, 2018 2:55 pm

Hi.

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

Craig

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

Re: math

Post by Klaus » Wed Sep 05, 2018 3:05 pm

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

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

Re: math

Post by avivchen64 » Wed Sep 05, 2018 6:36 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”