Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:52+00:00 2026-05-28T01:40:52+00:00

I have an array double x[] of length 11 and a function f(double x[])

  • 0

I have an array double x[] of length 11 and a function f(double x[]). I want to find the minimum of the function f() by discretization. So for given values val1, val2, ..., valn I need a loop trough all the tuples of x in {val_1, …, val_n}^11. I could easily use 11 nested loops, but is this really the most efficient I could do?

Edit:
To clarify things: the function f() is defined on an 11 dimensional set. I want to evaluate the function on the vertices of the an 11 dimensional grid. For a grid size h, possible values for the entries of the array x[] could be 0, h, 2*h, …, n*h = val_1, val_2, …,val_n . So in the beginning f(val_1, val_1, ..., val_1) should be evaluated, then f(val_1, val_1, ...,val_1, val_2), … and in the and f(val_n, val_n, ..., val_n). I don’t care about the order actually, but I do care about speed, because there are many such tuples. To be precise, there are n^11 such tuples. So for n=10 f() has to evaluated 10^11 times. My computer can evaluate f() approximately 5*10^6 times per second, so for n=10 the evaluation of f() takes 5 hours. That’s why I’m searching for the most efficient way to implement it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:40:53+00:00Added an answer on May 28, 2026 at 1:40 am

    Here is pseudocode (not necessarily syntactically-correct C code) for a non-recursive approach to iterate over all possible tuples:

    const int vals[]        = { val1, val2, val3, ... };
    
    int       x[NUM_DIMS]   = { vals[0], vals[0], ... };  // The current tuple
    int       i[NUM_DIMS]   = { 0 };                      // Index of each element in x[]
    
    
    while (1)
    {
        f(x);  // Whatever
    
        // Update x (we increment i[] treated as a base-N number)
        int j;
        for (j = 0; j < NUM_DIMS; j++)
        {
            i[j]++;                          // Increment the current digit
            x[j] = vals[i[j]];               // Update (via mapping)
            if (i[j] < NUM_VALS) { break; }  // Has this digit wrapped?
            // We've caused a carry to the next digit position
            i[j] = 0;                        // Wrap
            x[j] = vals[0];                  // Update (via mapping)
        }
        if (j == NUM_DIMS) { break; }  // All digits wrapped, therefore game over
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of double values vals, I need to randomly index into
In my program I have one array with 25 double values 0.04 When I
Let's say I have an array of lots of values (C++ syntax, sorry): vector<double>
Suppose I have an array of class values in Java and I want to
I have a function in C++ written as: MyFunc(const double* pArray, int length); I
I have two arrays values and keys both of the same length. I want
I have a double[][] array, and I want to get one row into a
I have an array of double pointers, but every time I try do print
I have an double array alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print
I have an array of a few million numbers. double* const data = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.