[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby math.pow equivalent

John Butler

3/29/2007 8:44:00 PM

Hi,

I am trying to calculate a monthly payment for a loan in Ruby. Does
anyone know what the equivalent for math.pow in Java is for Ruby?

@monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))

Ive searched everywhere and cant seem to find anything.

thanks

Johnny B

--
Posted via http://www.ruby-....

6 Answers

Brian Candler

3/29/2007 9:01:00 PM

0

On Fri, Mar 30, 2007 at 05:43:38AM +0900, John Butler wrote:
> I am trying to calculate a monthly payment for a loan in Ruby. Does
> anyone know what the equivalent for math.pow in Java is for Ruby?
>
> @monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))
>
> Ive searched everywhere and cant seem to find anything.

http://www.rubycentral.com/book/ref_c_float.html#Float.Arithmetic...

Look for 'exponentiation'

Harry

3/29/2007 9:06:00 PM

0

On 3/30/07, John Butler <johnnybutler7@gmail.com> wrote:
> Does
> anyone know what the equivalent for math.pow in Java is for Ruby?
>
> @monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))
>
>

Is this what you are looking for?

p 4 ** 3

Harry

--

http://www.kakueki.com/ruby...
Japanese Ruby List Subjects in English

Drew Olson

3/29/2007 9:08:00 PM

0

John Butler wrote:
> Hi,
>
> I am trying to calculate a monthly payment for a loan in Ruby. Does
> anyone know what the equivalent for math.pow in Java is for Ruby?
>
> @monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))
>
> Ive searched everywhere and cant seem to find anything.
>
> thanks
>
> Johnny B

I think this is what you're looking for:

irb(main):001:0> 2 ** 1
=> 2
irb(main):002:0> 2 ** 2
=> 4
irb(main):003:0> 2 ** 3
=> 8
irb(main):004:0> 2 ** 4
=> 16

--
Posted via http://www.ruby-....

John Butler

3/30/2007 9:22:00 AM

0

Drew Olson wrote:
> John Butler wrote:
>> Hi,
>>
>> I am trying to calculate a monthly payment for a loan in Ruby. Does
>> anyone know what the equivalent for math.pow in Java is for Ruby?
>>
>> @monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))
>>
>> Ive searched everywhere and cant seem to find anything.
>>
>> thanks
>>
>> Johnny B
>
> I think this is what you're looking for:
>
> irb(main):001:0> 2 ** 1
> => 2
> irb(main):002:0> 2 ** 2
> => 4
> irb(main):003:0> 2 ** 3
> => 8
> irb(main):004:0> 2 ** 4
> => 16



Yes this is what i am looking for. How do i then use it to calculate
amonthly payment, i have tried quite a few things but cant get the
syntax right: @monthlypayment =
@principal*@rate/(1-**(1/(1+@rate),@payments))


So for the example below:

Suppose you finance your car with a loan of $12000 at a yearly interest
rate of 11% for four years, and make equal payments monthly. How much
will your payments have to be? Here the parameters are principal P =
$12000, interest rate i = 0.11, number of years n = 4, and number of
periods per year q = 12. Then the monthly car payment M is given by

M = Pi/[q(1-[1+(i/q)]-nq)],
= ($12000)(0.11)/[(12)(1-[1+(0.11/12)]-(4)(12))],
= $110/(1-1.009166666...-48),
= $310.15.


Anyone done this before?


--
Posted via http://www.ruby-....

Stefano Crocco

3/30/2007 9:53:00 AM

0

Alle venerdì 30 marzo 2007, John Butler ha scritto:
> Drew Olson wrote:
> > John Butler wrote:
> >> Hi,
> >>
> >> I am trying to calculate a monthly payment for a loan in Ruby. Does
> >> anyone know what the equivalent for math.pow in Java is for Ruby?
> >>
> >> @monthlypayment = @principal*@rate/(1-Math.pow(1/(1+@rate),@payments))
> >>
> >> Ive searched everywhere and cant seem to find anything.
> >>
> >> thanks
> >>
> >> Johnny B
> >
> > I think this is what you're looking for:
> >
> > irb(main):001:0> 2 ** 1
> > => 2
> > irb(main):002:0> 2 ** 2
> > => 4
> > irb(main):003:0> 2 ** 3
> > => 8
> > irb(main):004:0> 2 ** 4
> > => 16
>
> Yes this is what i am looking for. How do i then use it to calculate
> amonthly payment, i have tried quite a few things but cant get the
> syntax right: @monthlypayment =
> @principal*@rate/(1-**(1/(1+@rate),@payments))
>
>
> So for the example below:
>
> Suppose you finance your car with a loan of $12000 at a yearly interest
> rate of 11% for four years, and make equal payments monthly. How much
> will your payments have to be? Here the parameters are principal P =
> $12000, interest rate i = 0.11, number of years n = 4, and number of
> periods per year q = 12. Then the monthly car payment M is given by
>
> M = Pi/[q(1-[1+(i/q)]-nq)],
> = ($12000)(0.11)/[(12)(1-[1+(0.11/12)]-(4)(12))],
> = $110/(1-1.009166666...-48),
> = $310.15.
>
>
> Anyone done this before?


** is an operator, just like + or *; it's used this way: base**exponent. In
your case, you should write:
@principal*@rate/(1-1/(1+@rate)**@payments)

I hope this helps

Stefano

John Butler

3/30/2007 12:54:00 PM

0

Yes, thanks.

--
Posted via http://www.ruby-....