For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2007 > two cents









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author two cents
Wade Ward

2007-04-15, 10:03 pm

I was looking at funny images at alt.binaries.humor.skewed, and found this
image of a cancelled check from what appears to be a disgruntled customer
with a background in engineering. Shown here:
http://www.billfordx.net/2007-04-15c.htm

My friend Sue was visiting and saw the image and asked what the total was.
I had forgotten what the infinite series totalled to, so I wrote this little
prog:
program sue1
implicit none
integer :: counter, i
real :: total, term
counter = 20
total = 0.0
do i = 1, counter
term = 1/ 2.0**i
total = total + term
write (6,'(f6.4, a ,f6.4)') total," " ,term
end do
end program sue1
I think the engineer made a mistake. e to the i pi is negative one, and the
series obviously adds to one, cancelling each other out. That leaves .002,
which I think, he wanted to be $.02 , like Randy Howard's sig.

One question, how does one get complex exponententiation, say,
exp( a +bi)
, where a and b are real or
exp(z)
, with z complex?
--
WW


John Harper

2007-04-16, 4:07 am

In article < psWdna9lCadGSr_bnZ2dnUVZ_oavnZ2d@comcast
.com>,
Wade Ward <invalid@invalid.net> wrote:
>
>One question, how does one get complex exponententiation, say,
>exp( a +bi)
>, where a and b are real or
>exp(z)
>, with z complex?


exp(cmplx(a,b)) gives a single precision answer in f77 or f95

exp(cmplx(a,b,kind(1d0)) gives a double precision answer in f95;
a and b may be single or double precision but the exp won't have
double-precision accuracy unless they are double precision.

exp(z) in f77 or f95, but complex double precision wasn't standard
Fortran in f77. If you want it, z must be declared as such, e.g.
complex(kind(1d0)) z

Forgive me if the following is obvious to you, but if z is large,
you should expect an answer exp(z*(1+e) = exp(z)*exp(z*e) where e
is of order epsilon(z) in f95 terminology. So if z = 100, the error
may be 100 times bigger than you had allowed for :-(

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
glen herrmannsfeldt

2007-04-16, 4:07 am

Wade Ward wrote:
(snip)

> One question, how does one get complex exponententiation,
> say, exp( a +bi , where a and b are real or exp(z)
> with z complex?


Before generic intrinsic functions, it was CEXP. Now
it is just EXP(), or EXP(CMPLX(a,b)).
(With an optional KIND on the CMPLX.)

-- glen

Kevin G. Rhoads

2007-04-16, 10:04 pm

>Before generic intrinsic functions, it was CEXP.

Yup. And CDEXP for those that supported complex double stuff.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com