help with the pow() function 
Author Message
 help with the pow() function

I am trying to use the pow() function but don;t have any information
on how to use it with other functions, for example, I am trying to use
it in a formula as below:

This is a formula for present value:

present value=future value divided by (1+interest per year divided by
number of compounding periods)^nk

I am using this in c to do the same thing:

P=F/(1+i/k)*pow(n,k)

I can't get the formula above to calculate correctly. Am I doing
something wrong here? I have to use the pow() for the n*k exponents.

I would greatly appreciate any help, Thanks
Ryan



Thu, 15 Jul 1999 03:00:00 GMT  
 help with the pow() function

Quote:

> I am trying to use the pow() function but don;t have any information
> on how to use it with other functions, for example, I am trying to use
> it in a formula as below:

> This is a formula for present value:

> present value=future value divided by (1+interest per year divided by
> number of compounding periods)^nk

I think this will work, but I haven't tested it.

/*  pv.c Calculates present value according to the formula

        pv = futureSum / (1 + rrate / 12)**(12 * termy)
   where:
        pv = present value in dollars
        FutureSum = dollar value you want in termy years
        termy = term, in years
        rrate = annual rate of return you can expece, decimal

   this sample sets
         futureSum = 40000.00
         termy = 12.0
         rrate = .1     */

#include <stdio.h>
#include <math.h>

int main()
  {
  double pv,futureSum,termy,rrate;

  futureSum = 40000.0;
  termy = 12.0;
  rrate = .1;  /* 10% */

  pv = futureSum/pow(1+rrate/12,12 * termy);
  printf("futureSum = $%.2f\n",futureSum);
  printf("termy = %.1fyears\n",termy);
  printf("rrate = %.1f\n\n",rrate);
  printf("present value = %.2f\n",pv);
  return 0;
  }
--
Al Bowers
Tampa, FL

http:www.gate.net/~abowers/index.html



Thu, 15 Jul 1999 03:00:00 GMT  
 help with the pow() function

Quote:

> I am trying to use the pow() function but don;t have any information
> on how to use it with other functions, for example, I am trying to use
> it in a formula as below:

> This is a formula for present value:

> present value=future value divided by (1+interest per year divided by
> number of compounding periods)^nk

> I am using this in c to do the same thing:

> P=F/(1+i/k)*pow(n,k)

> I can't get the formula above to calculate correctly. Am I doing
> something wrong here? I have to use the pow() for the n*k exponents.

> I would greatly appreciate any help, Thanks
> Ryan

Ryan,

1) Make sure that you have #include'd the <math.h> header file.
2) 'pow' takes two 'double's as arguments, and returns a 'double'.

Yours,

Geoff Houck
systems hk

http://www.teleport.com/~hksys



Fri, 16 Jul 1999 03:00:00 GMT  
 help with the pow() function

Quote:


>> I am trying to use the pow() function but don;t have any information
>> on how to use it with other functions, for example, I am trying to use
>> it in a formula as below:

>> This is a formula for present value:

>> present value=future value divided by (1+interest per year divided by
>> number of compounding periods)^nk

>> I am using this in c to do the same thing:

>> P=F/(1+i/k)*pow(n,k)

This is (F / (1 + i/k))*n^k, but you want

   pow(F / (1 - i/k), n * k);

Quote:

>> I can't get the formula above to calculate correctly. Am I doing
>> something wrong here? I have to use the pow() for the n*k exponents.

>1) Make sure that you have #include'd the <math.h> header file.

Good advice

Quote:
>2) 'pow' takes two 'double's as arguments, and returns a 'double'.

With a prototype for pow() in view, the  necessary promotions should
take place, shouldn't they?

A source of some suspicion is the type of "i". If "i" happens to
be an integer, the evaluation of the first argument of pow() will
happen in an undesirable way.

Kurt

--
| Kurt Watzka                             Phone : +49-89-2180-6254



Fri, 16 Jul 1999 03:00:00 GMT  
 help with the pow() function

Quote:

>I am trying to use the pow() function but don;t have any information
>on how to use it with other functions, for example, I am trying to use
>it in a formula as below:

>This is a formula for present value:

