using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace job._1
{
public partial class exp1_Lag : Form
{
public exp1_Lag()
{
InitializeComponent();
}
List<double> xn=null;
List<double> yn=null;
public void txtxy_TextChanged(object sender, EventArgs e)
{
string str = txtInput.Text;
int i1 = 0, i2 = 0;
while (str[i1] != *\0*)
{
string str0 = null;
if (str[i1] == *(*)
{
while (str[i1 + 1] != *,*)
{
str0 += str[i1 + 1];
i1++;
}
xn[i2] = double.Parse(str0);
str0 = null;
while (str[i1 + 1] != *)*)
{
str0 += str[i1 + 1];
i1++;
}
yn[i2] = double.Parse(str0);
i2++;
}
}
}
public void button1_Click(object sender, EventArgs e)
{
int n=int.Parse(txtn.Text);
int sum = 1;
double x = double.Parse(txtque.Text);
double tmp = 1, fx=0;
for (int i = 1; i <= n; i++)
{
sum *= i;
}
for (int i = 0; i <= sum; i++)
{
for (int j = 0; j <= n; j++)
{
if (j != i)
{
tmp *= (x - xn[j]) / (xn[i] - xn[j]);
}
}
fx+=tmp*yn[i];
}
lblans.Text = fx.ToString();
}
}
}
***********************************************************************************
***********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace job._1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new exp1_Lag());
}
}
}
**********************************************************************************
*************************************************************************************
实现拉格朗日插值函数算法
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace job._1
{
public partial class exp1_Lag : Form
{
public exp1_Lag()
{
InitializeComponent();
}
List<double> xn=null;
List<double> yn=null;
public void txtxy_TextChanged(object sender, EventArgs e)
{
string str = txtInput.Text;
int i1 = 0, i2 = 0;
while (str[i1] != *\0*)
{
string str0 = null;
if (str[i1] == *(*)
{
while (str[i1 + 1] != *,*)
{
str0 += str[i1 + 1];
i1++;
}
xn[i2] = double.Parse(str0);
str0 = null;
while (str[i1 + 1] != *)*)
{
str0 += str[i1 + 1];
i1++;
}
yn[i2] = double.Parse(str0);
i2++;
}
}
}
public void button1_Click(object sender, EventArgs e)
{
int n=int.Parse(txtn.Text);
int sum = 1;
double x = double.Parse(txtque.Text);
double tmp = 1, fx=0;
for (int i = 1; i <= n; i++)
{
sum *= i;
}
for (int i = 0; i <= sum; i++)
{
for (int j = 0; j <= n; j++)
{
if (j != i)
{
tmp *= (x - xn[j]) / (xn[i] - xn[j]);
}
}
fx+=tmp*yn[i];
}
lblans.Text = fx.ToString();
}
}
}
***********************************************************************************
***********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace job._1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new exp1_Lag());
}
}
}
**********************************************************************************
*************************************************************************************
实现拉格朗日插值函数算法