I know this is a rookie question but its been years since I've used MatLab. I need to use p_r,p_p,p_s to calculate p_rn,p_pn,p_sn and then use those values in place of p_r,p_p,p_s in subsequent calculations and then store them all in a matrix.
    8 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I believe I should be using a for loop with the definition of the matrix inside but the details have escaped me. Any help with this would be greatly appreciated. I would like to end up with something like this: A 101x3 matrix
    [p_r,  p_p,  p_s;
     p_rn1,  p_pn1,  p_sn1;
     p_rn2,  p_pn2,  p_sn2;
    ...;
    p_rn100,  p_pn100,  p_sn100]
___________________________________________________________________________________
    p_r = 0.35;
    p_p = 0.33;
    p_s = 0.32;
    T_0 = 0.39;
    T_1 = 0.23;
    T_2 = 0.38;
    W_0 = 0.50;
    W_1 = 0.29;
    W_2 = 0.21;
    L_0 = 0.35;
    L_1 = 0.38;
    L_2 = 0.27;
    p_rn = (((p_r)^2)*(T_0)) + (((p_p)^2)*(T_1)) + (((p_s)^2)*(T_2)) + ((p_r)*(p_p)*((L_0)+(W_1))) + ((p_r)*(p_s)*((L_2)+(W_0))) + ((p_p)*(p_s)*((L_1)+(W_2)));
    p_pn = (((p_r)^2)*(T_2)) + (((p_p)^2)*(T_0)) + (((p_s)^2)*(T_1)) + ((p_r)*(p_p)*((L_2)+(W_0))) + ((p_r)*(p_s)*((L_1)+(W_2))) + ((p_p)*(p_s)*((L_0)+(W_1)));
    p_sn = (((p_r)^2)*(T_1)) + (((p_p)^2)*(T_2)) + (((p_s)^2)*(T_0)) + ((p_r)*(p_p)*((L_1)+(W_2))) + ((p_r)*(p_s)*((L_0)+(W_1))) + ((p_p)*(p_s)*((L_2)+(W_0)));
2 Kommentare
Antworten (1)
  per isakson
      
      
 am 17 Apr. 2015
        
      Bearbeitet: per isakson
      
      
 am 17 Apr. 2015
  
      The comment caused me to deleted my first answer.
Caveat: I know next to nothing about Game Theory
Assumption: The expressions in the question define how the probabilities, P(n), are calculated based on their previous values, P(n-1). If so, no recursion is needed.
Try
    >> P = cssm( 1/3+randn(1,3)/200 ); P(1:5,:)
    ans =
        0.3337    0.3273    0.3278
        0.3263    0.3261    0.3252
        0.3186    0.3187    0.3185
        0.3045    0.3045    0.3045
        0.2781    0.2781    0.2781
    >> plot( P )
    >> P = cssm( 1/3+randn(1,3)/200 ); P(1:5,:)
    ans =
        0.3333    0.3410    0.3295
        0.3349    0.3367    0.3359
        0.3383    0.3384    0.3385
        0.3435    0.3435    0.3436
        0.3541    0.3541    0.3541
where
   function    P = cssm(P0)
        P = nan( 101, 3 );  % allocate memory
        p_r = 0.35; p_p = 0.33; p_s = 0.32;
        T_0 = 0.39; T_1 = 0.23; T_2 = 0.38;
        W_0 = 0.50; W_1 = 0.29; W_2 = 0.21;
        L_0 = 0.35; L_1 = 0.38; L_2 = 0.27;
        if nargin == 0
            P(1,:)  = [ p_r, p_p, p_s ];
        else
            P(1,:)  = P0;
        end
        for n = 2 : size( P, 1 )
            P(n,1)  = ((P(n-1,1))^2)*(T_0)                  ... 
                    + ((P(n-1,2))^2)*(T_1)                  ...     
                    + ((P(n-1,3))^2)*(T_2)                  ...
                    + ((P(n-1,1))*(P(n-1,2))*((L_0)+(W_1))) ...
                    + ((P(n-1,1))*(P(n-1,3))*((L_2)+(W_0))) ...
                    + ((P(n-1,2))*(P(n-1,3))*((L_1)+(W_2))) ;
            P(n,2)  = ((P(n-1,1))^2)*(T_2)                  ... 
                    + ((P(n-1,2))^2)*(T_0)                  ...
                    + ((P(n-1,3))^2)*(T_1)                  ...
                    + ((P(n-1,1))*(P(n-1,2))*((L_2)+(W_0))) ...
                    + ((P(n-1,1))*(P(n-1,3))*((L_1)+(W_2))) ...
                    + ((P(n-1,2))*(P(n-1,3))*((L_0)+(W_1))) ;
            P(n,3)  = ((P(n-1,1))^2)*(T_1)                  ...      
                    + ((P(n-1,2))^2)*(T_2)                  ...
                    + ((P(n-1,3))^2)*(T_0)                  ...
                    + ((P(n-1,1))*(P(n-1,2))*((L_1)+(W_2))) ...
                    + ((P(n-1,1))*(P(n-1,3))*((L_0)+(W_1))) ...
                    + ((P(n-1,2))*(P(n-1,3))*((L_2)+(W_0))) ;
        end
    end
Siehe auch
Kategorien
				Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

