I have wroted a LU writed in c++ and I need add same code to php i did it it's woarks but in php i have diffrent results. Main calculate in c++ are:
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
cout << tab1[i][j]<<"\t";
}
cout <<endl;
}
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
if (i==j)
{
tab2[i][j]=1;
tab3[i][j]=0;
}
else
{
tab3[i][j]=0;
tab2[i][j]=0;
}
}
}
//glowne dzielenie tego co mamy do rozlozenia
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
for (int k=0;k<m;k++)
{
pom+=tab2[i][k]*tab3[k][j];
pomoc+=tab2[j][k]*tab3[k][i];
}
if (i<=j)
tab3[i][j]=tab1[i][j]-pom;
if (j>=i)
tab2[j][i]=(tab1[j][i]-pomoc)/tab3[i][i];
pom=0;
pomoc=0;
}
}
and in php it looks:
$w= sizeof($this->input['macierz_1']);
$pom=0; $pomoc=0;
for ($i=1;$i<=$w;$i++)
{
for ($j=1;$j<=$w;$j++)
{
if ($i==$j)
{
$tab2[$i][$j]=1;
$tab3[$i][$j]=0;
}
else
{
$tab3[$i][$j]=0;
$tab2[$i][$j]=0;
}
}
}
//glowne dzielenie tego co mamy do rozlozenia
for ($i=1;$i<=$w;$i++)
{
for ($j=1;$j<=$w;$j++)
{
for ($k=1;$k<=$w;$k++)
{
$pom+=$tab2[$i][$k]*$tab3[$k][$j];
$pomoc+=$tab2[$j][$k]*$tab3[$k][$i];
}
if ($i<=$j)
$tab3[$i][$j]=($this->input['macierz_1'][$i][$j])-$pom;
if ($j>=$i)
$tab2[$j][$i]=(($this->input['macierz_1'][$i][$j])-$pomoc)/$tab3[$i][$i];
$pom=0;
$pomoc=0;
}
}
echo '<b>Macierz wynikowa L:<br> </b>';
$this->formularz($w,$w,'macierz_L',$tab2);
echo '<b>Macierz wynikowa U: <br> </b>';
$this->formularz($w,$w,'macierz_U',$tab3);
}
I know that i started arry in php form 1 not 0 and in all algorym its ok. Can any one tell me where i maked mastake or give algorytm LU in php that it woarks?