For looping problem: storing all answer in array
Show older comments
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)
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!