Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.6 kB
3
Indexable
Never
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            chart1.Series.Add("cos");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double PI = Math.PI;
            double Xmin = double.Parse(textBoxXmin.Text);
            double Xmax = double.Parse(textBoxXmax.Text);
            double degrees = double.Parse(textBoxDegrees.Text);

            // int Step = int.Parse(textBoxStep.Text);
            double Step = 0.5;

            double radians = degrees * PI / 180;
            double a = double.Parse(textBoxA.Text);

            // Количество точек графика
            int points = (int)Math.Ceiling((Xmax - Xmin) / Step + 1);

            double[] x = new double[points];

            double[] sin = new double[points];
            double[] cos = new double[points];
            double[] sh = new double[points];


            for (int i = 0; i < points; i++)
            {
                x[i] = Xmin + Step * i;

                sin[i] = Math.Sin(radians * x[i] + a); // sin(kx + a)
                cos[i] = Math.Cos(radians * x[i] + a); // cos(kx + a)

                sh[i] = Sh(x[i]);
            }

            chart1.ChartAreas[0].AxisX.Minimum = Xmin;
            chart1.ChartAreas[0].AxisX.Maximum = Xmax;
            chart1.ChartAreas[0].AxisX.MajorGrid.Interval = Step;

            chart1.ChartAreas[0].AxisY.Minimum = -20;
            chart1.ChartAreas[0].AxisY.Maximum = 20;

            // sin(kx + a)
            chart1.Series[0].Points.DataBindXY(x, sin);
            chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

            // cos(kx + a)
            chart1.Series[1].Points.DataBindXY(x, cos);
            chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

            chart1.Series[2].Points.DataBindXY(x, sh);
            chart1.Series[2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
        }

        //Гиперболический синус
        public double Sh(double x)
        {
            return (Math.Exp(x) - Math.Exp(-x)) / 2.0;
        }
    }
}