ChaChing 发表于 2013-5-6 14:54
Ref:
2.常见的程序出错问题整理 http://www.chinavib.com/thread-46001-1-1.html
7F->Function def ...
老师好,解决一个问题,又一个问题了:
df=0.1;xf=0.2;w=5;p=8;v=1;c=1.5;%缺货惩罚因子,成本弥补因子,收购价格,残值,单位成本%
syms x y g
for j=1:1:10;
eta(j)=j*0.1;%风险系数%
A(j)=0;
i=0.2;%积分上限%
l(j)=norminv(eta(j)*(normcdf(1,0.8,0.2)-normcdf(0,0.8,0.2))+normcdf(0,0.8,0.2),0.8,0.2);
fun=inline('x.*normpdf(x,0.8,0.2)/(normcdf(1,0.8,0.2)-normcdf(0,0.8,0.2))','x');
fun1=inline('normpdf(x,0.8,0.2)/(normcdf(1,0.8,0.2)-normcdf(0,0.8,0.2))','x');
m(j)=quadl(fun,0,l(j));
m(j)=double(m(j));
t(j)=quadl(fun,0,i)-(eta(j)*c-m(j))/((1+df-xf)*w);
while t(j)<A(j)
i=i+0.0001;
t(j)=quadl(fun,0,i)-(eta(j)*c-m(j))/((1+df-xf)*w);
end
I(j)=i-0.0001;
derta(j)=-w.*(1-xf).*I(j)-xf.*w.*quadl(fun,0,1)-eta(j)*c+xf.*w.*m(j)+(1+df-xf).*w.*I(j)*quadl(fun1,0,I(j));
%***x的pdf:normpdf(x,0.8,0.2)/(normcdf(1,0.8,0.2)-normcdf(0,0.8,0.2))***********y的密度函数:normpdf(y,5,2)/(normcdf(10,5,2)-normcdf(0,10,2))*******反应系数,收购成本*********%
Q=0.5;
fun2=inline('x.*normpdf(x,0.8,0.2)/(normcdf(1,0.8,0.2)-normcdf(0,0.8,0.2)).*normpdf(y,5,2)/(normcdf(10,5,2)-normcdf(0,10,2))','x','y');
yupper=inline('x.*Q','x');
t2(j)=quad2dgg(fun2,0,yupper,0,Q./10)+quadl(fun,Q./10,1)-(p*quadl(fun,0,1)+derta(j))/(p-v);
while t2(j)<0
Q=Q+0.001;
t2(j)=quad2dgg(fun2,0,yupper,0,Q./10)+quadl(fun,Q./10,1)-(p*quadl(fun,0,1)+derta(j))/(p-v);
end
Qr(j)=Q-0.001;
end
这个是程序,运行出来的结果。
??? Error using ==> inlineeval
Error in inline expression ==> x.*Q
??? Error using ==> eval
Undefined function or variable 'Q'.
Error in ==> inline.feval at 34
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in ==> gquad2dg at 54
xhigh=feval(limxhigh,y);
Error in ==> quad2dgg at 39
int_old=gquad2dg(fun,xlow,xhigh,ylow,yhigh,2,2,varargin{:}); |