For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2005 > multiplication by imaginary component









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 multiplication by imaginary component
treblataf79@freenet.de

2005-04-06, 12:21 pm

Hello,

I am translating a Matlab function into Fortran which computes
orthogonal polynomials. Does anyone know what syntax I should use in
Fortran95 for the following snippet from my Matlab function
kmax = 8
i=sqrt(-1);
for k=0:kmax,
P(:,k+1)=R(:,k+1)*i^k;
end

It computes the complex matrix "P" by multiplying real matrix "R" by
i^k.

Many thanks

Albert

Steven G. Kargl

2005-04-06, 12:21 pm

In article <1112455197.963494.77600@g14g2000cwa.googlegroups.com>,
treblataf79@freenet.de writes:
> Hello,
>
> I am translating a Matlab function into Fortran which computes
> orthogonal polynomials. Does anyone know what syntax I should use in
> Fortran95 for the following snippet from my Matlab function
> kmax = 8
> i=sqrt(-1);
> for k=0:kmax,
> P(:,k+1)=R(:,k+1)*i^k;
> end
>


integer k, kmax
complex i1
kmax = 8
i = cmplx(0.e0,1.e0)
do k = 0, kmax
p(:,k+1) = r(:,k+1) * i**k
end do

--
Steve
http://troutmask.apl.washington.edu/~kargl/
glen herrmannsfeldt

2005-04-06, 12:21 pm

Steven G. Kargl wrote:

> In article <1112455197.963494.77600@g14g2000cwa.googlegroups.com>,
> treblataf79@freenet.de writes:


[color=darkred]
> integer k, kmax
> complex i1
> kmax = 8
> i = cmplx(0.e0,1.e0)
> do k = 0, kmax
> p(:,k+1) = r(:,k+1) * i**k
> end do


I have no idea if any optimizing compilers figure this one out.
All it really does is move around and/or change the sign the real and
imaginary parts.

If I wanted to be sure it was fast, I might do it with a CASE
statement on MOD(K,4), and CMPLX, REAL, and AIMAG to do the
move.

Or the loop can be unrolled with four assignments in it,
and then special case for the last three.

-- glen

Steven G. Kargl

2005-04-06, 12:21 pm

In article <W9OdnQkkVql-eNPfRVn-2A@comcast.com>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:
> Steven G. Kargl wrote:
>
> I have no idea if any optimizing compilers figure this one out.
> All it really does is move around and/or change the sign the real and
> imaginary parts.
>
> If I wanted to be sure it was fast, I might do it with a CASE
> statement on MOD(K,4), and CMPLX, REAL, and AIMAG to do the
> move.
>
> Or the loop can be unrolled with four assignments in it,
> and then special case for the last three.


Sure, there's a number of ways to achieve the result.
I just gave the OP the obvious translation.


--
Steve
http://troutmask.apl.washington.edu/~kargl/
treblataf79@freenet.de

2005-04-06, 12:21 pm

Thanks a lot for the quick responses Steve G Kargl
and Glen Herrmannsfeldt, Thats works great.

Best regards

Albert

Sponsored Links







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

Copyright 2009 codecomments.com