asacyra
20-11-2013, 21:53
Было дано задание решение интеграла методом трапеции
вот код
namespace Reshenie
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static float a, b, x, n,g, c, step, y, sum, sum2, sum3;
public static float f(float x)
{
return (float)(32+28*x-9*x*x);
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToSingle(textBox1.Text);
b = Convert.ToSingle(textBox2.Text);
step = Convert.ToSingle(textBox3.Text);
sum = 0;
sum2 = 0;
sum3 = 0;
for (x = a; x <= b; x += step)
{
if (x == a || x == b)
{
y = Math.Abs(f(x));
sum += y;
}
else
{
y = Math.Abs(f(x));
sum2 += y;
}
}
float pogresh = (float)Math.Pow((b - a), 3) /
( (float)Math.Pow((b - a / step), 2));//учитывая погрешность
sum3 = (sum / 2 + sum2) * step + pogresh;
textBox6.Text = "Ответ: " + sum3.ToString("f3");
}
вот код
namespace Reshenie
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static float a, b, x, n,g, c, step, y, sum, sum2, sum3;
public static float f(float x)
{
return (float)(32+28*x-9*x*x);
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToSingle(textBox1.Text);
b = Convert.ToSingle(textBox2.Text);
step = Convert.ToSingle(textBox3.Text);
sum = 0;
sum2 = 0;
sum3 = 0;
for (x = a; x <= b; x += step)
{
if (x == a || x == b)
{
y = Math.Abs(f(x));
sum += y;
}
else
{
y = Math.Abs(f(x));
sum2 += y;
}
}
float pogresh = (float)Math.Pow((b - a), 3) /
( (float)Math.Pow((b - a / step), 2));//учитывая погрешность
sum3 = (sum / 2 + sum2) * step + pogresh;
textBox6.Text = "Ответ: " + sum3.ToString("f3");
}