How do I create a Markov Matrix with variables instead of numbers for probabilities?

조회 수: 1 (최근 30일)
How do I create a Markov Matrix with variables instead of numbers where the probabilities should go?

채택된 답변

Dana
Dana 2020년 9월 4일
If your goal is to manipulate P symbolically (i.e., algebraically, rather than numerically), then you'll need to use Matlab's symbolic toolbox if you have it. In that case,
P = sym('p',[4,4]);
creates a symbolic matrix P with element (i,j) denoted by pi_j.
  댓글 수: 2
Khushi Patel
Khushi Patel 2020년 9월 4일
Thank you so much!
Just wondering, is there any way to sub in values for p1_1, p11_2....pi_j into the matrix?
Dana
Dana 2020년 9월 4일
Use the subs function. To do one element at a time, subs(P,'p1_1',1) would replace p1_1 (which is the (1,1) element of P) with the number 1. To replace the whole matrix in one go with the elements of another matrix:
m = magic(4); % an arbitrary 4-by-4 numeric matrix
Psub = subs(P,P,m);
Note that the output of the subs function is still a symbolic matrix, even if it contains only numbers. To convert a symbolic matrix (or other symbolic variable) to a numeric one, use eval:
Psubnum = eval(Psub);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by