Пример #1
0
 /**
  * Solve the equation.
  *
  * Does not return any values, but holds them for later retrieval.
  */
 public function solve()
 {
     $a = $this->equation->getA();
     $b = $this->equation->getB();
     $c = $this->equation->getC();
     if ($this->getBsmfac($a, $b, $c) < 0) {
         $roots = $this->findImaginaryRoots($a, $b, $c);
     } else {
         $roots = $this->findRealRoots($a, $b, $c);
     }
     $roots = $this->orderRoots($roots);
     $this->saveRootsAsStrings($roots);
 }
 public function getAllEquations()
 {
     $result = ['groups' => [], 'ungrouped' => [], 'grouped' => []];
     // GROUPS
     $group_result = $this->equationDao->getGroups();
     $groups = [];
     if ($group_result and $group_result->num_rows > 0) {
         for ($i = 0; $i < $group_result->num_rows; $i++) {
             $temp = mysqli_fetch_array($group_result, MYSQLI_ASSOC);
             array_push($groups, $temp['group']);
         }
     }
     $result['groups'] = $groups;
     // UNGROUPED EQUATIONS
     $ungrouped_result = $this->equationDao->getUngroupedEquations();
     $ungrouped_equations = [];
     if ($ungrouped_result and $ungrouped_result->num_rows > 0) {
         while ($row = $ungrouped_result->fetch_assoc()) {
             $equation = new Equation();
             $equation->setEquation($row['equation']);
             $equation->setAnswer($row['answer']);
             array_push($ungrouped_equations, $equation);
         }
     }
     $result['ungrouped'] = $ungrouped_equations;
     // GROUPED EQUATIONS
     $grouped_result = $this->equationDao->getGroupedEquations();
     $temp_grouped_equations = [];
     $equations = [];
     if ($grouped_result and $grouped_result->num_rows > 0) {
         while ($row = $grouped_result->fetch_assoc()) {
             $equation = new Equation();
             $equation->setEquation($row['equation']);
             $equation->setAnswer($row['answer']);
             array_push($temp_grouped_equations, [$equation, $row['group']]);
             array_push($equations, $equation);
         }
     }
     $grouped_equations = [];
     $temp_equations = [];
     foreach ($temp_grouped_equations as $equation) {
         if ($grouped_equations == [] or in_array($equation[0], $temp_equations) === false) {
             array_push($temp_equations, $equation[0]);
             $indexes = array_keys($equations, $equation[0]);
             $groups = [];
             foreach ($indexes as $index) {
                 array_push($groups, $temp_grouped_equations[$index][1]);
             }
             array_push($grouped_equations, [$equation[0], $groups]);
         }
     }
     $result['grouped'] = $grouped_equations;
     return $result;
 }
Пример #3
0
include 'header.php';
include "class/equation.php";
if ($_SESSION['langue'] == 'en') {
    $text = array("Equation", "The system does not manage the complex numbers.", "Resolve", "Result", "Read documentation", "Documentation", "<samp>The present form allows to solve this type of equation</samp><br />\n                          <var>ax³</var> + <var>bx²</var> + <var>cx</var> + <var>d</var> = 0<br />\n                          <samp>Fields can remain empty</samp>");
    $algo = array("Algorithm for first degree equations <var>ax</var> + <var>b</var> = 0<br /><br />x = (- b)/ (a)", "Algorithm for second degree equations <var>ax²</var> + <var>bx</var> + <var>c</var> = 0<br /><br />\n                          Delta = <var>bx²</var> - 4 * a * c<br />\n                          SI Delta < 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x1 = (- b - racine(Delta))i / (2 * a)<br /></span>\n                            <span class=\"marge\">x2 = (- b + racine(Delta))i / (2 * a)<br /></span>\n                          FINSI<br />\n                          SI Delta = 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x = (-b) / (2 * a)<br /></span>\n                          FINSI<br />\n                          SI Delta > 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x1 = (- b - racine(Delta)) / (2 * a)<br /></span>\n                            <span class=\"marge\">x2 = (- b + racine(Delta)) / (2 * a)<br /></span>\n                          FINSI", "For this algorithm, I have used this website <a href=\"http://www.alain.be/boece/degree3algo.html\">site</a><br />\n                          Thanks to this, i can do my algorithm<br />\n                          This algorithm is to big to be on this page.");
    $menu = array("Quadratic equation", "Cubic function", "Linear equation");
} else {
    if ($_SESSION['langue'] == 'fr') {
        $text = array("Equation", "Le système ne prend pas en charge les nombres complexes.", "Résoudre", "Résultat", "Voir la documentation", "Documentation", "<samp>Le formulaire présent permet de résoudre ce type d'équation</samp><br />\n                          <var>ax³</var> + <var>bx²</var> + <var>cx</var> + <var>d</var> = 0<br />\n                          <samp>Les champs peuvent rester vides</samp>");
        $algo = array("Algorithme pour une equation du premier degré <var>ax</var> + <var>b</var> = 0<br /><br />x = (- b)/ (a)", "Algorithme pour une equation du second degré <var>ax²</var> + <var>bx</var> + <var>c</var> = 0<br /><br />\n                          Delta = <var>bx²</var> - 4 * a * c<br />\n                          SI Delta < 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x1 = (- b - racine(Delta))i / (2 * a)<br /></span>\n                            <span class=\"marge\">x2 = (- b + racine(Delta))i / (2 * a)<br /></span>\n                          FINSI<br />\n                          SI Delta = 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x = (-b) / (2 * a)<br /></span>\n                          FINSI<br />\n                          SI Delta > 0<br />\n                          ALORS<br />\n                            <span class=\"marge\">x1 = (- b - racine(Delta)) / (2 * a)<br /></span>\n                            <span class=\"marge\">x2 = (- b + racine(Delta)) / (2 * a)<br /></span>\n                          FINSI", "Pour cette algorithme, je me suis servi de ce <a href=\"http://www.alain.be/boece/degree3algo.html\">site</a><br />\n                          A partir de la méthode de la calcul, je fais mon algorithme<br />\n                          Celui ci est trop imposant pour étre affiché ici.");
        $menu = array("Second degrée", "Troisiéme degrée", "Premier degrée");
    }
}
if (isset($_POST['valider_equation'])) {
    $equation = new Equation($_POST['x3'], $_POST['x2'], $_POST['x'], $_POST['d']);
    $equation->Resolve();
    $result = $equation->getResult();
    $result_d = $equation->getResult_detail();
    $delta = $equation->getDelta();
    $f = $equation->getFonctionAff();
}
?>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12" style="margin-top: 10px;">
            <div class="alert alert-warning" role="alert"><?php 
echo $text[1];
?>
</div>
        </div>
Пример #4
0
<?php

require "equation.php";
if (isset($_POST['submit'])) {
    $equation = new Equation($_POST['equation']);
    echo 'Infix: ' . $equation->getInfix();
    echo '<br>Evaluation: ' . $equation->evaluate();
}
?>
<html>
<body>
	<form method="post">
		<input type="text" name="equation"/>
		<button type="submit" name="submit" value="submit">Submit</button>
	</form>
</body>
</html>