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.

5 views (last 30 days)
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)));

Answers (1)

per isakson
per isakson on 17 Apr 2015
Edited: per isakson on 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
  1 Comment
Jarrett White
Jarrett White on 17 Apr 2015
Thanks per isakson! What these p_r, p_p, and p_s represent are starting probabilities for strategies in a symmetric zero sum game. I am doing an doing an analysis on conditional responses and the cyclic flow of strategies in discrete time. The p_rn, p_pn, and p_sn, where n=time from 0 to 100, represent the new probabilities of using strategies after each round. So I would like to use p_r to find p_r1, p_r1 to find p_r2, and so on. I guess its a sort of recursive function. Then I need to store these values to construct a plot of their behavior. I'm just not entirely sure of what the correct syntax would be to represent the recursive nature in the loop. I feel like the answer lies in the construction of my definition of p_rn, p_pn, and p_sn.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!