-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMullerCalculadora.php
214 lines (180 loc) · 6.18 KB
/
MullerCalculadora.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
class ImpMuller {
public function calculateMuller($x0, $x1, $x2, $maxIter, $tol) {
try {
// Extract input values from text fields
$x0 = floatval($_POST["x0"]);
$x1 = floatval($_POST["x1"]);
$x2 = floatval($_POST["x2"]);
$maxIter = intval($_POST["maxIter"]);
$tol = floatval($_POST["tol"]);
// Initialize a string to store results
$results = "Resuldados del Metodo de Muller:<br>----------------------<br>";
// Perform Muller's method iterations
$h1 = $x1 - $x0;
$h2 = $x2 - $x1;
//Add a check for division by zero
if ($h1 == 0 || $h2 == 0) {
throw new DivisionByZeroError("Error: Division por cero.");
}
$d1 = ($this->f($x1) - $this->f($x0)) / $h1;
$d2 = ($this->f($x2) - $this->f($x1)) / $h2;
$d = ($d2 - $d1) / ($h2 + $h1);
$i = 3;
while ($i <= $maxIter) {
$b = $d2 + $h2 * $d;
$D = sqrt($b * $b - 4 * $this->f($x2) * $d);
$E = abs($b - $D) < abs($b + $D) ? $b + $D : $b - $D;
$h = -2 * $this->f($x2) / $E;
$p = $x2 + $h;
$results .= "ITERACION #" . ($i - 2) . ": raiz = " . $p . "<br>";
if (abs($h) < $tol) {
$results .= "¡ Eureka ! Raiz encontrada con la precisión requerida. :)<br>";
break;
}
$x0 = $x1;
$x1 = $x2;
$x2 = $p;
$h1 = $x1 - $x0;
$h2 = $x2 - $x1;
// Add a check for division by zero
if ($h1 == 0 || $h2 == 0) {
throw new DivisionByZeroError("Errorrr: Division por cero.");
}
$d1 = ($this->f($x1) - $this->f($x0)) / $h1;
$d2 = ($this->f($x2) - $this->f($x1)) / $h2;
$d = ($d2 - $d1) / ($h2 + $h1);
$i++;
}
if ($i > $maxIter) {
$results .= "Numero Maximo de iteraciones realizadas!\n";
}
return $results;
} catch (DivisionByZeroError $ex) {
return $ex->getMessage();
}
}
private function f($x) {
// Define your function here
return $x * $x * $x - $x * $x - $x - 1;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Muller Method</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
h1, h2 {
text-align: center;
}
form {
width: 300px;
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f8f8f8;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 8px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
background-color: #4caf50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#results-container {
width: 400px;
margin-top: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f8f8f8;
display: flex;
flex-direction: column;
align-items: center;
}
.result {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Metodo de Muller - Muller Method</h1>
<h2>CREADO POR: ENRIQUE MENDIA PARADA</h2>
<form action="index.php" method="post">
<div class="form-group">
<label for="x0">x0:</label>
<input type="text" class="form-control" name="x0" id="x0">
</div>
<div class="form-group">
<label for="x1">x1:</label>
<input type="text" class="form-control" name="x1" id="x1">
</div>
<div class="form-group">
<label for="x2">x2:</label>
<input type="text" class="form-control" name="x2" id="x2">
</div>
<div class="form-group">
<label for="maxIter">Numero de iteraciones:</label>
<input type="text" class="form-control" name="maxIter" id="maxIter">
</div>
<div class="form-group">
<label for="tol">Tolerancia:</label>
<input type="text" class="form-control" name="tol" id="tol">
</div>
<button type="submit" class="btn btn-primary">Calcular</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get input values
$x0 = isset($_POST["x0"]) ? floatval($_POST["x0"]) : null;
$x1 = isset($_POST["x1"]) ? floatval($_POST["x1"]) : null;
$x2 = isset($_POST["x2"]) ? floatval($_POST["x2"]) : null;
$maxIter = isset($_POST["maxIter"]) ? intval($_POST["maxIter"]) : null;
$tol = isset($_POST["tol"]) ? floatval($_POST["tol"]) : null;
// Check if all values are set
if ($x0 !== null && $x1 !== null && $x2 !== null && $maxIter !== null && $tol !== null) {
// Create an instance of ImpMuller
$muller = new ImpMuller();
// Calculate Muller's method
$result = $muller->calculateMuller($x0, $x1, $x2, $maxIter, $tol);
// Display result in a container
echo '<div id="results-container">';
echo '<div class="result">' . $result . '</div>';
echo '</div>';
} else {
echo "¡Ingresa valores válidos para todos los campos!";
}
}
?>
</body>
</html>