Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.DataVisualization.Charting;
- namespace Koniecznav3
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Oblicz_Click(object sender, EventArgs e)
- {
- double xy = double.Parse(xxTB.Text);
- double wynik = 0;
- string s = xTB.Text;
- String[] split = s.Split(' ');
- double[] TabX = new double[split.Length];
- for (int i = 0; i < split.Length; i++)
- {
- TabX[i] = double.Parse(split[i]);
- }
- string s2 = yTB.Text;
- String[] split2 = s2.Split(' ');
- double[] TabY = new double[split2.Length];
- for (int i = 0; i < split2.Length; i++)
- {
- TabY[i] = double.Parse(split2[i]);
- }
- for(int i = 0; i < TabY.Length; i++)
- {
- wynik += L(TabX, xy, i) * TabY[i];
- }
- wynikTB.Text = wynik.ToString();
- }
- public double L(double [] x ,double xy, int indexL)
- {
- double wynik = 1;
- for(int i = 0; i < x.Length; i++)
- {
- if (i != indexL)
- {
- wynik =wynik* ((xy - x[i]) / (x[indexL] - x[i]));
- }
- }
- return wynik;
- }
- private void rysuj_Click(object sender, EventArgs e)
- {
- double xy = double.Parse(xxTB.Text);
- string s = xTB.Text;
- String[] split = s.Split(' ');
- double[] TabX = new double[split.Length];
- for (int i = 0; i < split.Length; i++)
- {
- TabX[i] = double.Parse(split[i]);
- }
- string s2 = yTB.Text;
- String[] split2 = s2.Split(' ');
- double[] TabY = new double[split2.Length];
- for (int i = 0; i < split2.Length; i++)
- {
- TabY[i] = double.Parse(split2[i]);
- }
- var chart = chart1.ChartAreas[0];
- chart.AxisX.LabelStyle.Format = "";
- chart.AxisY.LabelStyle.Format = "";
- chart.AxisX.LabelStyle.IsEndLabelVisible = true;
- chart1.Series.Add("f(x)");
- chart1.Series["f(x)"].ChartType = SeriesChartType.Line;
- chart1.Series["f(x)"].Color = Color.Red;
- chart1.Series[0].IsVisibleInLegend = false;
- double wartoscX, wartoscY;
- for (wartoscX = TabX[0]; wartoscX <= TabX[TabX.Length - 1]; wartoscX += 0.01)
- {
- wartoscY = 0;
- for (int i = 0; i < TabX.Length; i++)
- {
- wartoscY += L(TabX, wartoscX, i) * TabY[i];
- }
- chart1.Series["f(x)"].Points.AddXY(wartoscX, wartoscY);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement