For looping problem: storing all answer in array
显示 更早的评论
Hi, can anyone help me with the output value in looping. I try to run the code but the answer just shows the answer from final iteration only (when Lm=90). How can I put all answer in an array like when Lm(0,30,60,90), so I have 4 last answers. Thank you.
function[qopt,ASr,ASs,AS]= loopingtry(alpha,Av,Std,n)
p=15;v=2;w=10;Lc=30/365;Lv=30/365;dx=0.01;c=4;
gammac=alpha*exp(alpha*Lc)*(1/(1-exp(-alpha/n)));
gammav=alpha*exp(-alpha*(Lv+(1/n)))*(1/(1-exp(-alpha/n)));
for Lm=0:30:90
Lz=Lm/365;
gammaz=alpha*exp(-alpha*Lz)*(1/(1-exp(-alpha/n)));
Proba=(n*p-w*gammaz)/(n*p-v*gammav);
qopt=ceil(Av+norminv(Proba)*Std);
I1=0;I2=0;
for y=0:dx:qopt-dx
fx=pdf('Normal',y,Av,Std);
fxplus=pdf('Normal',y+dx,Av,Std);
I1=I1+0.5*(y*fx +(y + dx)*fxplus)*dx;
I2 = I2+0.5*(fx + fxplus)*dx;
end
loss = (Av - qopt + (qopt * I2) - I1);
ASr= n*p * (Av - loss) + v * (qopt - Av + loss) * gammav- w*qopt*gammaz;
ASs=w * qopt * gammaz - c * qopt * gammac;
AS=ASr+ASs;
end
end
[qopt,ASr,ASs,AS]= loopingtry(0.2,1000,800,1)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!