Advertisement
Guest User

DUPA

a guest
Apr 1st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Windows.Forms.DataVisualization.Charting;
  11.  
  12. namespace Koniecznav3
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void Oblicz_Click(object sender, EventArgs e)
  22.         {
  23.             double xy = double.Parse(xxTB.Text);
  24.             double wynik = 0;
  25.  
  26.             string s = xTB.Text;
  27.             String[] split = s.Split(' ');
  28.             double[] TabX = new double[split.Length];
  29.             for (int i = 0; i < split.Length; i++)
  30.             {
  31.                 TabX[i] = double.Parse(split[i]);
  32.             }
  33.  
  34.             string s2 = yTB.Text;
  35.             String[] split2 = s2.Split(' ');
  36.             double[] TabY = new double[split2.Length];
  37.             for (int i = 0; i < split2.Length; i++)
  38.             {
  39.                 TabY[i] = double.Parse(split2[i]);
  40.             }
  41.            
  42.             for(int i = 0; i < TabY.Length; i++)
  43.             {
  44.                 wynik += L(TabX, xy, i) * TabY[i];
  45.             }
  46.             wynikTB.Text = wynik.ToString();
  47.         }
  48.  
  49.         public double L(double [] x ,double xy, int indexL)
  50.         {
  51.             double wynik = 1;
  52.             for(int i = 0; i < x.Length; i++)
  53.             {
  54.                 if (i != indexL)
  55.                 {                
  56.                     wynik =wynik* ((xy - x[i]) / (x[indexL] - x[i]));
  57.                 }
  58.             }    
  59.             return wynik;
  60.         }
  61.  
  62.         private void rysuj_Click(object sender, EventArgs e)
  63.         {
  64.             double xy = double.Parse(xxTB.Text);
  65.  
  66.             string s = xTB.Text;
  67.             String[] split = s.Split(' ');
  68.             double[] TabX = new double[split.Length];
  69.             for (int i = 0; i < split.Length; i++)
  70.             {
  71.                 TabX[i] = double.Parse(split[i]);
  72.             }
  73.  
  74.             string s2 = yTB.Text;
  75.             String[] split2 = s2.Split(' ');
  76.             double[] TabY = new double[split2.Length];
  77.             for (int i = 0; i < split2.Length; i++)
  78.             {
  79.                 TabY[i] = double.Parse(split2[i]);
  80.             }
  81.  
  82.             var chart = chart1.ChartAreas[0];
  83.             chart.AxisX.LabelStyle.Format = "";
  84.             chart.AxisY.LabelStyle.Format = "";
  85.             chart.AxisX.LabelStyle.IsEndLabelVisible = true;
  86.            
  87.             chart1.Series.Add("f(x)");
  88.             chart1.Series["f(x)"].ChartType = SeriesChartType.Line;
  89.             chart1.Series["f(x)"].Color = Color.Red;
  90.             chart1.Series[0].IsVisibleInLegend = false;
  91.  
  92.             double wartoscX, wartoscY;
  93.             for (wartoscX = TabX[0]; wartoscX <= TabX[TabX.Length - 1]; wartoscX += 0.01)
  94.             {
  95.                 wartoscY = 0;
  96.                 for (int i = 0; i < TabX.Length; i++)
  97.                 {
  98.                     wartoscY += L(TabX, wartoscX, i) * TabY[i];
  99.                 }
  100.                 chart1.Series["f(x)"].Points.AddXY(wartoscX, wartoscY);
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement