We help IT Professionals succeed at work.

calculate all possible path from a matrix

rmtogether
rmtogether asked
on
Medium Priority
599 Views
Last Modified: 2010-04-15
hi,


 | a     |   b     |     c     |
---------------------------------|
a| 0.5  | 0.25   | 0.25    | =1
---------------------------------|    
b| 0.375| 0.125 | 0.375  | =1
---------------------------------|
c| 0.125| 0.675 | 0.375  | =1
-----------------------------------


I need calculate the probability from a above matrix

for example, if I want to find a sequence of aab, it should calculate like:
a-->a-->b = 0.5 * 0.25 = 0.125

could someone give me some codes to find "all possible paths" for any given sequence? for example for sequence of 3, there is 3^3=27 possible paths (aaa,aab,aac, aba....ccc.etc). I want to find the probability of all 27 paths.


Comment
Watch Question

Data Warehouse / Database Architect
CERTIFIED EXPERT
Commented:

You simply need to next for() loops, one for each level.

for (i1 = 0; i1 < 3; ++i1)
  for (i2 = 0; i2 < 3; ++i2)
    for (i3 = 0; i3 < 3; ++i3)
      fprintf (stdout, "%c%c%c\n", 'a'+i1, 'a'+i2, 'a'+i3);



Good Luck,
Kent

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Kent OlsenData Warehouse / Database Architect
CERTIFIED EXPERT

Commented:

NEST for() loops.


That'll teach me to submit without reading......

sigh....

Author

Commented:
hi,

this is something I did so far, I would like modify the my code to find the maximun value of 27 outputs. could someone teach me how to do it?

-----------------------------
#include <stdio.h>


float matrix [3][3]={{0.5,0.25,0.25},
                     {0.375,0.125,0.375},
                     {0.125,0.675,0.375}};

main (){
    int i,j,k;
   
    // printf("the matrix is ");

     for (i=0; i<3; i++){
          printf("\n");
         for (j=0; j<3; j++) {
          //printf("%.3f\t", matrix[i][j]);  
             printf("\n");
            for (k=0; k<3; k++){
              printf("Prob(%d%d%d)=%.5f\n",i,j,k,matrix[i][j]*matrix[j][k]);   ----------------> find the maximun value
           
            }//end third for
                       
        }// end second for
    }// end first for


    system("pause");
}

Author

Commented:
hi, Kdo

Since I got your help already.I will close this question. and ask another one. thanks a lot

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_22043176.html
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.