how to code probability in general??

조회 수: 2 (최근 30일)
Edgaris Rhomer
Edgaris Rhomer 2013년 4월 15일
Suppose I have a matrix A=magic(2).
1) Each entry mutates with probability p. 2) If such mutation does occur, then with probability (1-q) a random integer between 1 and 2^2 is selected as the new value and replaces the old value.
How would I code this? I've been thinking about this for a while but I cannot come up with anything! Like, I would love to provide at least what I have so far but I haven't gotten a single clue.
Can this be coded even? At this stage it feels like it cannot be.. Thanks a lot in advance, any help is very much appreciated.
  댓글 수: 3
Edgaris Rhomer
Edgaris Rhomer 2013년 4월 15일
편집: Edgaris Rhomer 2013년 4월 15일
Thanks for the link. I put them there now.
I'm sorry I forgot to mention this. with probability q, it's taken that of a randomly selected number from lattice neighbours.

댓글을 달려면 로그인하십시오.

채택된 답변

Ahmed A. Selman
Ahmed A. Selman 2013년 4월 15일
First what is magic(2)? I thought the smallest magic matrix comes (3-by-3) since Magic (2) doesn't satisfy the condition (sum each row=sum each column=sum each diagonal=const.). But I think you meant any matrix with possible permutation, anyway.
For a magic matrix, when you could replace such an element by an integer, selected between 1 and n^2 (n being the size of magic(n) ), it will probably be the same value in order to keep the properties of the original matrix the same.
If this condition is to be ignored in the resulting matrix, then try to initiate a (flag matrix) which is the same size as the original matrix but with all elements zeros. It works as:
- During a simple read loop, when the permutation occurs, flag stores the first permuted elements as (1,1) the second as (2,2).. etc.
- In a second loop, select or generate random integers as required, and replace the flagged elements with them.
- In a third loop, replace the remaining zeros of the flag matrix with elements from the original matrix. The flag matrix will be the required one (tho it will absolutely posses different properties than the original one).
  댓글 수: 2
Edgaris Rhomer
Edgaris Rhomer 2013년 4월 15일
magic(2) gives me a 2x2 matrix just fine. ?
yes you're right. in fact for my project I have a 1000x1000 matrix instead with 3-digit integers as entries. I see your point, but I have some questions.
1) "when the permutation occurs" how would I code this, really? I want to know how to code that with some probability something happens.
Actually, I'll try this out first then ask more about the flag matrix approach. Thanks a lot!
Edgaris Rhomer
Edgaris Rhomer 2013년 4월 18일
I did it using rand() instead but I will accept the answer regardless.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by