Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I'm so glad I found this site... Now I can get some sleep, because my problem is solved..."

Geography

Where in the world do Tek-Tips members come from?
Lookingforhelponline (TechnicalUser)
29 Jun 12 13:15
Hello again. I made it back after writing a new code by myself, but I need help once again in executing a function. Pretty much I am trying to do something along the lines of:

CODE

D=x+y+z

DO x=1,20,5
DO y=1,20,5
DO z=1,20,5
ENDDO
ENDDO
ENDDO

MIN(Dall) [if Dall would be all of the values of D calculated] 

Where all possible combinations of x,y,z are used from the ranges I provided and all possible values of D are calculated, so that I can have the smallest value as my output from that range of data. My issue is I don't know how to make that happen or actually break the code down further into something else entirely to get the same result.

Thanks in advance for your time and consideration.
melmacianalf (TechnicalUser)
30 Jun 12 4:22

CODE --> F90

program min_xyz                                                                           
                                                                                          
  implicit none                                                                           
                                                                                          
  integer,parameter :: N = 1000                                                           
  integer           :: x, y, z, cnt, D, Dall(1:N)                                         
                                                                                          
  cnt = 0                                                                                 
                                                                                          
  do x = 1, 20, 5                                                                         
  do y = 1, 20, 5                                                                         
  do z = 1, 20, 5                                                                         
                                                                                          
    cnt = cnt + 1                                                                         
                                                                                          
    D = x + y + z                                                                         
    Dall(cnt) = D                                                                         
                                                                                          
  enddo                                                                                   
  enddo                                                                                   
  enddo                                                                                   
                                                                                          
  print *, minval(Dall(1:cnt))                                                                                                                                          
                                                                                          
end program min_xyz 

Gordon Shumway

gummibaer (Programmer)
30 Jun 12 9:51
Or, a little less heavy on memory, if you just need the minimum value of D and not the complete matrix:

CODE

function min (x, y, z)
    implicit none
    integer :: x, y, z, DMin

    DMin = 2000000000    ! just a very big number 
    do x = 1, 20, 5
    do y = 1, 20, 5
    do z = 1, 20, 5
        DMin = min (DMin, x + y + z) 
    enddo
    enddo
    enddo

    Print *, DMin
end function 

Quote:


Where all possible combinations of x,y,z are used ... and all possible values of D are calculated

... but you do not do this when you select an increment of 5 in the loops (??)

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.

ArkM (IS/IT--Management)
30 Jun 12 12:33
What's a funny problem!
The answer is 3.
No need to twist these strange loops ;)

Incidentally, there are only 64 elements in Dall array and max value of x+y+z is equal to 48...
gummibaer (Programmer)
30 Jun 12 13:34
Yes of course. I thought that this simple formula was just a placeholder for a more difficult thing.

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close