f(x)=0 olan denklemin E mutlak hatasıyla yaklaşık çözümlerinin bulunabilmesi için verilen denklemin
f(x)=x-h(x)=0 şekline dolayısıyla x-h(x)=0 veya x=h(x) şekline dönüştürülür. Burada h(x) sıradan bir fonksiyon olmayacaktır. h(x) fonksiyonunun birinci türevinin mutlak değerine verilen x(0) değerinin karşılığı 1 den küçük olmalıdır, aksi taktirde f(x) fonksiyonundan x' i ifade eden başka bir fonksiyon ifadesi çekilir.
x(n)=h(x(n))=x(n+1)
Bu yöntemle verilen denklemin yaklaşık çözümünün bulunabilmesi için x(0) ve E değerlerinin verilmesi gerekmektedir.
Basit iterasyon yöntemi teorik olarak bu şekil de ifade edilebilir. Aşağıda basit iterasyon yöntemiyle C# da yapılan denklem çözümü bulunmaktadır.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Recep Karatas
//10.03.2012
namespace basit_iterasyon_yöntemi
{
public partial class Form1 : Form
{
double denklem, b,a, sonuc,r,p,c;
double x;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
{
MessageBox.Show("Verileri Girmelisiniz...!");
}
else
{
int i = 0;
x = Convert.ToDouble(textBox3.Text);
b = Convert.ToDouble(textBox2.Text);
r = Convert.ToDouble(textBox1.Text);
p = Convert.ToDouble(textBox4.Text);
c = Convert.ToDouble(textBox5.Text);
birinci:
{
denklem = r * x * x + p * x + c;
sonuc = denklem;
a = Math.Abs(sonuc - x);
listBox1.Items.Add("X" + i + "=" + x);
i = i + 1;
listBox2.Items.Add("E =" + a);
}
if (b >= a)
{
label4.Text = Convert.ToString("Sonuç=" + "X" + i + "=" + sonuc);
listBox1.Items.Add("X" + i + "=" + sonuc);
}
else
{
x = sonuc;
goto birinci;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Basit İterasyon Yöntemi";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
listBox1.Items.Clear();
listBox2.Items.Clear();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start("http://recepkaratas.blogspot.com/");
}
}
}
Hiç yorum yok:
Yorum Gönder