private void button2_Click(object sender, EventArgs e)
{
string equation = textBox1.Text;
double initialGuess = double.Parse(textBox3.Text);
double epsilon = double.Parse(textBox4.Text);
double delta = double.Parse(textBox5.Text);
double root = SecantMethodSolve(equation, initialGuess, epsilon, delta);
label1.Text = "Root: " + root.ToString();
}
private double SecantMethodSolve(string equation, double x0, double epsilon, double delta)
{
double x1 = x0 + delta;
double f0 = EvaluateExpression(equation, x0);
double f1 = EvaluateExpression(equation, x1);
double x2, f2;
while (Math.Abs(f1) > epsilon)
{
x2 = x1 - f1 * (x1 - x0) / (f1 - f0);
f2 = EvaluateExpression(equation, x2);
x0 = x1;
f0 = f1;
x1 = x2;
f1 = f2;
}
return x1;
}
private double EvaluateExpression(string expression, double x)
{
try
{
DataTable dt = new DataTable();
string formula = expression.Replace("x", x.ToString());
object result = dt.Compute(formula, "");
return Convert.ToDouble(result);
}
catch (Exception)
{
return double.NaN;
}
}
private void button2_Click(object sender, EventArgs e)
{
string equation = textBox1.Text;
double initialGuess = double.Parse(textBox3.Text);
double epsilon = double.Parse(textBox4.Text);
double delta = double.Parse(textBox5.Text);
double root = SecantMethodSolve(equation, initialGuess, epsilon, delta);
label7.Text = "Root: " + root.ToString();
}
private double SecantMethodSolve(string equation, double x0, double epsilon, double delta)
{
double x1 = x0 + delta;
double f0 = EvaluateExpression(equation, x0);
double f1 = EvaluateExpression(equation, x1);
double x2, f2;
while (Math.Abs(f1) > epsilon)
{
x2 = x1 - f1 * (x1 - x0) / (f1 - f0);
f2 = EvaluateExpression(equation, x2);
x0 = x1;
f0 = f1;
x1 = x2;
f1 = f2;
}
return x1;
}
private double EvaluateExpression(string expression, double x)
{
// Реализация метода для вычисления значения выражения при указанном значении x
}