<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Numerical Methods Guy</title>
	
	<link>http://autarkaw.wordpress.com</link>
	<description>Simplifying numerical methods</description>
	<lastBuildDate>Wed, 08 Jul 2009 22:30:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/73199b80a75e6a5213f57c3508f7dcf8?s=96&amp;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>The Numerical Methods Guy</title>
		<link>http://autarkaw.wordpress.com</link>
	</image>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/wordpress/EDie" type="application/rss+xml" /><feedburner:emailServiceId>wordpress/EDie</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>How do I display the data of an array in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/5ac6TAT-Eck/</link>
		<comments>http://autarkaw.wordpress.com/2009/07/08/how-do-i-display-the-data-of-an-array-in-matlab/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 20:18:40 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=358</guid>
		<description><![CDATA[When I give a MATLAB project, I ask my students that the command window can only show output from disp and frprintf statements.  All other statement outputs need to be suppressed.  This is done to get an aesthetically pleasing report.  So what is a student supposed to do when you may have y vs x [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=358&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When I give a MATLAB project, I ask my students that the command window can only show output from disp and frprintf statements.  All other statement outputs need to be suppressed.  This is done to get an aesthetically pleasing report.  So what is a student supposed to do when you may have y vs x data and one needs to show it as an ouput, especially when the number of y vs x data points can change.</p>
<p>For example we may have</p>
<p>x=[1  4  5   7 ]</p>
<p>y=[12  23  34  100]</p>
<p>How do I display this with just disp and fprintf statements?</p>
<ul>
<li>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/displaying_arrays.m">here</a>.</li>
<li>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/displaying_arrays.html">here</a>.</li>
<li>DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  <a href="http://numericalmethods.eng.usf.edu/blog/displaying_arrays.m" target="_blank">DOWNLOAD THE MATLAB PROGRAM</a> INSTEAD</li>
</ul>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I display arrays in MATLAB?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw and Jeremy Baker;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/displaying_arrays.m;<br />
% Last Revised : July 8, 2009;<br />
% Abstract: This program shows you how to display arrays in MATLAB<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to display arrays&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com and Jeremy Baker&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/displaying_arrays.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   July 8, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% Input x and y arrays, for example as y vs x data<br />
x=[1  4  5   7 ];<br />
y=[12  23  34  100];<br />
%% DISPLAYING INPUTS METHOD 1<br />
disp(&#8217;INPUTS &#8211; Method 1&#8242;)<br />
n=length(x);<br />
fprintf(&#8217;The number of data points is %g \n&#8217;,n)<br />
disp(&#8217;________________________&#8217;)<br />
disp(&#8217;  x-values    y values  &#8216;)<br />
disp(&#8217;________________________&#8217;)<br />
for i=1:1:n<br />
fprintf(&#8217;      %g          %g \n&#8217;,x(i), y(i)&#8217;)<br />
end<br />
disp(&#8217;________________________&#8217;)</p>
<p>%% DISPLAYING INPUTS METHOD 2<br />
% Suggested by guest blogger Jeremy Baker<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;INPUTS &#8211; Method 2&#8242;)<br />
n=length(x);<br />
fprintf(&#8217;The number of data points is %g \n&#8217;,n)<br />
disp(&#8217;________________________&#8217;)<br />
disp(&#8217;     x    y  &#8216;)<br />
disp(&#8217;________________________&#8217;)<br />
dataval=[x;y]&#8216;;<br />
disp(dataval)<br />
disp(&#8217;________________________&#8217;)</p>
<p>_____________________________________________</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
<p><!--Session data--></p>
Posted in MATLAB programming, Numerical Methods Tagged: arrays, display, matlab <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=358&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/5ac6TAT-Eck" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/07/08/how-do-i-display-the-data-of-an-array-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/07/08/how-do-i-display-the-data-of-an-array-in-matlab/</feedburner:origLink></item>
		<item>
		<title>Poems on Numerical Methods</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/yZLro5nBieM/</link>
		<comments>http://autarkaw.wordpress.com/2009/07/04/poems-on-numerical-methods/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 17:32:58 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[poems]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=355</guid>
		<description><![CDATA[In Summer 2009, I gave a HW assignment of writing a poem to my mostly right-brained students.  The results were great; I think they think they are poets and they know it.  The poems were all compiled and can be viewed at http://numericalmethods.eng.usf.edu/EML3041/homework/poems2009summer.html.
So happy reading and let me know what you think.  I selected 14 poems out of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=355&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In Summer 2009, I gave a HW assignment of writing a poem to my mostly right-brained students.  The results were great; I think they think they are poets and they know it.  The poems were all compiled and can be viewed at <a href="http://numericalmethods.eng.usf.edu/EML3041/homework/poems2009summer.html">http://numericalmethods.eng.usf.edu/EML3041/homework/poems2009summer.html</a>.</p>
<p>So happy reading and let me know what you think.  I selected 14 poems out of the 60 or so submitted and am polling the class to select the best three.  The top three poem writers will get prizes including a dollar to get the 89c Chicken Burritto at Taco Bell for &#8220;thinking outside the bun&#8221; or the biggie fries at Wendy&#8217;s for thinking &#8220;square rather than round&#8221;.</p>
<p>_____________________________________________</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
Posted in Numerical Methods Tagged: Numerical Methods, poems <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/355/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/355/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/355/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/355/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/355/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/355/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/355/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/355/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/355/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/355/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=355&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/yZLro5nBieM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/07/04/poems-on-numerical-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/07/04/poems-on-numerical-methods/</feedburner:origLink></item>
		<item>
		<title>How do I do spline interpolation in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/P-nliiUiRos/</link>
		<comments>http://autarkaw.wordpress.com/2009/06/20/how-do-i-do-spline-interpolation-in-matlab/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 18:13:33 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Interpolation]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=349</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to conduct spline interpolation.

The MATLAB program link is here.
The HTML version of the MATLAB program is here.
DO [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=349&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to conduct spline interpolation.</p>
<ul>
<li>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/interpolate_spline.m">here</a>.</li>
<li>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/interpolate_spline.html">here</a>.</li>
<li>DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT  TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  <a href="http://numericalmethods.eng.usf.edu/blog/interpolate_spline.m" target="_blank">DOWNLOAD THE MATLAB PROGRAM</a> INSTEAD</li>
</ul>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I do spline interpolation?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/interpolate_spline.m;<br />
% Last Revised : June 20, 2009;<br />
% Abstract: This program shows you how to do spline interpolation?<br />
%           .<br />
clc<br />
clear all<br />
clf</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to do spline interpolation?&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/interpolation_spline.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   June 20, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% y vs x data to interpolate<br />
% x data<br />
x=[-1  -0.75  -0.5  -0.25   0.25  0.50 0.75  1];<br />
% ydata<br />
y=[-0.5  -0.5  -0.5  -0.5   0.5  0.5  0.5  0.5];<br />
% Where do you want to interpolate at<br />
xin=[-0.8  -0.7  0.7  0.8];<br />
%% DISPLAYING INPUTS<br />
disp(&#8217;INPUTS&#8217;)<br />
disp(&#8217;The x data&#8217;)<br />
x<br />
disp(&#8217;The y data&#8217;)<br />
y<br />
disp(&#8217;The x values where you want to find the interpolated values&#8217;)<br />
xin<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE<br />
% Fitting to spline &#8211; it is cubic splines<br />
yin=spline(x,y,xin);<br />
% This is only for plotting the spline interpolants<br />
% Find the number of data points<br />
n=length(x);<br />
xplot=x(1):(x(n)-x(1))/10000:x(n);<br />
yplot=spline(x,y,xplot);</p>
<p>%% DISPLAYING OUTPUTS<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;OUTPUTS&#8217;)<br />
disp(&#8217;x values at which function is to be interpolated&#8217;)<br />
xin<br />
disp(&#8217;y values at the xin values&#8217;)<br />
yin<br />
xlabel(&#8217;x');<br />
ylabel(&#8217;y');<br />
title(&#8217;y vs x &#8216;);<br />
plot(x,y,&#8217;o',&#8217;MarkerSize&#8217;,10,&#8217;MarkerEdgeColor&#8217;,'b&#8217;,'MarkerFaceColor&#8217;,'b&#8217;)<br />
hold on<br />
plot(xin,yin,&#8217;o',&#8217;MarkerSize&#8217;,10,&#8217;MarkerEdgeColor&#8217;,'r&#8217;,'MarkerFaceColor&#8217;,'r&#8217;)<br />
hold on<br />
plot(xplot,yplot,&#8217;LineWidth&#8217;,2)<br />
legend(&#8217;Points given&#8217;,'Points found&#8217;,'Spline Curve&#8217;,'Location&#8217;,'East&#8217;)<br />
hold off<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods  for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the  textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available  from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video  lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the  information follow you.</p>
Posted in Interpolation, matlab  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=349&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/P-nliiUiRos" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/06/20/how-do-i-do-spline-interpolation-in-matlab/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/06/20/how-do-i-do-spline-interpolation-in-matlab/</feedburner:origLink></item>
		<item>
		<title>How do I do polynomial interpolation in MATLAB</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/GEkjfMTLJoA/</link>
		<comments>http://autarkaw.wordpress.com/2009/06/11/how-do-i-do-polynomial-interpolation-in-matlab/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 12:27:22 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Interpolation]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/2009/06/11/345/</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to do polynomial interpolation.

The MATLAB program link is here.
The HTML version of the MATLAB program is here.
DO [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=345&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to do polynomial interpolation.</p>
<ul>
<li>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/interpolate_polynomial.m">here</a>.</li>
<li>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/interpolate_polynomial.html">here</a>.</li>
<li>DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT  TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  <a href="http://numericalmethods.eng.usf.edu/blog/interpolate_polynomial.m" target="_blank">DOWNLOAD THE MATLAB PROGRAM</a> INSTEAD</li>
</ul>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I do polynomial interpolation?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/interpolate_polynomial.m;<br />
% Last Revised : June 10, 2009;<br />
% Abstract: This program shows you how to do polynomial interpolation?<br />
%           .<br />
clc<br />
clear all<br />
clf</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to do polynomial interpolation?&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/interpolation_polynomial.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   June 10, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% y vs x data to interpolate<br />
% x data<br />
x=[-1  -0.6  -0.2  0.2  0.6  1];<br />
% ydata<br />
y=[0.0385    0.1000    0.5000    0.5000    0.1000    0.0385];<br />
% Where do you want to interpolate at<br />
xin=[-0.8  -0.7  0.7  0.8];<br />
%% DISPLAYING INPUTS<br />
disp(&#8217;INPUTS&#8217;)<br />
disp(&#8217;The x data&#8217;)<br />
x<br />
disp(&#8217;The y data&#8217;)<br />
y<br />
disp(&#8217;The x values where you want to find the interpolated values&#8217;)<br />
xin<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE<br />
% Find the number of data points<br />
n=length(x);<br />
% Fitting to polynomial of order m=n-1<br />
m=n-1<br />
% pp consists of the coefficients of the polynomial<br />
% pp(1)*x^m+pp(2)*x^m+&#8230;&#8230;.+pp(m)<br />
% pp(1) is coefficient of x^m<br />
% pp(2) is coefficient of x^(m-1)<br />
% and so on<br />
pp=polyfit(x,y,m);<br />
% Getting the values at xin<br />
yin=polyval(pp,xin);<br />
% This is only for plotting the interpolating polynomial<br />
xplot=x(1):(x(n)-x(1))/10000:x(n);<br />
yplot=polyval(pp,xplot);</p>
<p>%% DISPLAYING OUTPUTS<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;OUTPUTS&#8217;)<br />
disp(&#8217;x values at which function is to be interpolated&#8217;)<br />
xin<br />
disp(&#8217;y values at the xin values&#8217;)<br />
yin<br />
disp(&#8217;These are the coefficients of the polynomial interpolant&#8217;)<br />
disp(&#8217;pp(1) is coefficient of x^m, pp(2) is coefficient of x^(m-1) and so on&#8217;)<br />
fprintf(&#8217;Order of polynomial m =%g&#8217;,m)<br />
pp<br />
xlabel(&#8217;x');<br />
ylabel(&#8217;y');<br />
title(&#8217;y vs x &#8216;);<br />
plot(x,y,&#8217;o',&#8217;MarkerSize&#8217;,10,&#8217;MarkerEdgeColor&#8217;,'b&#8217;,'MarkerFaceColor&#8217;,'b&#8217;)<br />
hold on<br />
plot(xin,yin,&#8217;o',&#8217;MarkerSize&#8217;,10,&#8217;MarkerEdgeColor&#8217;,'k&#8217;,'MarkerFaceColor&#8217;,'k&#8217;)<br />
hold on<br />
plot(xplot,yplot,&#8217;LineWidth&#8217;,2)<br />
legend(&#8217;Points given&#8217;,'Points found&#8217;,'Polynomial Curve&#8217;)<br />
hold off<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods  for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the  textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available  from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video  lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the  information follow you.</p>
Posted in Interpolation, matlab, Numerical Methods  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/345/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=345&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/GEkjfMTLJoA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/06/11/how-do-i-do-polynomial-interpolation-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/06/11/how-do-i-do-polynomial-interpolation-in-matlab/</feedburner:origLink></item>
		<item>
		<title>How do I solve a boundary value ODE?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/EUZxLviW3X8/</link>
		<comments>http://autarkaw.wordpress.com/2009/05/25/how-do-i-solve-a-boundary-value-ode/#comments</comments>
		<pubDate>Mon, 25 May 2009 20:30:10 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[Ordinary Differential Equations]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=339</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a boundary value ordinary differential equation.

The MATLAB program link is here.
The HTML version of the MATLAB program [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=339&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a boundary value ordinary differential equation.</p>
<ul>
<li>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/ode_boundaryvalue.m">here</a>.</li>
<li>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/ode_boundaryvalue.html">here</a>.</li>
<li>DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  <a href="http://numericalmethods.eng.usf.edu/blog/ode_boundaryvalue.m" target="_blank">DOWNLOAD THE MATLAB PROGRAM</a> INSTEAD</li>
</ul>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I solve a boundary value ordinary differential equation?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/ode_boundaryvalue.m;<br />
% Last Revised : May 26, 2009;<br />
% Abstract: This program shows you how to solve an<br />
%           boundary value ordinary differential equation.<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to solve&#8217;)<br />
disp(&#8217;   a boundary value ordinary differential equation&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/ode_boundaryvalue.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   May 26, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% Solve the ordinary differential equation<br />
% y&#8221;-0.0000002y=0.000000075*x*(75-x)<br />
% Define x as a symbol<br />
syms x<br />
%The ODE<br />
ode_eqn=&#8217;D2y-0.000002*y=0.000000075*x*(75-x)&#8217;;<br />
% The initial conditions<br />
iv_1=&#8217;y(0)=0&#8242;;<br />
iv_2=&#8217;y(75)=0&#8242;;<br />
% The value at which y is sought at<br />
xval=37.5;<br />
%% DISPLAYING INPUTS</p>
<p>disp(&#8217;INPUTS&#8217;)<br />
func=['  The ODE to be solved is ' ode_eqn];<br />
disp(func)<br />
iv_explain=['  The boundary conditions are ' iv_1 '    ' iv_2];<br />
disp(iv_explain)<br />
fprintf(&#8217;  The value of y is sought at x=%g&#8217;,xval)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE</p>
<p>% Finding the solution of the ordinary differential equation<br />
soln=dsolve(ode_eqn,iv_1,iv_2,&#8217;x');<br />
% vpa below uses variable-precision arithmetic (VPA) to compute each<br />
% element of soln to 5 decimal digits of accuracy<br />
soln=vpa(soln,5);</p>
<p>%% DISPLAYING OUTPUTS<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;OUTPUTS&#8217;)<br />
output=['  The solution to the ODE is ' char(soln)];<br />
disp(output)<br />
value=subs(soln,x,xval);<br />
fprintf(&#8217;  The value of y at x=%g is %g&#8217;,xval,value)<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods  for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the  textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available  from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video  lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the  information follow you.</p>
Posted in matlab, Numerical Methods, Ordinary Differential Equations Tagged: matlab, Ordinary Differential Equations <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/339/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=339&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/EUZxLviW3X8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/05/25/how-do-i-solve-a-boundary-value-ode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/05/25/how-do-i-solve-a-boundary-value-ode/</feedburner:origLink></item>
		<item>
		<title>How do I solve an initial value ODE in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/l9gJmsdjCIk/</link>
		<comments>http://autarkaw.wordpress.com/2009/05/14/how-do-i-solve-an-initial-value-ode-in-matlab/#comments</comments>
		<pubDate>Thu, 14 May 2009 16:15:46 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[Ordinary Differential Equations]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=334</guid>
		<description><![CDATA[
Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to solve an initial value ordinary differential equation.

The MATLAB program link is here.
The HTML version of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=334&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div class="snap_preview">
<p>Many students ask me how do I do this or that in MATLAB.  So I thought why  not have a small series of my next few blogs do that.  In this blog, I show you  how to solve an initial value ordinary differential equation.</p>
<ul>
<li>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/ode_initial.m">here</a>.</li>
<li>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/ode_initial.html">here</a>.</li>
<li>DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  <a href="http://numericalmethods.eng.usf.edu/blog/ode_initial.m" target="_blank">DOWNLOAD THE MATLAB PROGRAM</a> INSTEAD</li>
</ul>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I solve an initial value ordinary differential equation?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/ode_initial.m;<br />
% Last Revised : May 14, 2009;<br />
% Abstract: This program shows you how to solve an<br />
%           initial value ordinary differential equation.<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to solve&#8217;)<br />
disp(&#8217;   an initial value ordinary differential equation&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/ode_initial.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   May 14, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% Solve the ordinary differential equation 3y&#8221;+5y&#8217;+7y=11exp(-x)<br />
% Define x as a symbol<br />
syms x<br />
%The ODE<br />
ode_eqn=&#8217;3*D2y+5*Dy+7*y=11*exp(-13*x)&#8217;;<br />
% The initial conditions<br />
iv_1=&#8217;Dy(0)=17&#8242;;<br />
iv_2=&#8217;y(0)=19&#8242;;<br />
% The value at which y is sought at<br />
xval=23.0;<br />
%% DISPLAYING INPUTS</p>
<p>disp(&#8217;INPUTS&#8217;)<br />
func=['  The ODE to be solved is ' ode_eqn];<br />
disp(func)<br />
iv_explain=['  The initial conditions are ' iv_1 '    ' iv_2];<br />
disp(iv_explain)<br />
fprintf(&#8217;  The value of y is sought at x=%g&#8217;,xval)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE</p>
<p>% Finding the solution of the ordinary differential equation<br />
soln=dsolve(ode_eqn,iv_1,iv_2,&#8217;x');<br />
% vpa below uses variable-precision arithmetic (VPA) to compute each<br />
% element of soln to 5 decimal digits of accuracy<br />
soln=vpa(soln,5);</p>
<p>%% DISPLAYING OUTPUTS<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;OUTPUTS&#8217;)<br />
output=['  The solution to the ODE is ' char(soln)];<br />
disp(output)<br />
value=subs(soln,x,xval);<br />
fprintf(&#8217;  The value of y at x=%g is %g&#8217;,xval,value)<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods  for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the  textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available  from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video  lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the  information follow you.</div>
Posted in matlab, MATLAB programming, Ordinary Differential Equations Tagged: matlab, Ordinary Differential Equations <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=334&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/l9gJmsdjCIk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/05/14/how-do-i-solve-an-initial-value-ode-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/05/14/how-do-i-solve-an-initial-value-ode-in-matlab/</feedburner:origLink></item>
		<item>
		<title>How do I solve a nonlinear equation that needs to be setup in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/S0oEsTarfhE/</link>
		<comments>http://autarkaw.wordpress.com/2009/04/17/how-do-i-solve-a-nonlinear-equation-that-needs-to-be-setup-in-matlab/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 17:14:24 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[nonlinear equations]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=329</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a nonlinear equation that needs to be set up.
For example to find the depth &#8216;x&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=329&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a nonlinear equation that needs to be set up.</p>
<p>For example to find the depth &#8216;x&#8217; to which a ball is floating in water is based on the following cubic equation<br />
4*R^3*S=3*x^2*(R-x/3)<br />
where<br />
R= radius of ball<br />
S= specific gravity of ball<br />
So how do we set this up if S and R are input values?</p>
<p>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/nonlinearequation_adv.m">here</a>.</p>
<p>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/nonlinearequation_adv.html">here</a>.</p>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I solve a nonlinear equation if I need to set it up?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/integration.m;<br />
% Last Revised : March 28, 2009;<br />
% Abstract: This program shows you how to solve a nonlinear equation<br />
% that needs to set up as opposed that is just given to you.<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to solve&#8217;)<br />
disp(&#8217;   a nonlinear equation that needs to be setup&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/nonlinearequation.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   April 17, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% Solve the nonlinear equation where you need to set up the equation<br />
% For example to find the depth &#8216;x&#8217; to which a ball is floating in water<br />
% is based on the following cubic equation<br />
% 4*R^3*S=3*x^2*(R-x/3)<br />
% R= radius of ball<br />
% S= specific gravity of ball<br />
% So how do we set this up if S and R are input values</p>
<p>S=0.6<br />
R=0.055<br />
%% DISPLAYING INPUTS<br />
disp(&#8217;INPUTS&#8217;)<br />
func=['  The equation to be solved is 4*R^3*S=3*x^2*(R-x/3)'];<br />
disp(func)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE<br />
% Define x as a symbol<br />
syms x<br />
% Setting up the equation<br />
C1=4*R^3*S<br />
C2=3<br />
f=[num2str(C1) '-3*x^2*(' num2str(R) '-x/3)']<br />
% Finding the solution of the nonlinear equation<br />
soln=solve(f,x);<br />
solnvalue=double(soln);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
for i=1:1:length(solnvalue)<br />
fprintf(&#8217;\nThe solution# %g is %g&#8217;,i,solnvalue(i))<br />
end<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
Posted in MATLAB programming, nonlinear equations, Numerical Methods Tagged: matlab, nonlinear equations <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/329/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=329&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/S0oEsTarfhE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/04/17/how-do-i-solve-a-nonlinear-equation-that-needs-to-be-setup-in-matlab/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/04/17/how-do-i-solve-a-nonlinear-equation-that-needs-to-be-setup-in-matlab/</feedburner:origLink></item>
		<item>
		<title>How do I solve a nonlinear equation in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/RfdW6KP01H0/</link>
		<comments>http://autarkaw.wordpress.com/2009/04/11/how-do-i-solve-a-nonlinear-equation-in-matlab/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 17:02:04 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[nonlinear equations]]></category>
		<category><![CDATA[nonlinear equation]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=325</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a nonlinear equation.
The MATLAB program link is here.
The HTML version of the MATLAB program is here.
%% HOW [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=325&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve a nonlinear equation.</p>
<p>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/nonlinearequation.m">here</a>.</p>
<p>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/nonlinearequation.html">here</a>.</p>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I solve a nonlinear equation?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/integration.m;<br />
% Last Revised : March 28, 2009;<br />
% Abstract: This program shows you how to solve a nonlinear equation.<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to solve&#8217;)<br />
disp(&#8217;   a nonlinear equation&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/nonlinearequation.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   April 11, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS<br />
% Solve the nonlinear equation x^3-15*x^2+47*x-33=0<br />
% Define x as a symbol<br />
syms x<br />
% Assigning the fleft hand side o the equation f(x)=0<br />
f=x^3-15*x^2+47*x-33;<br />
%% DISPLAYING INPUTS</p>
<p>disp(&#8217;INPUTS&#8217;)<br />
func=['  The equation to be solved is ' char(f), '=0'];<br />
disp(func)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE</p>
<p>% Finding the solution of the nonlinear equation<br />
soln=solve(f,x);<br />
solnvalue=double(soln);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
for i=1:1:length(solnvalue)<br />
fprintf(&#8217;\nThe solution# %g is %g&#8217;,i,solnvalue(i))<br />
end<br />
disp(&#8217;  &#8216;)</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
Posted in matlab, MATLAB programming, nonlinear equations Tagged: matlab, nonlinear equation <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=325&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/RfdW6KP01H0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/04/11/how-do-i-solve-a-nonlinear-equation-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/04/11/how-do-i-solve-a-nonlinear-equation-in-matlab/</feedburner:origLink></item>
		<item>
		<title>How do I integrate a discrete function in MATLAB?</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/IVXXxzXSI4A/</link>
		<comments>http://autarkaw.wordpress.com/2009/04/03/how-do-i-integrate-a-discrete-function/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 00:31:12 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Integration]]></category>
		<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=321</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to integrate a discrete function.
The MATLAB program link is here.
The HTML version of the MATLAB program is here.
_____________________________________________________
%% HOW [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=321&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to integrate a discrete function.</p>
<p>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/integrationdiscrete.m">here</a>.</p>
<p>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/integrationdiscrete.html">here</a>.</p>
<p>_____________________________________________________</p>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I integrate a discrete function?  Three cases of data are<br />
% discussed.</p>
<p>%% SUMMARY</p>
<p>% Language : MATLAB 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% http://numericalmethods.eng.usf.edu/blog/integrationdiscrete.m;<br />
% Last Revised : April 3, 2009;<br />
% Abstract: This program shows you how to integrate a given discrete function.</p>
<p>clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to integrate&#8217;)<br />
disp(&#8217;   a discrete function&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/integrationdiscrete.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   April 3, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% CASE 1</p>
<p>%% INPUTS</p>
<p>% Integrate the discrete function y from x=1 to 6.5<br />
% with y vs x data given as (1,2), (2,7), (4,16), (6.5,18)<br />
% Defining the x-array<br />
x=[1  2  4  6.5];<br />
% Defining the y-array<br />
y=[2  7  16  18];</p>
<p>%% DISPLAYING INPUTS<br />
disp(&#8217;____________________________________&#8217;)<br />
disp(&#8217;CASE#1&#8242;)<br />
disp(&#8217;LOWER LIMIT AND UPPER LIMITS OF INTEGRATION MATCH x(1) AND x(LAST)&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;INPUTS&#8217;)<br />
disp(&#8217;The x-data is&#8217;)<br />
x<br />
disp(&#8217;The y-data is&#8217;)<br />
y<br />
fprintf(&#8217;  Lower limit of integration, a= %g&#8217;,x(1))<br />
fprintf(&#8217;\n  Upper limit of integration, b= %g&#8217;,x(length(x)))<br />
disp(&#8217; &#8216;)</p>
<p>%% THE CODE</p>
<p>intvalue=trapz(x,y);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
fprintf(&#8217;  Value of integral is = %g&#8217;,intvalue)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;___________________________________________&#8217;)</p>
<p>%% CASE 2</p>
<p>%% INPUTS</p>
<p>% Integrate the discrete function y from x=3 to 6<br />
% with y vs x data given as (1,2), (2,7), (4,16), (6.5,18)<br />
% Defining the x-array<br />
x=[1  2  4  6.5];<br />
% Defining the y-array<br />
y=[2  7  16  18];<br />
% Lower limit of integration, a<br />
a=3;<br />
% Upper limit of integration, b<br />
b=6;<br />
%% DISPLAYING INPUTS</p>
<p>disp(&#8217;CASE#2&#8242;)<br />
disp(&#8217;LOWER LIMIT AND UPPER LIMITS OF INTEGRATION DO not MATCH x(1) AND x(LAST)&#8217;)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;INPUTS&#8217;)<br />
disp(&#8217;The x-data is&#8217;)<br />
x<br />
disp(&#8217;The y-data is&#8217;)<br />
y<br />
fprintf(&#8217;  Lower limit of integration, a= %g&#8217;,a)<br />
fprintf(&#8217;\n  Upper limit of integration, b= %g&#8217;,b)<br />
% Choose how many divisions you want for splining from a to b<br />
n=1000;<br />
fprintf(&#8217;\n  Number of subdivisions used for splining = %g&#8217;,n)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE</p>
<p>xx=a:(b-a)/n:b;<br />
% Using spline to approximate the curve from x(1) to x(last)<br />
yy=spline(x,y,xx);<br />
intvalue=trapz(xx,yy);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
fprintf(&#8217;  Value of integral is = %g&#8217;,intvalue)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;___________________________________________&#8217;)<br />
%% CASE 3</p>
<p>%% INPUTS</p>
<p>% Integrate the discrete function y from x=1 to 6.5<br />
% with y vs x data given as (1,2), (4,16), (2,7), (6.5,18)<br />
% The x-data is not in ascending order<br />
% Defining the x-array<br />
x=[1  4   2 6.5];<br />
% Defining the y-array<br />
y=[2  16  7 18];<br />
% Lower limit of integration, a<br />
a=3;<br />
% Upper limit of integration, b<br />
b=6;<br />
%% DISPLAYING INPUTS</p>
<p>disp(&#8217;CASE#3&#8242;)<br />
disp(&#8217;LOWER LIMIT AND UPPER LIMITS OF INTEGRATION DO not MATCH x(1) AND x(LAST) &#8216;)<br />
disp(&#8217;AND X-DATA IS NOT IN ASCENDING OR DESCENDING ORDER&#8217;)<br />
disp(&#8217;   &#8216;)<br />
disp(&#8217;INPUTS&#8217;)<br />
disp(&#8217;The x-data is&#8217;)<br />
x<br />
disp(&#8217;The y-data is&#8217;)<br />
y<br />
fprintf(&#8217;  Lower limit of integration, a= %g&#8217;,a)<br />
fprintf(&#8217;\n  Upper limit of integration, b= %g&#8217;,b)<br />
% Choose how many divisions you want for splining from a to b<br />
n=1000;<br />
fprintf(&#8217;\n  Number of subdivisions used for splining = %g&#8217;,n)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE<br />
[x,so] = sort(x); % so is the sort order<br />
y = y(so); % y data is now in same order as x data<br />
xx=a:(b-a)/n:b;<br />
% Using spline to approximate the curve from x(1) to x(last)<br />
yy=spline(x,y,xx);<br />
intvalue=trapz(xx,yy);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
fprintf(&#8217;  Value of integral is = %g&#8217;,intvalue)<br />
disp(&#8217;  &#8216;)</p>
<p>____________________________________________________________</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
Posted in Integration, MATLAB programming Tagged: Integration, matlab <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=321&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/IVXXxzXSI4A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/04/03/how-do-i-integrate-a-discrete-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/04/03/how-do-i-integrate-a-discrete-function/</feedburner:origLink></item>
		<item>
		<title>How do I integrate a continuous function in MATLAB</title>
		<link>http://feedproxy.google.com/~r/wordpress/EDie/~3/O1as16zUAdY/</link>
		<comments>http://autarkaw.wordpress.com/2009/03/28/how-do-i-integrate-a-continuous-function-in-matlab/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 19:29:02 +0000</pubDate>
		<dc:creator>Autar Kaw</dc:creator>
				<category><![CDATA[Integration]]></category>
		<category><![CDATA[MATLAB programming]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://autarkaw.wordpress.com/?p=314</guid>
		<description><![CDATA[Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog I show you how to integrate a continuous function.
The MATLAB program link is here.
The HTML version of the MATLAB program is here.
___________________________________________
%% HOW [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=314&subd=autarkaw&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog I show you how to integrate a continuous function.</p>
<p>The MATLAB program link is <a href="http://numericalmethods.eng.usf.edu/blog/integration.m">here</a>.</p>
<p>The HTML version of the MATLAB program is <a href="http://numericalmethods.eng.usf.edu/blog/html/integration.html">here</a>.</p>
<p>___________________________________________</p>
<p>%% HOW DO I DO THAT IN MATLAB SERIES?<br />
% In this series, I am answering questions that students have asked<br />
% me about MATLAB.  Most of the questions relate to a mathematical<br />
% procedure.</p>
<p>%% TOPIC<br />
% How do I integrate a continuous function?</p>
<p>%% SUMMARY</p>
<p>% Language : Matlab 2008a;<br />
% Authors : Autar Kaw;<br />
% Mfile available at<br />
% <a href="http://numericalmethods.eng.usf.edu/blog/integration.m">http://numericalmethods.eng.usf.edu/blog/integration.m</a>;<br />
% Last Revised : March 28, 2009;<br />
% Abstract: This program shows you how to integrate a given function.<br />
clc<br />
clear all</p>
<p>%% INTRODUCTION</p>
<p>disp(&#8217;ABSTRACT&#8217;)<br />
disp(&#8217;   This program shows you how to integrate&#8217;)<br />
disp(&#8217;   a given function &#8216;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;AUTHOR&#8217;)<br />
disp(&#8217;   Autar K Kaw of http://autarkaw.wordpress.com&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;MFILE SOURCE&#8217;)<br />
disp(&#8217;   http://numericalmethods.eng.usf.edu/blog/integration.m&#8217;)<br />
disp(&#8217; &#8216;)<br />
disp(&#8217;LAST REVISED&#8217;)<br />
disp(&#8217;   March 29, 2009&#8242;)<br />
disp(&#8217; &#8216;)</p>
<p>%% INPUTS</p>
<p>% Integrate exp(x)*sin(3*x) from x=2.0 to 8.7<br />
% Define x as a symbol<br />
syms x<br />
% Assigning the function to be differentiated<br />
y=exp(x)*sin(3*x);<br />
% Assigning the lower limit<br />
a=2.0;<br />
% Assigning the upper limit<br />
b=8.7;</p>
<p>%% DISPLAYING INPUTS</p>
<p>disp(&#8217;INPUTS&#8217;)<br />
func=['  The function is to be integrated is ' char(y)];<br />
disp(func)<br />
fprintf(&#8217;  Lower limit of integration, a= %g&#8217;,a)<br />
fprintf(&#8217;\n  Upper limit of integration, b= %g&#8217;,b)<br />
disp(&#8217;  &#8216;)<br />
disp(&#8217;  &#8216;)</p>
<p>%% THE CODE</p>
<p>% Finding the integral using the int command<br />
% Argument 1 is the function to be integrated<br />
% Argument 2 is the variable with respect to which the<br />
%    function is to be integrated &#8211; the dummy variable<br />
% Argument 3 is the lower limit of integration<br />
% Argument 4 is the upper imit of integration<br />
intvalue=int(y,x,a,b);<br />
intvalue=double(intvalue);</p>
<p>%% DISPLAYING OUTPUTS</p>
<p>disp(&#8217;OUTPUTS&#8217;)<br />
fprintf(&#8217;  Value of integral is = %g&#8217;,intvalue)<br />
disp(&#8217;  &#8216;)</p>
<p>_________________________________________________________</p>
<p>This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at <a href="http://numericalmethods.eng.usf.edu/"><span style="color:#000000;">http://numericalmethods.eng.usf.edu</span></a>, the textbook on <a href="http://autarkaw.com/books/numericalmethods/index.html"><span style="color:#1c9bdc;">Numerical Methods with Applications</span></a> available from the <a href="http://stores.lulu.com/kawautar"><span style="color:#1c9bdc;">lulu storefront</span></a>, and the YouTube video lectures available at <a href="http://numericalmethods.eng.usf.edu/videos"><span style="color:#000000;">http://numericalmethods.eng.usf.edu/videos</span></a> <span style="color:#000000;">and <a href="http://www.youtube.com/numericalmethodsguy">http://www.youtube.com/numericalmethodsguy</a></span></p>
<p>Subscribe to the blog via a <a href="http://feeds.feedburner.com/wordpress/EDie"><span style="color:#1c9bdc;">reader</span></a> or <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2178495&amp;loc=en_US"><span style="color:#1c9bdc;">email</span></a> to stay updated with this blog. Let the information follow you.</p>
Posted in Integration, MATLAB programming, Numerical Methods Tagged: Integration, matlab <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autarkaw.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autarkaw.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autarkaw.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autarkaw.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autarkaw.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autarkaw.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autarkaw.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autarkaw.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autarkaw.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autarkaw.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autarkaw.wordpress.com&blog=3780249&post=314&subd=autarkaw&ref=&feed=1" /></div><img src="http://feeds.feedburner.com/~r/wordpress/EDie/~4/O1as16zUAdY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://autarkaw.wordpress.com/2009/03/28/how-do-i-integrate-a-continuous-function-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The numerical methods guy</media:title>
		</media:content>
	<feedburner:origLink>http://autarkaw.wordpress.com/2009/03/28/how-do-i-integrate-a-continuous-function-in-matlab/</feedburner:origLink></item>
	</channel>
</rss>
