Reputation: 131
I do mathematical calculations using two arrays like this
$d_positif
array(3) { [0]=> float(2.7742631687417) [1]=> float(2.5949809043991) [2]=> float(3.0174025996932) }
$d_negatif
array(3) { [0]=> float(2.7259998526469) [1]=> float(3.4826656582587) [2]=> float(3.2284968891602) }
and i have formula
$count = count($d_positif);
for ($i = 0; $i < $count; $i++) {
$v[$i] = $d_positif[$i] / ($d_negatif[$i] + $d_positif[$i]);
}
V1 = 2.7742631687417 / (2.7742631687417 + 2.7259998526469)
V2 = 2.5949809043991 / (2.5949809043991 + 3.4826656582587)
V3 = 3.0174025996932 / (3.0174025996932 + 3.2284968891602)
I should get a result like this
array(3) { [0]=> float(0,495612636) [1]=> float(0,573028659) [2]=> float(0,51689863) }
but the output of mathematical operations like this
array(3) { [0]=> float(0.50438736437759) [1]=> float(0.42697134123315) [2]=> float(0.48310136995931) }
anyone can help me why it can be like that?
Upvotes: 2
Views: 57
Reputation: 41810
The output you are expecting is actually the result of
$v[$i] = $d_negatif[$i] / ($d_negatif[$i] + $d_positif[$i]);
not
$v[$i] = $d_positif[$i] / ($d_negatif[$i] + $d_positif[$i]);
Upvotes: 3