!
.

-

Xaml
Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NelderMid"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"x:Class="NelderMid.MainWindow"
mc:Ignorable="d"
Title="-"Height="441.3"Width="1040.047">
Grid>
Grid.ColumnDefinitions>
ColumnDefinitionWidth="177*"/>
ColumnDefinitionWidth="856*"/>
Grid.ColumnDefinitions>


GroupBoxx:Name="groupBox"Header=""HorizontalAlignment="Left"Margin="10,10,0,0"VerticalAlignment="Top"Height="382"Width="465"Grid.ColumnSpan="2">
GridMargin="-8,0,8,0">
Labelx:Name="label"Content=""HorizontalAlignment="Left"Margin="173,0,0,0"VerticalAlignment="Top"FontFamily="Georgia"FontSize="16"FontStyle="Italic"/>
Labelx:Name="label_Copy"Content="(x1-10)^2+(x2-12)^2+(x1-10)(x2-12)"HorizontalAlignment="Left"Margin="17,28,0,0"VerticalAlignment="Top"FontFamily="Georgia"FontSize="24"RenderTransformOrigin="0.474,1.893"Width="412"Height="47"/>
Labelx:Name="label_Copy1"Content="alpha=1 beta=0.5 gamma=2 "HorizontalAlignment="Left"Margin="95,69,0,0"VerticalAlignment="Top"FontFamily="Georgia"FontSize="16"RenderTransformOrigin="0.474,1.893"/>
TextBoxx:Name="t2"HorizontalAlignment="Left"Height="228"Margin="10,124,0,-20"TextWrapping="Wrap"VerticalAlignment="Top"Width="120"VerticalScrollBarVisibility="Auto"/>
Labelx:Name="label1"Content=""HorizontalAlignment="Left"Margin="43,97,0,0"VerticalAlignment="Top"FontFamily="Georgia"FontSize="14.667"/>
Labelx:Name="label1_Copy"Content=""HorizontalAlignment="Left"Margin="248,97,0,0"VerticalAlignment="Top"FontFamily="Georgia"FontSize="14.667"/>
TextBoxx:Name="t"HorizontalAlignment="Left"Height="228"Margin="147,124,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Width="296"VerticalScrollBarVisibility="Auto"/>
TextBoxx:Name="n1"HorizontalAlignment="Left"Height="21"Margin="62,37,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Width="25"/>
TextBoxx:Name="n2"HorizontalAlignment="Left"Height="21"Margin="183,37,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Width="26"/>
TextBoxx:Name="n3"HorizontalAlignment="Left"Height="22"Margin="303,37,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Width="25"/>
TextBoxx:Name="n4"HorizontalAlignment="Left"Height="22"Margin="381,37,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Width="23"/>
Grid>
GroupBox>
GroupBoxx:Name="groupBox1"Header=""Margin="303,10,18,0"VerticalAlignment="Top"Height="382"Grid.Column="1">
Grid>
Buttonx:Name="button"Content=""HorizontalAlignment="Left"Margin="194,14,0,0"VerticalAlignment="Top"Width="133"Click="button_Click"/>


chartingToolkit:Chartx:Name="chart1"HorizontalAlignment="Left"Margin="10,51,0,0"Title="-"VerticalAlignment="Top"Height="299"Width="501">
chartingToolkit:Chart.Axes>
chartingToolkit:LinearAxisName="axX"SeriesHost="{x:Null}"Orientation="X"/>
chartingToolkit:LinearAxisName="axY"SeriesHost="{x:Null}"Orientation="Y"/>
chartingToolkit:Chart.Axes>
chartingToolkit:Chart.DataContext>
PointCollection>1,10 2,20 3,30 4,40PointCollection>
chartingToolkit:Chart.DataContext>
chartingToolkit:Chart>
Grid>
GroupBox>

Grid>
Window>

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Controls.DataVisualization.Charting;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;

