如何在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