Metode Heun Menggunakan Program CSharp (C#)

Syntaxnya :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Metode_Heun
{
    class Program
    {
        struct nilai
        {
            public double xa;
            public double ya;
        }
        static void Main(string[] args)
        {
            double h, f, galat;
            int x = 0;
            int y = 1;
            double b = 0.10;
            int n = 5;
            h = (b - x) / n;
            Console.WriteLine("\n\t*****************************************");
            Console.WriteLine("\n\t\t\tMetode Heun");
            Console.WriteLine("\n\t*****************************************");
            Console.WriteLine("\t\tNilai h = {0}", h);
            Console.WriteLine("\n\t\tNilai X={0}\tNilai Y={1}", x, y);
            nilai[] hasil = new nilai[n + 1];

            for (int r = 1; r <= n; r++)
            {
                hasil[r].ya = hasil[r].ya + y + (h / 2) * ((x + y) + (x + (y + h * (x + y))));
                hasil[r].xa = x + h;
                h += 0.0200;
            }
            f = Math.Round(Math.Exp(b) - b - 1, 4);

            galat = f - hasil[n].ya;

            Console.WriteLine("\t\t-------------------------");
            Console.WriteLine("\t\tIterasi\tX[i]\tY[i]");
            Console.WriteLine("\t\t-------------------------");
            for (int i = 1; i <= n; i++)
            {
                Console.WriteLine("\t\t   {0} \t{1} \t{2}", i, hasil[i].xa, hasil[i].ya);
            }
            Console.WriteLine("\t\t-------------------------\n");

            Console.WriteLine("\t\tGalat = | eksak - hampiran |");
            Console.WriteLine("\t\t      = | {0} - {1} |", f, hasil[n].ya);
            Console.WriteLine("\t\t      = | {0} |", galat);
            Console.WriteLine("\t\t      = {0} ", (galat * -1));

            Console.WriteLine("\n\t\tHasil error dari f dan galat");
            Console.WriteLine("\n\t\tError = {0} dan {1}", f, galat);

            Console.ReadKey();
        }
    }
}

Tampilannya : 
Previous
Next Post »
Thanks for your comment