Newton Raphson Yontemi ( Doğrusal Denklem )

Programda kullanıcıdan

  • Başlangıç değerini
  • Mutlak hata değerini

Program 4e-0.5x-x için uygulanmış olup, farklı fonksiyonlar için uygulanmak istendiğinde FonksiyonHesap ve TurevHesap metodların geri dönüş değerleri değiştirilmesi gerekmektedir.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//www.delimuhendis.com




namespace NewtonRaphsonYontemi
{
    class Program
    {
        
        static double x = 0, eskiX = 0;
        static double mutlakHata = 0;
        static double uzaklasma = 0;
        static void Main(string[] args)
        {
            Console.Write("Başlangıç değerini giriniz: ");
            eskiX = Convert.ToDouble(Console.ReadLine());
            x = eskiX;
            Console.Write("Mutlak hata değerini giriniz: ");
            mutlakHata = Convert.ToDouble(Console.ReadLine());

            do
            {
                NewtonRaphson();
                if (uzaklasma > 3)
                    break;
            }
            while (Math.Abs(x - eskiX) > mutlakHata);

            if (uzaklasma > 3)
                Console.WriteLine("\n\nBaşlangıç değeri hatalı seçildi. Kökten uzaklaşıldı.");
            else
                Console.WriteLine("X : " + x);
            Console.Read();

        }


        static double FonksiyonHesap()
        {
            return 4 * Math.Pow(Math.E, (-0.5 * eskiX)) - eskiX;
        }

        static double TurevHesap()
        {
            return -2 * Math.Pow(Math.E, (-0.5 * eskiX));
        }
        
        static void NewtonRaphson()
        {
            eskiX = x;
            x = eskiX - (FonksiyonHesap()/TurevHesap());

            if (x - eskiX < 0)
                uzaklasma++;
           
            
        }
    }

    
}

 

Become a patron at Patreon!

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d blogcu bunu beğendi: