<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>how to &#187; C #</title>
	<atom:link href="http://www.neteyaz.com/category/programming/csharp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.neteyaz.com</link>
	<description>linux and open source tips</description>
	<lastBuildDate>Mon, 23 May 2011 08:47:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Graph Drawing With Newton and Lagrange Interpolation Methods in C#</title>
		<link>http://www.neteyaz.com/graph-drawing-with-newton-and-lagrange-interpolation-methods-in-c</link>
		<comments>http://www.neteyaz.com/graph-drawing-with-newton-and-lagrange-interpolation-methods-in-c#comments</comments>
		<pubDate>Thu, 12 Nov 2009 09:08:42 +0000</pubDate>
		<dc:creator>TaZ</dc:creator>
				<category><![CDATA[C #]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Graph Drawing with C#]]></category>
		<category><![CDATA[Interpolation Methods]]></category>
		<category><![CDATA[Lagrange Interpolation Method]]></category>
		<category><![CDATA[Newton Interpolation Method]]></category>
		<category><![CDATA[Polynomial]]></category>

		<guid isPermaLink="false">http://www.neteyaz.com/?p=9</guid>
		<description><![CDATA[This code for drawing a points array&#8217;s graph with lagrange or Newton Interpolation method.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace lagrange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int x, i = 0, n, flag = 0,lagrange_flag=0,newton_flag=0;
public static int y;
public static Point[] point_array = new Point[30];
public static string name;

private void panel1_Paint(object sender, PaintEventArgs [...]]]></description>
			<content:encoded><![CDATA[<p>This code for drawing a points array&#8217;s graph with lagrange or Newton Interpolation method.<br />
<span id="more-9"></span></p>
<div id="attachment_43" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-43" title="Interpolation methods" src="http://www.neteyaz.com/files/2009/11/adsız-300x217.jpg" alt="Drawing graph with interpolation methods" width="300" height="217" /><p class="wp-caption-text">Drawing graph with interpolation methods</p></div>
<pre>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace lagrange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int x, i = 0, n, flag = 0,lagrange_flag=0,newton_flag=0;
public static int y;
public static Point[] point_array = new Point[30];
public static string name;

private void panel1_Paint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Brushes.Blue);
pen.Width = 1;
Pen k = new Pen(Brushes.Red);
k.Width = 2;
if (flag &gt; 0)
{
Point[] point_array2 = new Point[i];
Point[] point_array3 = new Point[i];
for (int s = 0; s &lt; i; s++)
{
point_array2[s].X = point_array3[s].X = point_array[s].X;
point_array2[s].Y = point_array3[s].Y = point_array[s].Y;
}
for (int h = 0; h &lt; i; h++)
{
e.Graphics.DrawRectangle(pen, point_array[h].X, point_array[h].Y, 4, 4);

}
/*
#################################################################
#               Lagrange's İnterpolation                        #
#                                                               #
#################################################################
*/
if (lagrange_flag == 1)
{

for (float d = point_array2[0].X; d &lt; point_array2[point_array2.Length - 1].X; d += 0.05f)
{
float fx = 0;
for (int v = 0; v &lt; point_array2.Length; v++)
{
float lg = 1;
for (int y = 0; y &lt; point_array2.Length; y++)
{
if (v != y)
{
lg *= (d - point_array2[y].X) / (point_array2[v].X - point_array2[y].X);
}
}
fx += lg * point_array2[v].Y;
}
e.Graphics.DrawEllipse(k, d, fx, 1f, 1f);
}
}
/*
#################################################################
#                  Newton's İnterpolation                       #
#                                                               #
#################################################################
*/
if (newton_flag==1)
{

float carpim = 1;
for (float d = point_array2[0].X; d &lt; point_array2[point_array2.Length - 1].X; d += 0.05f)
{
float fx = 0;
float[,] dizi2 = new float[i, i];
for (int l = 0; l &lt; point_array2.Length; l++)
{
dizi2[0,Convert.ToInt32( l)] = point_array2[l].Y;
}
for (int v = 1; v &lt; point_array2.Length; v++)
{
for (int y = v; y &lt; point_array2.Length; y++)
{
dizi2[v, y] = (float)(dizi2[v - 1, y]-dizi2[v - 1, y - 1]  ) / (point_array2[y].X - point_array2[y - v].X);

}
} int t;
for (int o = 0; o &lt; point_array2.Length; o++)
{
for (t = 0; t &lt; o; t++)
{
carpim*=( d-point_array2[t].X);

}
carpim *= dizi2[o, o];
fx += carpim;
carpim = 1;
}
e.Graphics.DrawEllipse(k, d, fx, 1f, 1f);
}
}
}
if (flag == 0)
{
for (int h = 0; h &lt; i; h++)
{
Font newfont = new Font("Verdana", 6);

PointF points = new PointF(point_array[h].X, point_array[h].Y);
string cumle = "{" + point_array[h].X + " , "  + point_array[h].Y + "}";
e.Graphics.DrawRectangle(pen, point_array[h].X, point_array[h].Y, 4, 4);
e.Graphics.DrawString(cumle, newfont, Brushes.Black, points);
}
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{

x = e.X;
y = e.Y;
point_array[i].X = e.X;
point_array[i].Y = e.Y;
n = i + 1;
listBox1.Items.Add(n + ")  " + x + "       " + y);
i++;

if (flag &gt; 0)
{
int l;
int p;
for (int j = 0; j &lt; i - 1; j++)
{
if (point_array[j].X &gt; point_array[j + 1].X)
{
l = point_array[j + 1].X;
p = point_array[j + 1].Y;
point_array[j + 1].X = point_array[j].X;
point_array[j + 1].Y = point_array[j].Y;
point_array[j].X = l;
point_array[j].Y = p;
j = -1;
}
}
listBox1.Items.Clear();
for (int t = 0; t &lt; i; t++)
{

listBox1.Items.Add(t + 1 + ")  " + point_array[t].X + "       " + point_array[t].Y);
}

this.Refresh();
}

this.Refresh();

}

private void button3_Click(object sender, EventArgs e)
{

lagrange_flag = 1;
newton_flag = 0;
int b;
int c;
for (int j = 0; j &lt; i - 1; j++)
{
if (point_array[j].X &gt; point_array[j + 1].X)
{
b = point_array[j + 1].X;
c = point_array[j + 1].Y;
point_array[j + 1].X = point_array[j].X;
point_array[j + 1].Y = point_array[j].Y;
point_array[j].X = b;
point_array[j].Y = c;
j = -1;
}
}
listBox1.Items.Clear();
for (int t = 0; t &lt; i; t++)
{

listBox1.Items.Add(t + 1 + ")  " + point_array[t].X + "       " + point_array[t].Y);
}
flag++;
this.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
int b;
int c;
newton_flag = 1;
lagrange_flag = 0;
for (int j = 0; j &lt; i - 1; j++)
{
if (point_array[j].X &gt; point_array[j + 1].X)
{
b = point_array[j + 1].X;
c = point_array[j + 1].Y;
point_array[j + 1].X = point_array[j].X;
point_array[j + 1].Y = point_array[j].Y;
point_array[j].X = b;
point_array[j].Y = c;
j = -1;
}
}
listBox1.Items.Clear();
for (int t = 0; t &lt; i; t++)
{

listBox1.Items.Add(t + 1 + ")  " + point_array[t].X + "       " + point_array[t].Y);
}

flag++;

this.Refresh();
}

private void button4_Click(object sender, EventArgs e)
{
i = 0; flag = 0; lagrange_flag = 0; newton_flag = 0;
listBox1.Items.Clear();

for (int s = 0; s &lt; point_array.Length; s++)
{
point_array[s].X = 0;
point_array[s].Y = 0;
}
this.Refresh();
}

private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.neteyaz.com/graph-drawing-with-newton-and-lagrange-interpolation-methods-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

