Программа, выводящая график степенной функции y = bx^a - C#
Формулировка задачи:
помогите написать такую программу,которая при нажатии на кнопку выводила бы график степенной функции такого плана y = bx^a
подскажите плиз
Решение задачи: «Программа, выводящая график степенной функции y = bx^a»
textual
Листинг программы
using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using System.Drawing; class Gr: Form { public Gr() { TableLayoutPanel layout = new TableLayoutPanel { Left = 10, Top = 10, ColumnCount = 3, RowCount = 2, AutoSize = true, Height = 50 }; layout.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 30F)); this.Controls.Add(layout); this.ALabel = new Label { Text = "A: ", Dock = DockStyle.Bottom }; this.BLabel = new Label { Text = "B:", Dock = DockStyle.Bottom }; layout.Controls.Add(this.ALabel, 0, 0); layout.Controls.Add(this.BLabel, 0, 1); this.AValue = new NumericUpDown { Minimum = -100, Maximum = 100, Dock = DockStyle.Bottom }; this.BValue = new NumericUpDown { Minimum = -100, Maximum = 100, Dock = DockStyle.Bottom }; layout.Controls.Add(this.AValue, 1, 0); layout.Controls.Add(this.BValue, 1, 1); this.CommandButton = new Button { Text = "Построить" }; layout.Controls.Add(this.CommandButton, 2, 1); Chart chart = new Chart { Left = 10, Top = layout.Bottom + 10, Width = this.ClientRectangle.Width - 20, Height = this.ClientRectangle.Height - 30 - layout.Height, Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top }; this.Controls.Add(chart); ChartArea chartArea = new ChartArea(); chart.ChartAreas.Add(chartArea); Series series = new Series(); chart.Series.Add(series); series.ChartType = SeriesChartType.Spline; series.Color = Color.Green; series.BorderWidth = 4; chart.Titles.Add("title"); chart.Titles[0].Text = "График функции"; chart.Titles[0].Font = new Font(this.Font.FontFamily, 14F, FontStyle.Regular); this.CommandButton.Click += delegate { series.Points.Clear(); for (int i = -50; i <= 50; i++) { series.Points.AddXY((double)i, Math.Pow((double)this.BValue.Value * i, (double)this.AValue.Value)); } }; } public Label ALabel { get; set; } public Label BLabel { get; set; } public Button CommandButton { get; set; } public NumericUpDown AValue { get; set; } public NumericUpDown BValue { get; set; } public static void Main(string[] argv) { Application.EnableVisualStyles(); Application.Run(new Gr()); } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д