class GoldenSection {
PHI = (1 + Math.sqrt(5)) / 2;
f(x) {
return Math.pow(x, 3) - 2 * Math.pow(x, 2) - 3 * x - 5;
}
FindMIn(a, b, e) {
let x1, x2;
while (true){
x1 = b - (b - a) / this.PHI;
x2 = a + (b - a) / this.PHI;
if (this.f(x1) >= this.f(x2))
a = x1;
else
b = x2;
if (Math.abs(b - a) < e)
break;
}
return (a + b) / 2;
}
FindMax(a, b, e) {
let x1, x2;
while (true) {
x1 = b - (b - a) / this.PHI;
x2 = a + (b - a) / this.PHI;
if (this.f(x1) <= this.f(x2))
a = x1;
else
b = x2;
if (Math.abs(b - a) < e)
break;
}
return (a + b) / 2;
}
}
let GS = new GoldenSection();
console.log(GS.FindMIn(0,4,0.001));
console.log(GS.FindMax(0, 4, 0.001));
<form>
Уравнение
<input type="text" id="GOLD">
=0
<br>
<br>
Интвервал
<input type="text" id="prib" style="width:50px;">
<br>
<br>
<button type="button" onclick="polinom()">
Решить
</button>
</form>
<p id="result">
</p>
<!DOCTYPE html>
<html lang="">
<head>
<title>Task 2</title>
<script>
class GoldenSection {
PHI = (1 + Math.sqrt(5)) / 2;
f(x) {
return Math.pow(x, 3) - 2 * Math.pow(x, 2) - 3 * x - 5;
}
FindMIn(a, b, e) {
let x1, x2;
while (true){
x1 = b - (b - a) / this.PHI;
x2 = a + (b - a) / this.PHI;
if (this.f(x1) >= this.f(x2))
a = x1;
else
b = x2;
if (Math.abs(b - a) < e)
break;
}
return (a + b) / 2;
}
FindMax(a, b, e) {
let x1, x2;
while (true) {
x1 = b - (b - a) / this.PHI;
x2 = a + (b - a) / this.PHI;
if (this.f(x1) <= this.f(x2))
a = x1;
else
b = x2;
if (Math.abs(b - a) < e)
break;
}
return (a + b) / 2;
}
}
let GS = new GoldenSection();
console.log(GS.FindMIn(0,4,0.001));
console.log(GS.FindMax(0, 4, 0.001));
</script>
</head>
<body>
<form>
Уравнение
<input type="text" id="polin">
=0
<br>
<br>
Начальное приближение
<input type="text" id="prib" style="width:50px;">
<br>
<br>
<button type="button" onclick="polinom()">
Решить
</button>
</form>
<p id="result">
</p>
</body>
</html>
Чтобы допустим уравнение Math.pow(x, 3) - 2 * Math.pow(x, 2) - 3 * x - 5;
Я мог ввести в форме , и интервалы console.log(GS.FindMIn(0,4,0.001));
Мало опыта с HTML , поэтому прошу помощи чтобы можно было связать нормально формы и при отправки можно было получать результат, много читал , но ничего не получается не знаю как сделать
[1]: https://i.stack.imgur.com/JnJ8g.png