Rekursive Funktion in matlab

Wie Schreibe ich eine rekursive Funktion in matlab, die es im Grunde als eine Markov-Kette!
Ich habe versucht, schreiben Sie einen pseudo-code für it und neue zu MATLAB:

Die Funktion geht so:

   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]

Habe ich versucht-code, kann jemand tel mir, ob Ihr Recht:

 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
Wenn ich so direkt sein darf (und wahrscheinlich falsch), es scheint mir, dass dies würde mehr sauber gemacht ohne Rekursion wie in der linearen Lösung für die Generierung der fibonacci-Folge (das ist, was Sie zu sein scheinen, versuchen zu tun)
nicht ein fibonnacci!!

InformationsquelleAutor happyme | 2012-11-09

Schreibe einen Kommentar