Esempio n. 1
0
function countUpHords(array $param)
{
    foreach ($param as $key => $value) {
        ${$key} = $value;
    }
    unset($param);
    if (empty($end)) {
        //$end = 0 => A ; $end = 1 => B
        $forDiff = 1;
        $x = $b;
    } else {
        $forDiff = -1;
        $x = $a;
        $a = $b;
    }
    $f_a = $coef1 * pow($a, 3) + $coef2 * pow($a, 2) + $coef3 * $a + $coef4;
    //count f(a) or f(b)
    $n = 0;
    $tabCalc = "<tr><th></th><th>{$coef1}</th><th>{$coef2}</th><th>{$coef3}</th><th>{$coef4}</th></tr>";
    //table for calcs
    $listOfH = '';
    //this var have list of calcs h
    do {
        $param = ['id' => $n, 'x[n]' => $x];
        $calc = getCalc($coef1, $coef2, $coef3, $coef4, $x);
        $tabCalc .= "<tr style='border-top: 2px solid black;'><td rowspan='2'>x[{$n}] = {$x}</td><td>:</td><td>{$calc['0']}</td><td>{$calc['2']}</td><td>{$calc['4']}</td></tr>\n                    <tr><td>{$coef1}</td><td>{$calc['1']}</td><td>{$calc['3']}</td><td>{$calc['5']}</td></tr>";
        $param['f(x[n])'] = $calc[5];
        $param['a/b'] = correctNum(($x - $a) * $forDiff);
        $param['f(a/b)'] = correctNum(($param['f(x[n])'] - $f_a) * $forDiff);
        if (empty($param['f(a/b)'])) {
            //early exit (division by zero)
            return false;
        }
        $param['h'] = correctNum($param['f(x[n])'] * $param['a/b'] / $param['f(a/b)']);
        $listOfH .= "h[{$n}] = {$param['f(x[n])']} * {$param['a/b']} / {$param['f(a/b)']} = {$param['h']}<br/>";
        $params[$n] = $param;
        $x = correctNum($x - $param['h']);
        $n++;
    } while (!empty($param['h']) && $n < 56);
    //if there is closing, 56 step will be last
    $lastX =& $params[count($params) - 1]['x[n]'];
    $lastX = "<span class='colGreen'>{$lastX}</span>";
    unset($lastX);
    return [$params, $tabCalc, $listOfH];
}
Esempio n. 2
0
function countUpKos(array $param)
{
    foreach ($param as $key => $value) {
        ${$key} = $value;
    }
    unset($param);
    /*count coefs f'(x[n])*/
    $coef1_L = $coef1 * 3;
    $coef2_L = $coef2 * 2;
    $coef3_L = $coef3;
    /*//count coefs f'(x[n])*/
    $n = 0;
    $tabCalc = "<tr><th></th><th>{$coef1}</th><th>{$coef2}</th><th>{$coef3}</th><th>{$coef4}</th></tr>";
    // table for calcs f(x)
    $tabCalc_L = "<tr><th></th><th>{$coef1_L}</th><th>{$coef2_L}</th><th>{$coef3_L}</th></tr>";
    // table for calcs f'(x)
    do {
        $param = array('id' => $n, 'x[n]' => $x);
        $calc = getCalc($coef1, $coef2, $coef3, $coef4, $x);
        $calc_L = getCalc_L($coef1_L, $coef2_L, $coef3_L, $x);
        $tabCalc .= "<tr style='border-top: 2px solid black;'><td rowspan='2'>x[{$n}] = {$x}</td><td>:</td><td>{$calc['0']}</td><td>{$calc['2']}</td><td>{$calc['4']}</td></tr>\n                    <tr><td>{$coef1}</td><td>{$calc['1']}</td><td>{$calc['3']}</td><td>{$calc['5']}</td></tr>";
        $tabCalc_L .= "<tr style='border-top: 2px solid black;'><td rowspan='2'>x[{$n}] = {$x}</td><td>:</td><td>{$calc_L['0']}</td><td>{$calc_L['2']}</td></tr>\n                    <tr><td>{$coef1_L}</td><td>{$calc_L['1']}</td><td>{$calc_L['3']}</td></tr>";
        $param['f(x[n])'] = $calc[5];
        $param['f\'(x[n])'] = $calc_L[3];
        if (empty($param['f\'(x[n])'])) {
            //early exit (division by zero)
            return false;
        }
        $param['h'] = correctNum($param['f(x[n])'] / $param['f\'(x[n])']);
        $params[$n] = $param;
        if (empty($param['h'])) {
            // keeping coefs square equation for counting two other solutions
            $coef2 = $calc[1];
            $coef3 = $calc[3];
        }
        $x = correctNum($x - $param['h']);
        $n++;
    } while (!empty($param['h']) && $n < 56);
    //if there is closing, 56 step will be last
    $lastX =& $params[count($params) - 1]['x[n]'];
    $lastX = "<span class='colGreen'>{$lastX}</span>";
    unset($lastX);
    return [$params, $tabCalc, $tabCalc_L, countUpSquare($coef1, $coef2, $coef3, $param['x[n]'])];
}
Esempio n. 3
0
function countUpSquare($coef1, $coef2, $coef3, $firstSolution)
{
    $calcSquare = "<br />Урав. 2-го порядка: ({$coef1} * x<sup>2</sup>) + ({$coef2} * x) + ({$coef3}) = 0<br />";
    $d = correctNum(pow($coef2, 2) - 4 * $coef1 * $coef3);
    $calcSquare .= "<br />D = {$coef2}<sup>2</sup> - 4*{$coef1}*{$coef3} = {$d}<br /><br />";
    if ($d < 0) {
        $d = abs($d);
        $pow12 = correctNum(pow($d, 1 / 2));
        $part1 = correctNum(-$coef2 / (2 * $coef1));
        $part2 = correctNum($pow12 / (2 * $coef1));
        $calcSquare .= "x<sub>2, 3</sub> = ( -({$coef2}) &#177; √<span class='radical'>-{$d}</span> ) / (2*{$coef1}) = ( -({$coef2}) &#177; {$pow12}i ) / (2*{$coef1}) = <span class='colorBlue''>{$part1} &#177; {$part2}i</span>";
    } elseif ($d > 0) {
        $pow12 = correctNum(pow($d, 1 / 2));
        $secondSolution = correctNum((-$coef2 + $pow12) / (2 * $coef1));
        $thirdSolution = correctNum((-$coef2 - $pow12) / (2 * $coef1));
        $calcSquare .= "x<sub>2</sub> = ( -({$coef2}) + √<span class='radical'>{$d}</span> ) / (2*{$coef1}) = ( -({$coef2}) + {$pow12} ) / (2*{$coef1}) = <span class='colorBlue''>{$secondSolution}</span><br /><br />\n                        x<sub>3</sub> = ( -({$coef2}) - √<span class='radical'>{$d}</span> ) / (2*{$coef1}) = ( -({$coef2}) - {$pow12} ) / (2*{$coef1}) = <span class='colorBlue''>{$thirdSolution}</span>";
    } else {
        $secondSolution = -$coef2 / (2 * $coef1);
        $calcSquare .= "x<sub>2</sub> = -({$coef2}) / (2 * {$coef1}) = {$secondSolution}<br /><br />\n                        <span style='color: red;'>По идее такого быть не должно!<br />Лучше перепроверить введённые данные</span>";
    }
    $calcSquare .= "<br /><br />x<sub>1</sub> = <span class='colorBlue'>{$firstSolution}</span><br />";
    return $calcSquare;
}
Esempio n. 4
0
function countUpKombo(array $param)
{
    $pattern = '<span>x<sub class=\'index\' >n</sub></span>';
    $pattern_line = '<span>x<sub class=\'index\' >n</sub><sup class=\'line\' >—</sup></span>';
    $patOnlyLine = '<sup class=\'line\' >—</sup>';
    //transformation array's items on single vars | begin
    foreach ($param as $key => $value) {
        ${$key} = $value;
    }
    unset($param);
    //transformation array's items on single vars | end
    if (empty($end)) {
        //$end = 0 => fixed A ; $end = 1 => fixed B
        $forDiff = 1;
        $x = $b;
        $x_line = $a;
        $forTable = "{$pattern} - {$pattern_line}";
        $forTableF = "f({$pattern}) - f({$pattern_line})";
    } else {
        $forDiff = -1;
        $x = $a;
        $x_line = $b;
        $forTable = "{$pattern_line} - {$pattern}";
        $forTableF = "f({$pattern_line}) - f({$pattern})";
    }
    /*count coefs f'(x[n])*/
    $coef1_L = $coef1 * 3;
    $coef2_L = $coef2 * 2;
    $coef3_L = $coef3;
    /*//count coefs f'(x[n])*/
    $n = 0;
    $mainTable = "<tr><th rowspan='2'>n</th><th>{$pattern}</th><th rowspan='2'>{$forTable}</th><th>f({$pattern})</th><th rowspan='2'>{$forTableF}</th><th rowspan='2'>f '({$pattern_line})</th><th>h</th></tr>\n                  <tr><th>{$pattern_line}</th><th>f({$pattern_line})</th><th>h<sup class='lineH' >—</sup></th></tr>";
    //table for calcs f(x)
    $tabCalc = "<tr><th class='fontNorm' ><span class='colorBlack'>result:</span> f({$pattern})</th><th>{$coef1}</th><th>{$coef2}</th><th>{$coef3}</th><th>{$coef4}</th></tr>\n";
    //table for calcs f(x_line)
    $tabCalc_line = "<tr><th class='fontNorm'><span class='colorBlack'>result:</span> f({$pattern_line})</th><th>{$coef1}</th><th>{$coef2}</th><th>{$coef3}</th><th>{$coef4}</th></tr>\n";
    //table for calcs f'(x_line)
    $tabCalc_deriv_line = "<tr><th class='fontNorm'><span class='colorBlack'>result:</span> f '({$pattern_line})</th><th>{$coef1_L}</th><th>{$coef2_L}</th><th>{$coef3_L}</th></tr>\n";
    //this var have list of calcs h
    $listOfH = '';
    do {
        $param = ['id' => $n, 'x[n]' => $x, 'x[n]line' => $x_line, 'x[n]-x[n]line' => correctNum(($x - $x_line) * $forDiff)];
        $patChanging = "<sub class=\\'index\\' >{$n}</sub>";
        $calc = getCalc($coef1, $coef2, $coef3, $coef4, $x);
        $calc_line = getCalc($coef1, $coef2, $coef3, $coef4, $x_line);
        $calc_deriv_line = getCalc_L($coef1_L, $coef2_L, $coef3_L, $x_line);
        $tabCalc .= "<tr class='separate' ><td rowspan='2'>x{$patChanging} = {$x}</td><td>:</td><td>{$calc[0]}</td><td>{$calc[2]}</td><td>{$calc[4]}</td></tr>\n                    <tr><td>{$coef1}</td><td>{$calc[1]}</td><td>{$calc[3]}</td><td class='colGreen'>{$calc[5]}</td></tr>";
        $tabCalc_line .= "<tr class='separate' ><td rowspan='2'>x{$patChanging}{$patOnlyLine} = {$x_line}</td><td>:</td><td>{$calc_line[0]}</td><td>{$calc_line[2]}</td><td>{$calc_line[4]}</td></tr>\n                    <tr><td>{$coef1}</td><td>{$calc_line[1]}</td><td>{$calc_line[3]}</td><td class='colGreen'>{$calc_line[5]}</td></tr>";
        $tabCalc_deriv_line .= "<tr class='separate' ><td rowspan='2'>x{$patChanging}{$patOnlyLine} = {$x_line}</td><td>:</td><td>{$calc_deriv_line[0]}</td><td>{$calc_deriv_line[2]}</td></tr>\n                    <tr><td>{$coef1_L}</td><td>{$calc_deriv_line[1]}</td><td class='colGreen'>{$calc_deriv_line[3]}</td></tr>";
        if (abs($param['x[n]-x[n]line']) <= 0.0001) {
            $mainTable .= "<tr class='separate'><td rowspan='2'>{$n}</td><td>{$param['x[n]']}</td><td rowspan='2'>{$param['x[n]-x[n]line']}</td></tr>\n                           <tr><td>{$param['x[n]line']}</td></tr>";
            break 1;
        }
        $param['f(x[n])'] = $calc[5];
        $param['f(x[n])line'] = $calc_line[5];
        $param['f\'(x[n])line'] = $calc_deriv_line[3];
        $param['f(x[n])-f(x[n])line'] = ($param['f(x[n])'] - $param['f(x[n])line']) * $forDiff;
        //early exit (division by zero)
        if (empty($param['f(x[n])-f(x[n])line']) || empty($param['f\'(x[n])line'])) {
            return false;
        }
        $param['h'] = correctNum($param['f(x[n])'] * $param['x[n]-x[n]line'] / $param['f(x[n])-f(x[n])line']);
        $param['h_line'] = correctNum($param['f(x[n])line'] / $param['f\'(x[n])line']);
        $listOfH .= "h{$patChanging} = {$param['f(x[n])']} * {$param['x[n]-x[n]line']} / {$param['f(x[n])-f(x[n])line']} = {$param['h']}<br/>\n                     h{$patChanging}<sup class='lineH' style='right: 19px;' >—</sup> = {$param['f(x[n])line']} / {$param['f\'(x[n])line']} = {$param['h_line']}";
        $mainTable .= "<tr class='separate'><td rowspan='2'>{$n}</td><td>{$param['x[n]']}</td><td rowspan='2'>{$param['x[n]-x[n]line']}</td>\n                           <td>{$param['f(x[n])']}</td><td rowspan='2'>{$param['f(x[n])-f(x[n])line']}</td>\n                           <td rowspan='2'>{$param['f\'(x[n])line']}</td><td>{$param['h']}</td></tr>\n                       <tr><td>{$param['x[n]line']}</td><td>{$param['f(x[n])line']}</td><td>{$param['h_line']}</td></tr>";
        if (empty($param['h']) && empty($param['h_line'])) {
            $listOfH .= '<hr />';
            break 1;
        }
        $x = correctNum($x - $param['h']);
        $x_line = correctNum($x_line - $param['h_line']);
        $n++;
        $listOfH .= "<br />x<sub class=\\'index\\' >{$n}</sub> = {$param['x[n]']} - ({$param['h']}) = {$x}<br />\n                     x<sub class=\\'index\\' >{$n}</sub>{$patOnlyLine} = {$param['x[n]line']} - ({$param['h_line']}) = {$x_line}<hr />";
    } while ($n < 30);
    //if there is closing, 30 step will be last
    //keeping coefs square equation for counting two other solutions |begin
    //redefine vars $coef2 and $coef3
    if (abs($calc[5]) <= abs($calc_line[5])) {
        $coef2 = $calc[1];
        $coef3 = $calc[3];
        $firstSolution = $param['x[n]'];
    } else {
        $coef2 = $calc_line[1];
        $coef3 = $calc_line[3];
        $firstSolution = $param['x[n]line'];
    }
    //keeping coefs square equation for counting two other solutions |end
    return [$mainTable, $tabCalc, $tabCalc_line, $tabCalc_deriv_line, $listOfH, countUpSquare($coef1, $coef2, $coef3, $firstSolution)];
}
Esempio n. 5
0
function countUpKos(array $param)
{
    foreach ($param as $key => $value) {
        ${$key} = $value;
    }
    unset($param);
    /*count coefs f'()*/
    $coef1_L = $coef1 * 3;
    $coef2_L = $coef2 * 2;
    $coef3_L = $coef3;
    /*//count coefs f'()*/
    $n = 0;
    $tabCalc = "<tr><th></th><th>{$coef1}</th><th>{$coef2}</th><th>{$coef3}</th><th>{$coef4}</th></tr>";
    // table for calcs f(x)
    $tabCalc_L = "<tr><th></th><th>{$coef1_L}</th><th>{$coef2_L}</th><th>{$coef3_L}</th></tr>";
    // table for calcs f'(x)
    do {
        $param = array('id' => $n, 'x[n]' => $x);
        $calc[0] = correctNum($coef1 * $x);
        //2 row, 3 col
        $calc[1] = correctNum($calc[0] + $coef2);
        //3 row, 3 col
        $calc[2] = correctNum($calc[1] * $x);
        //2 row, 4 col
        $calc[3] = correctNum($calc[2] + $coef3);
        //3 row, 4 col
        $calc[4] = correctNum($calc[3] * $x);
        //2 row, 5 col
        $calc[5] = correctNum($calc[4] + $coef4);
        //3 row, 5 col
        $calc_L[0] = correctNum($coef1_L * $x);
        $calc_L[1] = correctNum($calc_L[0] + $coef2_L);
        $calc_L[2] = correctNum($calc_L[1] * $x);
        $calc_L[3] = correctNum($calc_L[2] + $coef3_L);
        $tabCalc .= "<tr style='border-top: 2px solid black;'><td rowspan='2'>x[{$n}] = {$x}</td><td>:</td><td>{$calc['0']}</td><td>{$calc['2']}</td><td>{$calc['4']}</td></tr>\n                    <tr><td>{$coef1}</td><td>{$calc['1']}</td><td>{$calc['3']}</td><td>{$calc['5']}</td></tr>";
        $tabCalc_L .= "<tr style='border-top: 2px solid black;'><td rowspan='2'>x[{$n}] = {$x}</td><td>:</td><td>{$calc_L['0']}</td><td>{$calc_L['2']}</td></tr>\n                    <tr><td>{$coef1_L}</td><td>{$calc_L['1']}</td><td>{$calc_L['3']}</td></tr>";
        $param['f(x[n])'] = $calc[5];
        $param['f\'(x[n])'] = $calc_L[3];
        if (empty($param['f\'(x[n])'])) {
            //early exit (division by zero)
            return false;
        }
        $param['h'] = correctNum($param['f(x[n])'] / $param['f\'(x[n])']);
        $params[$n] = $param;
        if (empty($param['h'])) {
            // keeping coefs square equation for counting two other solutions
            $resX[0] = $x;
            $coef2 = $calc[1];
            $coef3 = $calc[3] + $calc[5] * -1;
        }
        $x = correctNum($x - $param['h']);
        $n++;
    } while (!empty($param['h']) && $n < 56);
    //if there is closing, 56 step will be last
    $lastX = $params[count($params) - 1]['x[n]'];
    $params[count($params) - 1]['x[n]'] = "<span style='color: green;'>{$lastX}</span>";
    $d = correctNum(pow($coef2, 2) - 4 * $coef1 * $coef3);
    $calcSquare = "<br />D = {$coef2}^2 - 4*{$coef1}*{$coef3} = {$d}";
    $i = $d < 0 ? 'i' : '';
    $calcSquare .= "{$i}<br /><br />";
    $d = abs($d);
    if ($d == 1) {
        $resX[1] = -$coef2 / (2 * $coef1);
        $calcSquare .= "x2 = -({$coef2}) / (2 * {$coef1}) = {$resX['1']}<br /><br />x1 = {$resX['0']}";
    }
    $resX[1] = correctNum((-$coef2 + pow($d, 1 / 2)) / (2 * $coef1));
    $resX[2] = correctNum((-$coef2 - pow($d, 1 / 2)) / (2 * $coef1));
    $calcSquare .= "x2 = (-({$coef2}) + {$d}{$i}^(1/2)) / (2*{$coef1}) = {$resX['1']}<br />x3 = (-({$coef2}) - {$d}{$i}^(1/2)) / (2*{$coef1}) = {$resX['2']}<br /><br />x1 = {$resX['0']}";
    return [$params, $tabCalc, $tabCalc_L, $calcSquare];
}