<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Mike Palermo&#039;s Blog</title>
	<atom:link href="http://mpalermo1220.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mpalermo1220.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 22 Dec 2009 07:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mpalermo1220.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Mike Palermo&#039;s Blog</title>
		<link>http://mpalermo1220.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mpalermo1220.wordpress.com/osd.xml" title="Mike Palermo&#039;s Blog" />
	<atom:link rel='hub' href='http://mpalermo1220.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Numerical Integration</title>
		<link>http://mpalermo1220.wordpress.com/2009/12/22/numerical-integration/</link>
		<comments>http://mpalermo1220.wordpress.com/2009/12/22/numerical-integration/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 07:07:28 +0000</pubDate>
		<dc:creator>mpalermo1220</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mpalermo1220.wordpress.com/?p=61</guid>
		<description><![CDATA[Quadrature The benefit of using a type of quadrature is that it allows you to solve rather difficult integrations.  This is done by finding a polynomial interpolation of the given function then integrating the resulting polynomial.  It makes difficult integrations possible, well at least they are usually a fairly good estimation. Rectangle Method (for integration) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=61&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1><span style="text-decoration:underline;">Quadrature</span></h1>
<p>The benefit of using a type of quadrature is that it allows you to solve rather difficult integrations.  This is done by finding a polynomial interpolation of the given function then integrating the resulting polynomial.  It makes difficult integrations possible, well at least they are usually a fairly good estimation.</p>
<h1><span style="text-decoration:underline;">Rectangle Method (for integration)</span></h1>
<p>If you are unable to determine the polynomial interpolation of a function, there is an alternative.  You can use something called the Rectangle Method.  What it does is it divides the graph of the equation into many rectangles.  There are three different types of rectangles that you can use.  They are the right hand, left hand, and midpoint rectangles.  If we let (a,b) be the limits of integration and n as the number of rectangles over the interval, the rectangles have a width of:  Δ = (<em>b</em> − <em>a</em>) / <em>n</em>.  Let us assume x<sub>1</sub> and x<sub>2</sub> make up a sub-interval of (a,b), then the heights of the rectangles are based on what type of rectangle you are using:</p>
<p>Height of Rectangles</p>
<ul>
<li>Left Hand : Top left corner of rectangle, h=f(x<sub>1</sub>)</li>
<li>Right Hand : Top right corner of rectangle, h=f(x<sub>2</sub>)</li>
<li>Midpoint : h=f(x<sub>2</sub> + x<sub>1</sub> / 2)</li>
</ul>
<p>For an easy example, suppose you have a rectangle whose width is from x=1 to x=1.1, then the heights of the rectangles would be:</p>
<ul>
<li>LH : h=f(1)</li>
<li>RH : h=f(1.1)</li>
<li>MP : h=f(1.1+1/2)=f(2.1/2)=f(1.05)</li>
</ul>
<p>Here are some examples of what a function looks like broken up into rectangles (from Wikipedia):</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/13.jpg"><img class="aligncenter size-medium wp-image-62" title="13" src="http://mpalermo1220.files.wordpress.com/2009/12/13.jpg?w=300&#038;h=136" alt="" width="300" height="136" /></a>Now that we have the height and width of the rectangle, we know the area of the rectangle is HxW.  We repeat each step to find the area of every other rectangle to find an approximation of the definite integral.  Our approximation becomes more and more accurate when we increase the total number of sub-intervals.</p>
<p>Here is a code from Wikipedia that utilizes the midpoint rectangles:</p>
<pre>function [I] = riemann(f,a,b,n)
%f=name of function, a=start value, b=end value, n=number of
%iterations
%made by Carolina, Niklas, Benjamin and Damiano
h=(b-a)./n;
S=f(a);
i=1:1:n-1;
x=a+h.*i;
y=f(x);
S=S+sum(y);
S=S+f(b);
F=h.*S;
end
</pre>
<h1><span style="text-decoration:underline;">Trapezoidal Rule</span></h1>
<p>Similar and much more accurate than the midpoint rule, the trapezoidal rule breaks the function into trapezoids (how obvious was that?).  Much like the rectangle rules, the trapezoidal rules divides the interval into smaller sub-intervals.  The area of each of these trapezoids are not that easy to predict, so we can utilize the formula from Wikipedia:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/15.jpg"><img class="aligncenter size-medium wp-image-64" title="15" src="http://mpalermo1220.files.wordpress.com/2009/12/15.jpg?w=367&#038;h=24" alt="" width="367" height="24" /></a><a href="http://mpalermo1220.files.wordpress.com/2009/12/16.jpg"><img class="aligncenter size-full wp-image-65" title="16" src="http://mpalermo1220.files.wordpress.com/2009/12/16.jpg?w=201&#038;h=621" alt="" width="201" height="621" /></a></p>
<p>Here is a coding for the composite Trapezoidal Rule:</p>
<pre>function [F] = trap(f,a,b,n)
%f=name of function, a=start value, b=end value, n=number of
%iterations
%made by Carolina, Niklas, Benjamin and Damiano
h=(b-a)./n;
S=f(a);
i=1:1:n-1;
x=a+h.*i;
y=f(x);
S=S+2.*sum(y);
S=S+f(b);
F=h.*S./2;
F;
end
</pre>
<h1><span style="text-decoration:underline;">Simpson&#8217;s Rule</span></h1>
<p>Here is another example of how to approximate an integral.  It is conveniently equal to the average of the midpoint and trapezoidal rules.  If you do not feel like calculating both approximations, you can just use the equation:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/17.jpg"><img class="aligncenter size-full wp-image-66" title="17" src="http://mpalermo1220.files.wordpress.com/2009/12/17.jpg?w=414&#038;h=51" alt="" width="414" height="51" /></a>Simpson&#8217;s Rule is by far the most accurate approximation besides calculating the definite integral itself.  Below is a code for the Simpson&#8217;s Rule:</p>
<pre>function [P] = simpson(f,a,b,n)
%f=name of function, a=start value, b=end value, n=number of
%iterations
h=(b-a)/n;
S=f(a);
i=1:2:n-1;
x=a+h.*i;
y=f(x);
S=S+4*sum(y);
i=2:2:n-2;
x=a+h.*i;
y=f(x);
S=S+2*sum(y);
S=S+f(b);
P=h*S/3;
end
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mpalermo1220.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mpalermo1220.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mpalermo1220.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=61&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mpalermo1220.wordpress.com/2009/12/22/numerical-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dc31f6f658dd224665bdeb57d1acef9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mpalermo1220</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/13.jpg?w=300" medium="image">
			<media:title type="html">13</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/15.jpg?w=300" medium="image">
			<media:title type="html">15</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/16.jpg" medium="image">
			<media:title type="html">16</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/17.jpg" medium="image">
			<media:title type="html">17</media:title>
		</media:content>
	</item>
		<item>
		<title>Polynomial Interpolation</title>
		<link>http://mpalermo1220.wordpress.com/2009/12/22/polynomial-interpolation/</link>
		<comments>http://mpalermo1220.wordpress.com/2009/12/22/polynomial-interpolation/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 05:47:59 +0000</pubDate>
		<dc:creator>mpalermo1220</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mpalermo1220.wordpress.com/?p=40</guid>
		<description><![CDATA[Beginning polynomial interpolation involves a basic understand of what its purpose is.  Say for example we have a bunch of points on a graph.  We would use polynomial interpolation to determine the equation that fits all the points.  The equation would be in the form of a polynomial equation: The objective of polynomial interpolation is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=40&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Beginning polynomial interpolation involves a basic understand of what its purpose is.  Say for example we have a bunch of points on a graph.  We would use polynomial interpolation to determine the equation that fits all the points.  The equation would be in the form of a polynomial equation:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/5.jpg"><img class="aligncenter size-medium wp-image-41" title="5" src="http://mpalermo1220.files.wordpress.com/2009/12/5.jpg?w=300&#038;h=14" alt="" width="300" height="14" /></a>The objective of polynomial interpolation is to determine the coefficients of this polynomial.  There are several methods to finding such coefficients.</p>
<h1><span style="text-decoration:underline;">Vandermonde Matrix</span></h1>
<p>The first method is to use a special type matrix called a Vandermonde Matrix.  We begin by determining the set of points as {(x<sub>0</sub>, f(x<sub>0</sub>)), (x<sub>1</sub>, f(x<sub>1</sub>)), (x<sub>2</sub>, f(x<sub>2</sub>)),&#8230;, (x<sub>n+1</sub>, f(x<sub>n+1</sub>))}.  From these points, we set up the system of equations:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/6.jpg"><img class="aligncenter size-medium wp-image-44" title="6" src="http://mpalermo1220.files.wordpress.com/2009/12/6.jpg?w=300&#038;h=114" alt="" width="300" height="114" /></a>We can now transform this system of equations into a matrix form:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/7.jpg"><img class="aligncenter size-medium wp-image-45" title="7" src="http://mpalermo1220.files.wordpress.com/2009/12/7.jpg?w=300&#038;h=110" alt="" width="300" height="110" /></a>From here, it is easy to type the matrix into Matlab and allow the program to find the inverse of the Vandermonde Matrix.  Unfortunately, with large values of n, the matrix becomes closer and closer to being singular which is something Matlab has trouble with.  So if n is large, we have to try other methods of polynomial interpolation.</p>
<h1><span style="text-decoration:underline;">Lagrange Interpolation</span></h1>
<p>The best possible definition for Lagrange Interpolation comes straight from Wikipedia:</p>
<p><span style="color:#ff0000;">Given a set of <em>k</em> + 1 data points</span></p>
<dl>
<dd><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/5/c/e/5ce24ebcbf7048ddd470abb471aba925.png" alt="(x_0, y_0),\ldots,(x_k, y_k)" /></span></dd>
</dl>
<p><span style="color:#ff0000;">where no two <em>x</em><sub><em>j</em></sub> are the same, the <strong>interpolation polynomial in the Lagrange form</strong> is a linear combination</span></p>
<dl>
<dd><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/f/b/f/fbf1a1a198c3f3c6dc043ef8e18f8835.png" alt="L(x) := \sum_{j=0}^{k} y_j \ell_j(x)" /></span></dd>
</dl>
<p><span style="color:#ff0000;">of Lagrange basis polynomials</span></p>
<h1><span style="color:#ff0000;"> </span><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/8/b/6/8b6c54923053f5d804ac01ef2ada443f.png" alt="\ell_j(x) := \prod_{i=0,\, i\neq j}^{k} \frac{x-x_i}{x_j-x_i} = \frac{(x-x_0)}{(x_j-x_0)} \cdots \frac{(x-x_{j-1})}{(x_j-x_{j-1})} \frac{(x-x_{j+1})}{(x_j-x_{j+1})} \cdots \frac{(x-x_{k})}{(x_j-x_{k})}." width="457" height="38" /> (1)<br />
</span></h1>
<p><span style="color:#ff0000;">The function we are looking for has to be a polynomial function <em>L</em>(<em>x</em>) of degree less than or equal to <em>k</em> with</span></p>
<dl>
<dd><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/1/d/7/1d77fff2196a620b2c57c22974671b10.png" alt="L(x_j) = y_j \qquad j=0,\ldots,k" /></span></dd>
</dl>
<p><span style="color:#ff0000;">The Lagrange polynomial is a solution to the interpolation problem.  As can be seen</span></p>
<ol>
<li><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/3/7/c/37ca7ba34492aac83e9cda730482fd1f.png" alt="\ell_j(x)" /><span style="color:#000000;"> is a polynomial and has degree <em>k</em>.</span></span></li>
<li><span style="color:#ff0000;"><img src="http://upload.wikimedia.org/math/7/7/c/77c0a0d495ebe61829360c6340a92eb8.png" alt="\ell_i(x_j) = \delta_{ij},\quad 0 \leq i,j \leq k.\, " /></span></li>
</ol>
<p><span style="color:#ff0000;">Thus the function <em>L</em>(<em>x</em>) is a polynomial with degree at most <em>k</em> and</span></p>
<h1><span style="color:#ff0000;"> </span><img src="http://upload.wikimedia.org/math/6/b/f/6bffa185bea4c9e0156f8e438659c4b1.png" alt="L(x_i) = \sum_{j=0}^{k} y_j \ell_j(x_i) = \sum_{j=0}^{k} y_j \delta_{ji} = y_i." /> <span style="color:#ff0000;">(2)</span></h1>
<p>Let us use a very easy to understand example from Wikipedia just for a proof of concept.  The example calls for a polynomial interpolation of degree two (k=2) with the points:</p>
<p>x<sub>0</sub>=1 : f(x<sub>0</sub>)=1<br />
x<sub>1</sub>=2 : f(x<sub>1</sub>)=4<br />
x<sub>2</sub>=3 : f(x<sub>2</sub>)=9</p>
<p>Now let us use equation (1).  We do so by substituting in our values of x<sub>0</sub>, x<sub>1</sub>, x<sub>2</sub>.</p>
<p><img src="/Users/Mike/AppData/Local/Temp/moz-screenshot.png" alt="" /><a href="http://mpalermo1220.files.wordpress.com/2009/12/8.jpg"><img class="aligncenter size-medium wp-image-49" title="8" src="http://mpalermo1220.files.wordpress.com/2009/12/8.jpg?w=300&#038;h=138" alt="" width="300" height="138" /></a>From these answers, we can now use equation (2).</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/9.jpg"><img class="aligncenter size-medium wp-image-50" title="9" src="http://mpalermo1220.files.wordpress.com/2009/12/9.jpg?w=300&#038;h=42" alt="" width="300" height="42" /></a></p>
<p>For problems in which we need to find higher degree polynomials, we can rely on Matlab and the following code to figure out the coefficients of the polynomial (code courtesy of Kristie):</p>
<p>clear</p>
<p>N=20;</p>
<p>xp=linspace(0,1,N+1); %creates equidistant points</p>
<p>M=100;</p>
<p>x=linspace(0,1.2,M);</p>
<p>f=cos(20*xp); %function value</p>
<p>ff=cos(20*x);</p>
<p>for k=1:M  % each point x(k)</p>
<p>%Lagrange Interpolants</p>
<p>for j=1:N+1</p>
<p>L(j,k)=1;</p>
<p>for i=1:N+1</p>
<p>if i~=j</p>
<p>L(j,k)=L(j,k).*(x(k)-xp(i))/(xp(j)-xp(i));</p>
<p>end</p>
<p>end</p>
<p>end</p>
<p>end</p>
<p>P=L’*f’  % this does the summation which builds the interpolating polynomial</p>
<p>plot(x,P)</p>
<p>hold on</p>
<p>plot(x,ff,’r&#8217;)</p>
<p>plot(xp,f,’gp’)</p>
<h1><span style="text-decoration:underline;">Newtons Divided Differences</span></h1>
<p>Another method for interpolating polynomials is by using a method called Newtons Divided Differences.  Much like Lagrange Interpolation, we begin with a set of points.  The definition from Wikipedia for Newton Divided Differences:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/10.jpg"><img class="aligncenter size-full wp-image-52" title="10" src="http://mpalermo1220.files.wordpress.com/2009/12/10.jpg?w=170&#038;h=57" alt="" width="170" height="57" /></a>where</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/11.jpg"><img class="aligncenter size-full wp-image-53" title="11" src="http://mpalermo1220.files.wordpress.com/2009/12/11.jpg?w=142&#038;h=25" alt="" width="142" height="25" /></a> are called the divided differences and</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/12.jpg"><img class="aligncenter size-full wp-image-54" title="12" src="http://mpalermo1220.files.wordpress.com/2009/12/12.jpg?w=172&#038;h=55" alt="" width="172" height="55" /></a></p>
<p>called the Newton Basis Polynomial.</p>
<p>The key to knowing how divided differences work is to understand in what way they are recursive.  The first few divided differences can be mentioned as:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/14.jpg"><img class="aligncenter size-medium wp-image-55" title="14" src="http://mpalermo1220.files.wordpress.com/2009/12/14.jpg?w=366&#038;h=159" alt="" width="366" height="159" /></a></p>
<p>Here is an example code that shows how Newton Divided Differences interpolates the function f(x)=3x^2</p>
<p>clear all<br />
N=50;<br />
for j=1:N+1<br />
xp(j)=-cos(pi*(j-1)/N); %Chebyshev Gauss Labatto Points<br />
end<br />
M=50;<br />
x=linspace(-1.0,1.0,M);<br />
f=3.0.*xp.*xp;<br />
ff=3.0.*x.*x;</p>
<p>for j=1:N<br />
D(1,j)=(f(j+1)-f(j))/(xp(j+1)-xp(j));<br />
end<br />
%Newton divided differences<br />
for k=1:N-1<br />
for j=1:N-k<br />
D(k+1,j)=(D(k,j+1)-D(k,j))/(xp(j+k+1)-xp(j));<br />
end<br />
end<br />
%build the basis polynomials<br />
Pol(1,:)=(x(:)-xp(1));<br />
for j=1:N-1<br />
Pol(j+1,:)=Pol(j,:)&#8217;.*(x(:)-xp(j+1));<br />
end</p>
<p>P=f(1)+0.0*x;<br />
for j=1:N<br />
P(:)=P(:)+D(j,1)*Pol(j,:)&#8217;;<br />
end<br />
P&#8217;<br />
plot(x,P)<br />
hold on<br />
plot(x,ff,&#8217;bp&#8217;)<br />
plot(xp,f,&#8217;gp&#8217;)</p>
<h1><span style="text-decoration:underline;">Conclusion</span></h1>
<p>Polynomial interpolation is a tricky subject to cover because there are a couple methods that are straight forward in finding the coefficients for the polynomials, such as the Vandermonde Matrix and Lagrange Interpolation.  But unlike those two, Newton Divided differences is a little bit trickier to understand.  From the code I am using, it seems that Newton Divided Differences just gives you a bunch of points.  The Vandermonde Matrix is quite easy to use and understand, but unfortunately it becomes an obscure method with an increased number of points.  Overall, I feel like Lagrange Interpolation is the most effective method of polynomial interpolation.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mpalermo1220.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mpalermo1220.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mpalermo1220.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=40&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mpalermo1220.wordpress.com/2009/12/22/polynomial-interpolation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dc31f6f658dd224665bdeb57d1acef9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mpalermo1220</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/5.jpg?w=300" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/6.jpg?w=300" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/7.jpg?w=300" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/5/c/e/5ce24ebcbf7048ddd470abb471aba925.png" medium="image">
			<media:title type="html">(x_0, y_0),\ldots,(x_k, y_k)</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/f/b/f/fbf1a1a198c3f3c6dc043ef8e18f8835.png" medium="image">
			<media:title type="html">L(x) := \sum_{j=0}^{k} y_j \ell_j(x)</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/8/b/6/8b6c54923053f5d804ac01ef2ada443f.png" medium="image">
			<media:title type="html">\ell_j(x) := \prod_{i=0,\, i\neq j}^{k} \frac{x-x_i}{x_j-x_i} = \frac{(x-x_0)}{(x_j-x_0)} \cdots \frac{(x-x_{j-1})}{(x_j-x_{j-1})} \frac{(x-x_{j+1})}{(x_j-x_{j+1})} \cdots \frac{(x-x_{k})}{(x_j-x_{k})}.</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/1/d/7/1d77fff2196a620b2c57c22974671b10.png" medium="image">
			<media:title type="html">L(x_j) = y_j \qquad j=0,\ldots,k</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/3/7/c/37ca7ba34492aac83e9cda730482fd1f.png" medium="image">
			<media:title type="html">\ell_j(x)</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/7/7/c/77c0a0d495ebe61829360c6340a92eb8.png" medium="image">
			<media:title type="html">\ell_i(x_j) = \delta_{ij},\quad 0 \leq i,j \leq k.\, </media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/math/6/b/f/6bffa185bea4c9e0156f8e438659c4b1.png" medium="image">
			<media:title type="html">L(x_i) = \sum_{j=0}^{k} y_j \ell_j(x_i) = \sum_{j=0}^{k} y_j \delta_{ji} = y_i.</media:title>
		</media:content>

		<media:content url="/Users/Mike/AppData/Local/Temp/moz-screenshot.png" medium="image" />

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/8.jpg?w=300" medium="image">
			<media:title type="html">8</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/9.jpg?w=300" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/10.jpg" medium="image">
			<media:title type="html">10</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/11.jpg" medium="image">
			<media:title type="html">11</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/12.jpg" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/14.jpg?w=300" medium="image">
			<media:title type="html">14</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding the Zero of a Function (Continued)</title>
		<link>http://mpalermo1220.wordpress.com/2009/12/21/finding-the-zero-of-a-function-continued/</link>
		<comments>http://mpalermo1220.wordpress.com/2009/12/21/finding-the-zero-of-a-function-continued/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 21:54:25 +0000</pubDate>
		<dc:creator>mpalermo1220</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mpalermo1220.wordpress.com/?p=28</guid>
		<description><![CDATA[Newton&#8217;s Method Another formidable technique for determining the zero of a function is by using Newton&#8217;s Method.  It is very similar to the Fixed Point method in that it uses recursion to determine the zero.  Newton&#8217;s Method is defined as: Where xn is an initial guess and is the original function divided by the derivative [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=28&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration:underline;">Newton&#8217;s Method</span></strong><strong> </strong></p>
<p>Another formidable technique for determining the zero of a function is by using Newton&#8217;s Method.  It is very similar to the Fixed Point method in that it uses recursion to determine the zero.  Newton&#8217;s Method is defined as:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/1.jpg"><img class="aligncenter size-full wp-image-32" title="1" src="http://mpalermo1220.files.wordpress.com/2009/12/1.jpg?w=224&#038;h=67" alt="" width="224" height="67" /></a></p>
<p>Where <em>x</em><sub>n</sub> is an initial guess and <a href="http://mpalermo1220.files.wordpress.com/2009/12/2.jpg"><img class="aligncenter size-full wp-image-33" title="2" src="http://mpalermo1220.files.wordpress.com/2009/12/2.jpg?w=49&#038;h=42" alt="" width="49" height="42" /></a> is the original function divided by the derivative of the function.  This method is repeated until the specified accuracy is achieved.</p>
<p>Let us recall our previous example of f(x)=x^2-2 .  From calculus, we know the derivative of f(x):  f&#8217;(x)=2x.</p>
<p>Since we already have a general idea of what the zero of this function is, we can make a fairly accurate guess.  Let us use x<sub>0</sub>=1.5.  Now according to Newton’s Method, our first approximation should look like:</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/3.jpg"><img class="aligncenter size-medium wp-image-34" title="3" src="http://mpalermo1220.files.wordpress.com/2009/12/3.jpg?w=300&#038;h=106" alt="" width="300" height="106" /></a></p>
<p>Now as you can see, 1.41666667 is still not close enough to the exact answer so we would repeat these steps to find f(x<sub>0</sub>).  The first ten iterations of this method yield:</p>
<p>f(x<sub>0</sub>)=1.416666666666667<br />
f(x<sub>1</sub>)=1.414215686274510<br />
f(x<sub>2</sub>)=1.414213562374690<br />
f(x<sub>3</sub>)=1.414215686274510<br />
f(x<sub>4</sub>)=1.414213562373095<br />
f(x<sub>5</sub>)=1.414213562373095<br />
f(x<sub>6</sub>)=1.414213562373095<br />
f(x<sub>7</sub>)=1.414213562373095<br />
f(x<sub>8</sub>)=1.414213562373095<br />
f(x<sub>9</sub>)=1.414213562373095<br />
f(x<sub>10</sub>)=1.414213562373095</p>
<p>As you can see, we approach our desired approximation very quickly, five iterations to be exact.  You can see how quickly this method converges to our desired answer by looking at the following chart.</p>
<p><a href="http://mpalermo1220.files.wordpress.com/2009/12/4.jpg"><img class="aligncenter size-medium wp-image-35" title="4" src="http://mpalermo1220.files.wordpress.com/2009/12/4.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a>Here is the code that finds the zero of f(x)=x^2-2 and produced the previous graph.</p>
<p>%Newton&#8217;s Method for f(x)=x^2-2</p>
<p>clear all<br />
format long<br />
p(1)=1.5;<br />
pexact(1)=1.414;<br />
error(1)=abs(p(1)-pexact(1));<br />
rate(1)=error(1);<br />
n=10;<br />
for i=1:n<br />
p(i+1)=p(i)-(p(i)*p(i)-2)/(2*p(i));<br />
pexact(i+1)=1.414;<br />
error(i+1)=abs(p(i+1)-pexact(i+1));<br />
rate(i+1)=(1/4)*rate(i);<br />
end<br />
for i=1:n<br />
p(i)<br />
end<br />
plot(p)<br />
hold on<br />
plot(pexact, &#8216;r&#8217;)<br />
figure<br />
plot(error, &#8216;r&#8217;)<br />
hold on<br />
plot(rate, &#8216;b&#8217;)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mpalermo1220.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mpalermo1220.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mpalermo1220.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=28&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mpalermo1220.wordpress.com/2009/12/21/finding-the-zero-of-a-function-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dc31f6f658dd224665bdeb57d1acef9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mpalermo1220</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/1.jpg" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/2.jpg" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/3.jpg?w=300" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/12/4.jpg?w=300" medium="image">
			<media:title type="html">4</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding the Zero of a Function</title>
		<link>http://mpalermo1220.wordpress.com/2009/10/06/finding-the-zero-of-a-function/</link>
		<comments>http://mpalermo1220.wordpress.com/2009/10/06/finding-the-zero-of-a-function/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 06:14:14 +0000</pubDate>
		<dc:creator>mpalermo1220</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mpalermo1220.wordpress.com/?p=3</guid>
		<description><![CDATA[We were given a function &#8220;f&#8221; over a fixed interval [a,b], where either f(a) or f(b) was positive with the other being negative.  The objective, given that f(x) is continuous on [a,b], was to prove that for some point c, where a&#60;c&#60;b, that f(c)=0.  There are several ways to determine a value of c. Bisection [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=3&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We were given a function &#8220;f&#8221; over a fixed interval [a,b], where either f(a) or f(b) was positive with the other being negative.  The objective, given that f(x) is continuous on [a,b], was to prove that for some point c, where a&lt;c&lt;b, that f(c)=0.  There are several ways to determine a value of c.</p>
<h2><span style="text-decoration:underline;"><strong>Bisection Method</strong></span></h2>
<p>The first method was the bisection method.  This method involved finding the midpoint of the interval [a,b].  I called this point m.  The next step was to determine if a&lt;c&lt;m or m&lt;c&lt;b.  In other words, I was trying to determine if the function&#8217;s zero value was between the interval of a and m or the interval of m and b.  This is simply done by multiplying f(a) with f(m).  If this product is negative, then that means c (or zero value) is between a and m.  Otherwise, if f(a) x f(m) is positive, then m&lt;c&lt;b.  Although, on the rare occasion, if f(m)=0, then we have found the zero of the function, c=m.</p>
<p>After determining the correct section in which c is located, you must reassign values for either a or b.  If a&lt;c&lt;m, then set b=m.  If m&lt;c&lt;b, then set a=m.  Now, that the method is understood, all that is left to do is to repeat these steps until you have a margin of error of 10<sup>-15</sup>.  In other words, b-m should roughly equal 10<sup>-15</sup>.</p>
<p>Doing these calculations by hand will become tedious very quickly.  To make it easier to understand, here is the coding to determine the zero of the function f(x)=x<sup>2</sup>-2 on the interval [1,2].  Basic algebra tells us that the zero of f(x) that is on the interval of [1,2] is the square root of 2.   *This is the coding for a MATLAB .m file.</p>
<p>a=1;       <span style="color:#99cc00;">%left endpoint</span><br />
b=2;      <span style="color:#99cc00;">%right endpoint</span><br />
fa=a^2-2;    <span style="color:#99cc00;">%left function value</span><span style="color:#99cc00;"> of f(x)=x^2-2</span><br />
fb=b^2-2;    <span style="color:#99cc00;">%right function value</span><span style="color:#99cc00;"> of f(x)=x^2-2</span><br />
Nstop=log(1.e15)/log(2);   <span style="color:#99cc00;">%figure our how many iterations</span><br />
for j=1:Nstop+1<br />
m(j)=(a+b)/2;<br />
f(j)=m(j)*m(j) -2 ;<br />
if (f(j)==0)<br />
mm=m(j);<br />
break<br />
end    <span style="color:#99cc00;">%need to stop!</span><br />
if (f(j)*fa&lt;0) b=m(j) ;<br />
else a=m(j);<br />
end<br />
fa=a^2-2;<br />
fb=b^2-2;<br />
end</p>
<h2><strong><span style="text-decoration:underline;">Multi-partition Method</span></strong></h2>
<p>The next idea was to determine if it is more efficient to divide the interval into more than two partitions like the bisection method used.  This is called the multi-partition method.  It uses the same ideas as the bisection method except that you have the choice of how many partitions to separate the interval into.  It comes with its own advantages and disadvantages.  For example, it requires far less number of intervals to be divided because the error will get closer to the desired error of 10<sup>-15</sup>.  Unfortunately, you may have to do &#8220;n number of partitions&#8221; per interval which significantly increases the total number of iterations that need to be done and the longer it takes to get to an answer.</p>
<p>The multi-partition works the same way as the bisection method in regards to finding partition in which c is located.  We start this procedure by first determining how many partitions we want to use.  We will designate each partition point as i<sub>k</sub> with k=1&#8230;n number of partitions.  Just like the bisection method, after we find the partition where point c is located, we reassign point a to the point i<sub>k</sub> and point b to the point i<sub>k+1</sub>, where  i<sub>k</sub>&lt;c&lt;i<sub>k+1</sub>. We repeat these steps until b-c is roughly10<sup>-15</sup>.</p>
<p>Using the same function as earlier, f(x)=x<sup>2</sup>-2 on the interval [1,2], here is the coding for the multi-partition method.</p>
<p>a=1;    <span style="color:#99cc00;">%initial left endpoint</span><br />
b=2;      <span style="color:#99cc00;">%initial right endpoint</span><br />
fa=a^2-2;        <span style="color:#99cc00;">%initial left function value</span><br />
fb=b^2-2;       <span style="color:#99cc00;">%initial right function value</span><br />
partition=10;    <span style="color:#99cc00;">%number of partitions</span><br />
Nstop=log(1.e15)/log(partition);         <span style="color:#99cc00;">%figure our how many iterations</span><br />
i=0;<br />
for j=1:Nstop+1     <span style="color:#99cc00;">%iteration loop</span><br />
interval=(b-a)/partition;    <span style="color:#99cc00;">%interval between each partition</span><br />
m=0;<br />
while (m~=b)     <span style="color:#99cc00;">%</span><span style="color:#99cc00;">continues until the right partition is found</span><br />
m=a+interval;<br />
fm=m^2-2;<br />
if (fm==0)<br />
mm=m;<br />
break<br />
end    <span style="color:#99cc00;">%need to stop!</span><br />
if (fa*fm&lt;0)<br />
b=m;<br />
fb=b^2-2;<br />
end<br />
if (fa*fm&gt;0)<br />
a=m;<br />
fa=a^2-2;<br />
end<br />
end<br />
end<br />
m    <span style="color:#99cc00;">%outputs the zero of f(x)</span></p>
<h2><span style="color:#99cc00;"><strong><span style="color:#000000;"><span style="text-decoration:underline;">Fixed Point Method</span></span></strong></span></h2>
<p><span style="color:#99cc00;"><span style="color:#000000;">Another unique way of finding the zero is by using the fixed point method.  We still want to find the point c such that f(c)=0.  But now also we have to define another function g(x) in which g(c)=c, thus defining a fixed point.  Another condition that is required is that |g&#8217;(x)|&lt;1.</span></span></p>
<p><span style="color:#99cc00;"><span style="color:#000000;">We would assume g(x)=x, but instead we are going to say g(x)=x+r•f(x) where</span></span><span style="color:#99cc00;"><span style="color:#000000;"> r•f(x) </span></span><span style="color:#99cc00;"><span style="color:#000000;"> is the error.  Eventually </span></span><span style="color:#99cc00;"><span style="color:#000000;">r•f(x) </span></span><span style="color:#99cc00;"><span style="color:#000000;"> will</span></span> converge to zero as x gets closer to c.  Using our previous example of  f(x)=x<sup>2</sup>-2, we can now say g(x)=x+r•(x<sup>2</sup>-2).</p>
<p>Now solving the triangle inequality:</p>
<ul>
<li><span style="color:#99cc00;"><span style="color:#000000;">|g&#8217;(x)|&lt;1 → -1&lt;</span></span><span style="color:#99cc00;"><span style="color:#000000;">g&#8217;(x)&lt;1</span></span></li>
<li><span style="color:#99cc00;"><span style="color:#000000;">where g&#8217;(x)=1+2r</span></span>x → -1&lt;<span style="color:#99cc00;"><span style="color:#000000;">1+2r</span></span>x<span style="color:#99cc00;"><span style="color:#000000;">&lt;1</span></span></li>
<li><span style="color:#99cc00;"><span style="color:#000000;">which implies -2&lt;2rx&lt;0 → -1&lt;rx&lt;0 → -1/x&lt;r&lt;0</span></span></li>
</ul>
<p>From this we begin by taking an estimate of the zero value.  Our estimate has to be on the interval of [1,2].  To make it easy, let us use x<sub>1</sub>=1.5.  Using this value for x<sub>1</sub>, we can now find decide on a value of r.  Remember <span style="color:#99cc00;"><span style="color:#000000;">-1/x&lt;r&lt;0, so in our example, </span></span><span style="color:#99cc00;"><span style="color:#000000;">-1/1.5&lt;r&lt;0 </span></span><span style="color:#99cc00;"><span style="color:#000000;"> → -0.6667&lt;r&lt;0.  Let us pick a value of r satisfying this inequality.  Let r=-0.25.</span></span></p>
<p><span style="color:#99cc00;"><span style="color:#000000;">We can now find out what g(</span></span>x<sub>2</sub>) is equal to.</p>
<ul>
<li>g(x<sub>2</sub>)=x<sub>1</sub> + r•(x<sub>1</sub><sup>2</sup>-2)</li>
<li>g(x<sub>2</sub>)=1.5 + (-0.25)(1.5<sup>2</sup>-2)</li>
<li>g(x<sub>2</sub>)=1.5 + (-0.25)(2.25-2)</li>
<li>g(x<sub>2</sub>)=1.5 + (-0.25)(0.25)</li>
<li>g(x<sub>2</sub>)=1.5 &#8211; 0.0625</li>
<li>g(x<sub>2</sub>)=1.4375</li>
</ul>
<p>Using this procedure, we can find g(x<sub>n</sub>) by following these steps n times.  For example, g(x<sub>3</sub>) can be found by:</p>
<ul>
<li>g(x<sub>3</sub>)=x<sub>2</sub> + r•(x<sub>2</sub><sup>2</sup>-2)</li>
<li>g(x<sub>3</sub>)=1.4375 + (-0.25)(1.4375<sup>2</sup>-2)</li>
<li>g(x<sub>3</sub>)=1.4375 + (-0.25)(2.0664-2)</li>
<li>g(x<sub>3</sub>)=1.4375 + (-0.25)(0.0664)</li>
<li>g(x<sub>3</sub>)=1.4375 &#8211; 0.0166</li>
<li>g(x<sub>3</sub>)=1.4209</li>
</ul>
<p>As you can see, we are getting closer to our targeted value of 1.41421356.  It is much more efficient to let a computer calculate more precise answers.  This can be done by using the following code designed for our example.</p>
<p>p(1)=1.5;   <span style="color:#99cc00;">%initial guess</span><br />
pexact(1)=1.41421356237095;   <span style="color:#99cc00;">%exact value of c</span><br />
error(1)=abs(p(1)-pexact(1));<br />
rate(1)=error(1);<br />
r=-0.25;<br />
n=25;  <span style="color:#99cc00;">%number of iterations</span><br />
for x=1:n<br />
p(x+1)=p(x)+r*(p(x)*p(x)-2);<br />
pexact(x+1)=1.41421356237095;<br />
error(x+1)=abs(p(x+1)-pexact(x+1));  <span style="color:#99cc00;">%measures how far away the estimate is off from the exact answer. converges to 0.</span><br />
rate(x+1)=(1/2)*rate(x);<br />
end<br />
p(n)<br />
plot(p)   <span style="color:#99cc00;">%</span><span style="color:#99cc00;"><span style="color:#99cc00;">p</span>lots x<sub>n</sub></span><br />
hold on<br />
plot(pexact, &#8216;r&#8217;)  <span style="color:#99cc00;">%plots exact value c.  Shows how x<sub>n</sub> converges to c.</span><br />
figure<br />
plot(error, &#8216;r&#8217;)<br />
hold on<br />
plot(rate, &#8216;b&#8217;)</p>
<div id="attachment_20" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-20 " title="exact" src="http://mpalermo1220.files.wordpress.com/2009/10/exact.png?w=460&#038;h=345" alt="exact" width="460" height="345" /><p class="wp-caption-text">Figure 1:  Shows how each estimate gets closer and eventually converges to the value of c.</p></div>
<p style="text-align:center;">
<div id="attachment_24" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-24" title="error" src="http://mpalermo1220.files.wordpress.com/2009/10/error1.png?w=460&#038;h=345" alt="Figure 2:  Shows how far off each estimate is compared to the value of c.  After a short period of time, the error converges to 0." width="460" height="345" /><p class="wp-caption-text">Figure 2:  Shows how far off each estimate is compared to the value of c.  After a short period of time, the error converges to 0.</p></div>
<h2><span style="color:#000000;"><span style="text-decoration:underline;"><strong>Conclusion</strong></span></span></h2>
<p><span style="color:#000000;">All three of these methods yielded the same result.  The only difference is their ease of usage.  The bisection method is by far the easiest to use, but the fixed point method yielded the quickest answer.  The fixed point method requires several calculations to be found, specifically g&#8217;(x) which might now be known to those with no calculus background.  The multi-partition has no real advantage over the bisection method since it is essentially the same thing, but with a longer calculation time.  If I had to recommend a method, it would be the bisection method because of its ease of use and effectiveness.<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mpalermo1220.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mpalermo1220.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mpalermo1220.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mpalermo1220.wordpress.com&amp;blog=9704077&amp;post=3&amp;subd=mpalermo1220&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mpalermo1220.wordpress.com/2009/10/06/finding-the-zero-of-a-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4dc31f6f658dd224665bdeb57d1acef9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mpalermo1220</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/10/exact.png" medium="image">
			<media:title type="html">exact</media:title>
		</media:content>

		<media:content url="http://mpalermo1220.files.wordpress.com/2009/10/error1.png" medium="image">
			<media:title type="html">error</media:title>
		</media:content>
	</item>
	</channel>
</rss>
