T
T
tera10042018-11-07 19:57:07
C++ / C#
tera1004, 2018-11-07 19:57:07

The program does not output a number. What is the problem?

The program must find the roots of the equation by Newton's method

class Program
    {
        static void Main(string[] args)

        {
            const float e = 0.0001f;
            float x, xLast, fx, _fx;
            Console.WriteLine("Введите начальное приближение к корню");
             x = Convert.ToSingle(Console.ReadLine());
            do
            {
                fx = 2 * Convert.ToSingle(Math.Log(x) - 1 / x);
                _fx = (2 / x) + (1 / x * x);
                xLast = (-2 / x * x) - (2 / x * x * x);
               Convert.ToDouble( x = xLast - fx / _fx);
            }
            while( Math.Abs(fx) > e);
            
            Console.WriteLine( "Значение корня уравнения ={0} ", x);
            Console.Read();
               }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-11-07
@Rsa97

Because the derivative is calculated incorrectly and the method itself is implemented incorrectly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question