第一个函数:
func
tion f=shapley(v,n)
x=zeros(1,n);f=x;e=ones(1,n);s=0;t=s;
while 1
k=1;
while x(k)==1
p=feval(v,x);
if s==1 w=1;
else
if s>t w=w*t/(n-t);
elseif s<t
w=w*(n-s)/s;
end
end
f=f+w*x*p;
if s<n f=f-w*s/(n-s)*(e-x)*p; end
t=s;
x(k)=0;s=t-1;
if k==n f=f/n;return; end
k=k+1;
end
x(k)=1;s=t+1;
end
第二个函数:
function v=eigen(x)s=sum(x);if s==0 v=0;return;endif s==1 v=1;return;endif x=[1,1,0] v=7;return;endif x=[1,0,1] v=5;return;endif x=[0,1,1] v=4;return;endif s==3 v=10;end
运行结果F=shapley(@eigen1,3)??? Error: File: d:
matlab7workeigen1.m Line: 5 Column: 5The expression to the left of the equals sign is not a valid target for an assignment.
Error in ==> shapley at 6 p=feval(v,x);
-
-
-
x==[1,1,0]
一周热门 更多>