Program okienkowy liczący metodą Eulera dane zagadnienie poczatkowe; Co moze byc przyczyna zawieszenia sie programu po kliknieciu buttona?
public Form1()
{
InitializeComponent();
}
double x0, y0, h;
private void textBox1_TextChanged(object sender, EventArgs e)//wczytywanie zmiennych wprowadzonych przez użytkownika
{
x0 = double.Parse(textBox1.Text);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
y0 = double.Parse(textBox2.Text);
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
h = double.Parse(textBox3.Text);
}
static double df(double x, double y)
{
return y * Math.Cos(x);
}
public delegate double Funkcja(double x, double y);
private void Start_Click(object sender, EventArgs e)
{
{
double WynikEuler = y0;
richTextBox1.Clear();
richTextBox1.SelectedText = string.Format("x:\t" + "y:\t\t\t" + "Wynik dokładny:\t\t\t" + "Różnica:\t") + Environment.NewLine;
for (int i = 0; i <= 50; i++)
{
double x = 0.1 * i;
WynikEuler = Euler(df, x0, WynikEuler, h, x);
double WynikDokladny = Math.Exp(Math.Sin(x));
double roznica = Math.Abs(WynikEuler - WynikDokladny);
richTextBox1.Text += "x:\t" + x + "y\t" + WynikEuler.ToString("E5") + "\t" + "Wynik dokładny:\t" + WynikDokladny.ToString("E5") + "\t" + "Różnica:\t" + roznica.ToString("E5") + Environment.NewLine;
x0 = x;
}
}
}
public static double Euler(Funkcja df, double x0, double y0, double h, double x)
{
double Nowyx, Nowyy, rezultat;
if (x <= x0)
{
rezultat = y0;
}
else
{
do
{
if (h > x - x0)
{
h = x - x0;
}
Nowyy = y0 + df(x0, y0) * h;
Nowyx = x0 + h;
x0 = Nowyx;
y0 = Nowyy;
}
while (x0 < x);
rezultat = Nowyy;
}
return rezultat;
}
}
}