Home > Archive > Fortran > March 2007 > complex number & sort
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 |
complex number & sort
|
|
| nakisa 2007-03-19, 7:13 pm |
| hi everbody , i have 3 questions :
1) i know how complex number must be written in fortran . but now i
want to
calculate complex number in loop and use its value for other parts ,
my problem is
with complex number in loop . for example , i guess with this way i
can
work with complex numbers :
complex m
do i=1,10,1
m=(i,i)
end do
this program doesn't work .what can i do ?
2) i have an array with dimensioins A(3,200) . i want to sort these
array
with increasing the second row data algebrically . in fortran
libarary i can't
find suitable program , all program are for vectors .can anybody
propose me a way ?
3) in my program , numbers are calculated with 6 digits precesion
after point .( for example 21.938495 ) how
can i control the precesion ? i want it computes with 3 or 2 digits
after point .
best ,nakisa
| |
| Michael Metcalf 2007-03-19, 7:13 pm |
|
"nakisa" <nakisa.nooraee@gmail.com> wrote in message
news:1174311138.452082.35810@e65g2000hsc.googlegroups.com...
> hi everbody , i have 3 questions :
>
Does the following answer the first and third?
complex m
do i=1,10,1
m=cmplx(i,i)
end do
write(*, '(2f10.2)') m
end
Regards,
Mike Metcalf
| |
| meek@skyway.usask.ca 2007-03-19, 7:13 pm |
| In a previous article, "nakisa" <nakisa.nooraee@gmail.com> wrote:
>hi everbody , i have 3 questions :
>
>1) i know how complex number must be written in fortran . but now i
>want to
>calculate complex number in loop and use its value for other parts ,
>my problem is
>with complex number in loop . for example , i guess with this way i
>can
>work with complex numbers :
>
>complex m
>
>do i=1,10,1
> m=(i,i)
m= cmplx(float(i),float(i))
>end do
>
>this program doesn't work .what can i do ?
>
>2) i have an array with dimensioins A(3,200) . i want to sort these
>array
>with increasing the second row data algebrically . in fortran
>libarary i can't
>find suitable program , all program are for vectors .can anybody
>propose me a way ?
There are 3 columns per row - which column do you want to
use for ordering ?.
Chris
>
>3) in my program , numbers are calculated with 6 digits precesion
>after point .( for example 21.938495 ) how
>can i control the precesion ? i want it computes with 3 or 2 digits
>after point .
>
>best ,nakisa
>
One way is to multipl all by 1000 or 100 and use integer arith.
| |
| highegg 2007-03-19, 7:13 pm |
|
> 2) i have an array with dimensioins A(3,200) . i want to sort these
> array
> with increasing the second row data algebrically . in fortran
> libarary i can't
> find suitable program , all program are for vectors .can anybody
> propose me a way ?
You can use, for instance, this module:
http://artax.karlin.mff.cuni.cz/~ha...na/ordering.f90
to sort your array according to the second column (i.e. permute rows
in such a way that the second column is in increasing order), you can
simply do:
USE ordering
.....
A = A(:, order(A(2,:)) ) ! sort A by 2nd column
"order" is a function that computes an ordering permutation for an
integer/real array X, such that X(order(X)) is increasing sequence.
> 3) in my program , numbers are calculated with 6 digits precesion
> after point .( for example 21.938495 ) how
> can i control the precesion ? i want it computes with 3 or 2 digits
> after point .
Available kinds of real numbers depend on you hardware. What you
probably want is to display the results with only 2 or 3 digits. Check
out the WRITE statement and edit descriptors in your compiler's
manual.
| |
| nakisa 2007-03-19, 10:07 pm |
| hi and thanks alot
two of three problems are solved , only i can't use "ordering " for
sorting array !
nakisa
| |
| highegg 2007-03-20, 4:23 am |
| On Mar 20, 3:39 am, "nakisa" <nakisa.noor...@gmail.com> wrote:
> hi and thanks alot
> two of three problems are solved , only i can't use "ordering " for
> sorting array !
>
> nakisa
Why not?
| |
| highegg 2007-03-20, 4:23 am |
|
> USE ordering
> ....
> A = A(:, order(A(2,:)) ) ! sort A by 2nd column
>
of course, this is sorting by 2nd row. My apologies.
| |
| nakisa 2007-03-20, 4:23 am |
| i use the same notation that you wrote .but program doesn't run . can
you send a sample link ?
i search but i can't find useful link ( the pervious link in past
posts are not use this command !)
best,nakisa
| |
| highegg 2007-03-20, 4:23 am |
| On Mar 20, 8:55 am, "nakisa" <nakisa.noor...@gmail.com> wrote:
> i use the same notation that you wrote .but program doesn't run . can
> you send a sample link ?
> i search but i can't find useful link ( the pervious link in past
> posts are not use this command !)
> best,nakisa
An example program is included (commented out) at the end of the
module file.
What compiler are you using? Do you compile the module before using
it?
| |
| nakisa 2007-03-20, 4:23 am |
|
> An example program is included (commented out) at the end of the
> module file.
> What compiler are you using? Do you compile the module before using
> it?
i use comqap version 7 ,my program is not inclue module . it is very
strange for me , that i can't find this function in fortran libaray or
its help . !!! am i need to install something eles ???
| |
| highegg 2007-03-20, 7:09 pm |
|
> i use comqap version 7 ,my program is not inclue module .
IIRC (and IIGC, G for Google), the HP Compaq Visual Fortran ended up
with version 6.6 - do you mean Intel Visual Fortran 7 or something
else? The exact name of you product should be available in the Help/
About... menu.
Do you use Fortran 77 or Fortran 95? If you code in F77, that's fine,
but I suggest to at least learn using modules - many useful libraries
are provided through them. Consult your manual or some of the various
resources on the web.
> it is very
> strange for me , that i can't find this function in fortran libaray or
> its help . !!! am i need to install something eles ???
you probably misunderstood. The order function is not standard Fortran
intrinsic - so you can't find it in the standard library or your
manual. You have to include the above hyperlinked file, ordering.f90,
in your project in order to be able to use it.
There is no standard Fortran intrinsic functions to do sorting.
| |
| Kevin G. Rhoads 2007-03-20, 7:09 pm |
| Use appropriate intrinsic function:
complex m
do i=1,10,1
m = CMPLX(i,i)
end do
>i have an array with dimensioins A(3,200) . i want to sort these
>array with increasing the second row data algebrically . in fortran
>libarary i can't find suitable program
For such small values a bubble sort is OK, if array sizes are expected
to grow find a pre-coded HEAPSORT and use that. E.g., Numerical Recipes.
| |
| nakisa 2007-03-22, 4:06 am |
| thanks of your help
nakisa
|
|
|
|
|