I have an equation getting trouble while solving it. My equation:
S1=O*P*M1/Y1
D1=N-S1
S2=(O-D1)*P*M2/Y2
D2=N-S2
S3=(O-D1-D2)*P*M3/Y3
D3=N-S3
...
What I've done:
$S = array();
$M = array(30,31,30);
$Y = array(360,360,360);
$O = 30000;
$P = 0.3;
$N = 10509.74;
$D = array();
for($i=1; $i<=count($M); $i++){
if($i==1){
$S[1] = $O*$P*$M[1]/$Y[1];
$D[1] = $N - $S[1];
}
else{
for($k=2; $k<=count($M); $k++){
$S[$i] = ($O-$D[$k-1])*$P*$M[$k]/$Y[$k];
$D[$i] = $N - $S[$i];
}
}
}
print_r($S);
No idea where i did wrong or I'm doing on wrong way.
See Question&Answers more detail:os