我给出了一些PROB值,x = 5。当x = 5,x = 4,...时,如何获得M的值并将其单独存储?我试过以下但是没有用。请帮忙。
function [ M,P ] = Recursion( PROB,lambda,x)
if x==1
M=exp(-lambda);
else if x>1
L=0;
for i=1:x-1
L=L+(i*PROB(:,i));
end
M=(lambda/(x-1))*L*Recursion(PROB,lambda,x-1);
P=[];
P=[P;M];
end
end
答案 0 :(得分:0)
尝试这样的代码。您还需要从函数的递归调用中获取P
。
function [ M,P ] = Recursion( PROB,lambda,x)
if x == 1
M = exp(-lambda);
P = M;
else
if x > 1
L = 0;
for i = 1:x-1
L = L+(i*PROB(:,i));
end
[M,P] = Recursion(PROB,lambda,x-1);
M = (lambda/(x-1))*L*M;
P = [P;M];
end
end