How can I calculate each entry for this 10x10 matrix?
3 views (last 30 days)
Show older comments
Hi all, I'm trying to create a very specific matrix (N = 10, but the idea is it would work for any N) but I don't know how to do it. Here is what I have so far:
%%% This program is going to calculate each entry in a given matrix.
N = input('please enter a whole number bigger than 1: ');
syms k; %%% must be initialized so we can use it in defining the two functions below.
R_p = ((N+10*k)/(N^2));
C_p = (((4*N^2)-(4*k^2))/(N^2));
k is a variable that ranges from 1 to N and R_p and C_p are two functions that will be generating each entry in the following way: (((R_p)(1 - C_p)) - ((C_p)(1-R_p))).
Specifically, R_p and C_p assign probabilities for any given (N,k) and each entry in the matrix G is generated by the expression underlined above.
What I don't know how to do is write the code that generates this matrix. I imagine it will be something involving a for loop or maybe a nested sequence of for loops but I'm a bit rusty on my Matlab skills.
I tried to only include the absolutely necessary details above, but if it helps, here is the context: Two duelists each have a gun that contains a single bullet and each gun is equipped with a silencer. They advance towards each other in N steps, and each may fire at his opponent at the end of each step. Neither knows whether his opponent has fired, and each has but one shot in the game. The probability that player R will hit his opponent, player C, after moving k steps is given by R_p, and the probability that Player C will hit player R after moving k steps is given by C_p. Player R gets +1 if he shoots and kills C before C shoots and kills R, -1 if player C shoots and kills R before R can shoot and kill C, and 0 otherwise. Each player has N strategies corresponding to firing after 1, 2, . . . , N steps. Let player R choose strategy i and let player C choose strategy j (i.e., R is a "row player" and C is a "column player").
The goal is to create what's known as a "payoff matrix" where each entry is the expected value of a given "strategy." The way to calculate each entry is given by the underlined expression just below the code. Thank you for all the help!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!