[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


calculate all possible path from a matrix

Posted on 2006-10-30
Medium Priority
Last Modified: 2010-04-15

 | 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.

Question by:rmtogether
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 46

Accepted Solution

Kent Olsen earned 1500 total points
ID: 17837564

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,
LVL 46

Expert Comment

by:Kent Olsen
ID: 17837573

NEST for() loops.

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



Author Comment

ID: 17838378

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},

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

     for (i=0; i<3; i++){
         for (j=0; j<3; j++) {
          //printf("%.3f\t", matrix[i][j]);  
            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


Author Comment

ID: 17838431
hi, Kdo

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


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question