如何在matlab中編寫遞歸函數,它基本上是一個馬爾可夫鏈! 我試圖寫它和僞代碼新MATLAB:matlab中的遞歸函數
的功能發生是這樣的:
P= Probability
x= status(0,1)
Dij= probability to pick a site
P(Status of Site(i) being x at next time step)= Summation[P(Status of Site(i) being x at previous time step)*Dij]
我已經試過代碼,任何人都可以電話我是否其右:
function [t,index]= CopyingInfluenceModel
%%Define constants
StatusP1=rand(1,0);
StatusP0=rand(1,0);
% Initializing the variables
t=[];
index=[];
i=[];
%assigining the initial conditions
t(1)=0;
%set index no i to 1(initial condition for i=1)
i=1;
%% If the probability is zero, terminate while loop
while p(i)>=0
%calculate time step for given index no
t(i+1)= t(i);
%calculate the status_probability at given time t=(i+1)
StatusP1(i+1)=StatusP1(i)+sum(StatusP1(i)*Dij);
%index i increases by 1 to calculate next probability
i=i+1;
end
end
如果我可能如此大膽(也可能不正確),在我看來,這將更順利地完成沒有遞歸,因爲在生成斐波那契序列的線性解決方案(這是你似乎試圖做的) –
不是斐波那契! – happyme