# Help on evaluating functions.

• March 6th, 2010, 02:52 AM
Help on evaluating functions.
Good day everyone.

I have this problem involving a function evaluation.

Let's say F is a mathematical function of multiple variables, and each variable has a discrete number of values.

For example: F(a,b,c)=(a+b)/c

and a={1,2,3) b={3,5,6) and c={8,9,7}

so F(1,3,8)=(1+3)/8=0.5

In my problem, F is a function of 7 variables. and each variable has a specific number of allowed values, how will I be able to solve all the possible F values? this could be easily done manually for a small number of combinations, but how about for large numbers of possible combinations.

thank you very much!
• March 6th, 2010, 02:19 PM
Amleto
Re: Help on evaluating functions.
put all the allowable values per variable into a vector or list, then iterate over all of them. e.g:

(untested)
Code:

```#include <iostream> #include <vector> using namespace std; float func(float a, float b, float c) {   return (a + b) / c; } int main() {   vector<float> theAs;   vector<float> theBs;   vector<float> theCs;   theAs.push_back(1);   theAs.push_back(2);   theAs.push_back(3);   theBs.push_back(3);   theBs.push_back(5);   theBs.push_back(6);   theCs.push_back(7);   theCs.push_back(8);   theCs.push_back(9);   vector<float>::iterator itA = theAs.begin();   vector<float>::iterator itB = theBs.begin();   vector<float>::iterator itC = theCs.begin();   for(; itA != theAs.end(); ++itA)   {     for(; itB != theBs.end(); ++itB)     {       for(; itC != theCs.end(); ++itC)       {         cout << func(*itA, *itB, *itC) << endl;       }     }   } }```