namespaceNelderMid
{
///
/// MainWindow.xaml
///
public partial class MainWindow : Window
{
publicMainWindow()
{
InitializeComponent();
}

double al = 1, b = 0.5, g = 2;
const double eps=1,T=6;
constint n = 2,m=n+1;
double[,] a = new double[m, n];
double[] F = new double[m];
double center;
double[,] C = new double[1, n];
double[,] R = new double[1, n];
double[,] E = new double[1, n];
double[,] S = new double[1, n];
voidinit()
{
for (int i = 0; i
{
for (int j = 0; j
{
if (i == 0) a[i, j] = 0;
else if (i == j + 1)
a[i, j] = (T / (n * Math.Sqrt(2))) * (Math.Sqrt(m) - 1 + n);
else
a[i, j] = (T / (n * Math.Sqrt(2))) * (Math.Sqrt(m) - 1);
}
}

}

Random randomGen = new Random();
voidgetGraph(double[,] ma, string nazv)
{

t2.Text += " "+num+" : \n";
Color gColor = gColor = System.Windows.Media.Color.FromRgb(Convert.ToByte(randomGen.Next(255)), Convert.ToByte(randomGen.Next(255)), Convert.ToByte(randomGen.Next(255)));
Brush b = new SolidColorBrush(gColor);
int j = 0;
while (j
{
if (j > 0) nazv = "";
List>MyValue = new List>();
MyValue.Add(new KeyValuePair(ma[j, 0], ma[j, 1]));
j++;
if (j == m)
MyValue.Add(new KeyValuePair(ma[0, 0], ma[0, 1]));
else
MyValue.Add(new KeyValuePair(ma[j, 0], ma[j, 1]));
showChart(MyValue, nazv, b);
}

for (int i = 0; i
{
t2.Text += Math.Round(a[i, 0], 2) + " \t" + Math.Round(a[i, 1], 2)+"\n";
}
num++;
t2.Text += "\n";

}

doublefunc(double[,] mas, int i)
{
double res = Math.Pow(mas[i, 0] - Convert.ToInt32(n1.Text), 2) + Math.Pow(mas[i, 1] - Convert.ToInt32(n2.Text), 2) + (mas[i, 0] - Convert.ToInt32(n3.Text)) * (mas[i, 1] - Convert.ToInt32(n4.Text));
return res;
}

public void replace(int H)
{
for (int j = 0; j
{
a[H, j] = R[0, j];
}
t.Text += "\n ";
}

private void showChart(List>valueList, string title,BrushgColor)
{
System.Windows.Controls.DataVisualization.Charting.LineSeries lineSeries1 = new System.Windows.Controls.DataVisualization.Charting.LineSeries();
lineSeries1.Title = title;
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";

Style style = new Style(typeof(LineDataPoint));
style.Setters.Add(new Setter(LineDataPoint.BackgroundProperty, gColor));
if (title == "")
style.Setters.Add(new Setter(LineDataPoint.VisibilityProperty, Visibility.Hidden));
lineSeries1.DataPointStyle = style;
lineSeries1.ItemsSource = valueList;
chart1.Series.Add(lineSeries1);
}

intnum = 1;

private void button_Click(object sender, RoutedEventArgs e)
{
num = 1;
init();
t.Clear();
t2.Clear();
double z = 1000;
chart1.Series.Clear();
getGraph(a, " ");
while (z >eps)
{
//
t.Text += " : \n";
for (int i = 0; i
{
F = func(a, i);
t.Text += "F[" + (i + 1) + "]=" + Math.Round(F, 2) + " ";
}
t.Text += "\n";
//
t.Text += " : \n";
int H = 0, L = 0, G = 0;
for (int i = 1; i
{
if (F > F[H])
{
G = H;
H = i;
}
else if (F }
t.Text += "max = " + Math.Round(F[H], 2) + " H=" + (H + 1) + " min = " + Math.Round(F[L], 2) + " L=" + (L + 1) + "\n";
t.Text += " : \n";
//
double sum;
for (int j = 0; j
{
sum = 0;
for (int i = 0; i
C[0, j] = (1.0 / n) * (sum - a[H, j]);
t.Text += "C[" + (j + 1) + "]=" + Math.Round(C[0, j], 2) + " ";
}
center = func(C, 0);
t.Text += " " + Math.Round(center, 2) + "\n&q...