>present value=future value divided by (1+interest per year divided by
>number of compounding periods)^nk

>I am using this in c to do the same thing:

>P=F/(1+i/k)*pow(n,k)

From your statement above, you appear to want:

   P = F / pow( 1 + i/k, n * k );

Don't forget to include math.h.




Fri, 16 Jul 1999 03:00:00 GMT  
 help with the pow() function

Quote:



> >> I am trying to use the pow() function but don;t have any information
> >> on how to use it with other functions, for example, I am trying to use
> >> it in a formula as below:

> >> This is a formula for present value:

> >> present value=future value divided by (1+interest per year divided by
> >> number of compounding periods)^nk

> >> I am using this in c to do the same thing:

> >> P=F/(1+i/k)*pow(n,k)

> This is (F / (1 + i/k))*n^k, but you want

>    pow(F / (1 - i/k), n * k);

Please, the correct formula is:

        P = F/(pow(1-(i/k),(n*k))

double P is Present Value
double F is Future Value
float  i is the annual interest rate
int    k is the number of compounding periods per year
int    n is the number of years

Note: If the anual interest rate is 5%, i==0.05, not 5.0

(Note: I graduated with a 3.59{*filter*}in Accounting at U Mass and a 4.0{*filter*}
from the Military Accounting School at Fort Benjamin Harrison,
Indianapolis.  I sometime have nightmares about these formulas.  I will
never forgive you for reminding me about them.)

Quote:
> >> I can't get the formula above to calculate correctly. Am I doing
> >> something wrong here? I have to use the pow() for the n*k exponents.
> >1) Make sure that you have #include'd the <math.h> header file.
> Good advice

> >2) 'pow' takes two 'double's as arguments, and returns a 'double'.

> With a prototype for pow() in view, the  necessary promotions should
> take place, shouldn't they?

> A source of some suspicion is the type of "i". If "i" happens to
> be an integer, the evaluation of the first argument of pow() will
> happen in an undesirable way.

> Kurt

Alicia Carla Longstreet
Wealth is not without its advantages
and the case to the contrary,
although it has often been made,
has never proved widely persuasive.
                John Kenneth Galbraith
I just want the opportunity to prove the old adage...
"Money can't buy happieness."


Sat, 17 Jul 1999 03:00:00 GMT  
 help with the pow() function



Quote:



>> >> I am trying to use the pow() function but don;t have any information
>> >> on how to use it with other functions, for example, I am trying to use
>> >> it in a formula as below:

>> >> This is a formula for present value:

>> >> present value=future value divided by (1+interest per year divided by
>> >> number of compounding periods)^nk

>> >> I am using this in c to do the same thing:

>> >> P=F/(1+i/k)*pow(n,k)

>> This is (F / (1 + i/k))*n^k, but you want

>>    pow(F / (1 - i/k), n * k);

>Please, the correct formula is:

>    P = F/(pow(1-(i/k),(n*k))

Not quite.  Your parentheses don't balance, you should be adding, not
subtracting, and you need a semi-colon at the end:

   P = F / pow( 1 + i / k, n * k );



Sat, 17 Jul 1999 03:00:00 GMT  
 help with the pow() function



| (Note: I graduated with a 3.59{*filter*}in Accounting at U Mass and a 4.0{*filter*}
| from the Military Accounting School at Fort Benjamin Harrison,
| Indianapolis.

Oooohhhh, I love numbers -- mine is nine inches high and if you take it all
the
way, from one end to the other it ends up something like 2 inches thick;
it's
a real standard so to speak. I'm talking about my copy of the ISO/IEC 9899
Standard here of course; have you bought your own copy already?

It could come in handy if you want to participate in this group you know,
'cause then
you don't have to brag about irrelevant numbers anymore ...




Mon, 19 Jul 1999 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. POW Function...Please Help

2. POW FUNCTION....PLEASE HELP

3. POW Function...Please Help

4. computing powers without the pow() function.

5. POW FUNCTION

6. pow function

7. a pow function

8. the pow() function

9. Trying to use pow() function...

10. Implementation of pow(3m) function

11. Question regarding pow() function

12. The pow() function...

 

 
Powered by phpBB® Forum Software