20 марта 2017 в 20:08:11
(7 лет 35 недель 4 дня 1 час назад)
500
03.05.2016 18:41:01
Текст задания
Требуется перевести программу с С#(форма)на 1С. Описание программы присутствует в документе ворд! вот файл https://cloud.mail.ru/public/NKdC/9iZpYhJQq
вот код на C#
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;
using System.Windows.Forms.DataVisualization.Charting;
namespace Программа
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double f(double x, double u,double alpha,double b,int M)
{
return -alpha * x + b * u * (1 - x / M);
}
double max(double a, double b)
{
if (a > b) return a;
return b;
}
private void button1_Click(object sender, EventArgs e)
{
double eps1, eps2, alpha, b, h, J1, J2, A_k, X;
int t0, T, M, A, S0, q;
alpha = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);
t0 = Convert.ToInt32(textBox3.Text);
T = Convert.ToInt32(textBox4.Text);
S0 = Convert.ToInt32(textBox5.Text);
M = Convert.ToInt32(textBox6.Text);
A = Convert.ToInt32(textBox7.Text);
eps1 = Convert.ToDouble(textBox9.Text);
eps2 = Convert.ToDouble(textBox10.Text);
q = Convert.ToInt32(textBox11.Text);
A_k = Convert.ToInt32(textBox8.Text);
h = (T - t0) / (double)q;
double[] t = new double[q + 1];
double[] x1 = new double[q + 1];
double[] x2 = new double[q + 1];
double[] psi = new double[q + 1];
double[] u1 = new double[q];
double[] u2 = new double[q];
t[0] = t0;
for (int i = 0; i <= q - 1; i++)
t[i + 1] = t[i] + h;
for (int i = 0; i <= q - 1; i++)
u1[i] = A;
x1[0] = S0;
for (int i = 0; i <= q - 1; i++)
x1[i + 1] = x1[i] + h * f(x1[i], u1[i], alpha, b, M);
J1 = 0;
for (int i = 0; i <= q - 1; i++)
J1 -= x1[i] * h;
for (int i = 0; i <= q - 1; i++)
J1 += A_k * h * (Math.Pow(max(0, -x1[i]), 2) + Math.Pow(max(0, x1[i] - M), 2));
label:
psi[q] = 0;
for (int i = q - 1; i <= 1; i--)
psi[i] = h + psi[i + 1] - alpha * psi[i + 1] * h - b / M * u1[i] * psi[i + 1] * h - 2 * A_k * h * (-max(0, -x1[i]) + max(0, x1[i] - M)); ;
for (int i = 0; i <= q - 1; i++)
{
if (b * psi[i + 1] * (1 - x1[i] / M) >= 0)
u2[i] = A;
else
u2[i] = 0;
}
x2[0] = S0;
for (int i = 0; i <= q - 1; i++)
x2[i + 1] = x2[i] + h * f(x2[i], u2[i], alpha, b, M);
J2 = 0;
for (int i = 0; i <= q - 1; i++)
J2 -= x2[i] * h;
for (int i = 0; i <= q - 1; i++)
J2 += A_k * h * (Math.Pow(max(0, -x2[i]), 2) + Math.Pow(max(0, x2[i] - M), 2));
X = Math.Abs(x1[0] - x2[0]);
for (int i = 1; i <= q; i++)
if (X < Math.Abs(x1[i] - x2[i]))
X = Math.Abs(x1[i] - x2[i]);
for (int i = 0; i <= q; i++)
chart1.Series["x(t)"].Points.AddXY(t[i], x2[i]);
for (int i = 0; i <= q - 1; i++)
chart2.Series["u(t)"].Points.AddXY(t[i], u2[i]);
textBox12.Text = Convert.ToString(J2);
string[] row = new string[4];
row[0] = "q";
row[1] = "t";
row[2] = "x(t)";
row[3] = "u(t)";
dataGridView1.ColumnCount = 4;
dataGridView1.RowCount = 1;
dataGridView1.Rows.Add(row);
for (int i = 0; i <= q; i++)
{
row[0] = i.ToString();
row[1] = t[i].ToString();
row[2] = x1[i].ToString();
row[3] = "";
if (i != q) row[3] = u1[i].ToString();
dataGridView1.Rows.Add(row);
}
}
else
{
J1 = J2;
for (int i = 0; i <= q; i++)
x1[i] = x2[i];
for (int i = 0; i <= q - 1; i++)
u1[i] = u2[i];
A_k++;
goto label;
}
}
else
{
J1 = J2;
for (int i = 0; i <= q; i++)
x1[i] = x2[i];
for (int i = 0; i <= q - 1; i++)
u1[i] = u2[i];
A_k++;
goto label;
}
}
}
}