<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://hpclab.ucentral.edu.co/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://hpclab.ucentral.edu.co/wiki/index.php?title=FdcoeffF.m&amp;feed=atom&amp;action=history</id>
		<title>FdcoeffF.m - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://hpclab.ucentral.edu.co/wiki/index.php?title=FdcoeffF.m&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://hpclab.ucentral.edu.co/wiki/index.php?title=FdcoeffF.m&amp;action=history"/>
		<updated>2019-03-26T18:04:41Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.5</generator>

	<entry>
		<id>http://hpclab.ucentral.edu.co/wiki/index.php?title=FdcoeffF.m&amp;diff=3503&amp;oldid=prev</id>
		<title>Mmejia: Created page with &quot;&lt;pre&gt;  function c = fdcoeffF(k,x)  % Compute coefficients for finite difference approximation for the % derivative of order k at xbar based on grid values at points in x. % % ...&quot;</title>
		<link rel="alternate" type="text/html" href="http://hpclab.ucentral.edu.co/wiki/index.php?title=FdcoeffF.m&amp;diff=3503&amp;oldid=prev"/>
				<updated>2014-03-22T13:27:41Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt;  function c = fdcoeffF(k,x)  % Compute coefficients for finite difference approximation for the % derivative of order k at xbar based on grid values at points in x. % % ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function c = fdcoeffF(k,x)&lt;br /&gt;
&lt;br /&gt;
% Compute coefficients for finite difference approximation for the&lt;br /&gt;
% derivative of order k at xbar based on grid values at points in x.&lt;br /&gt;
%&lt;br /&gt;
% This function returns a row vector c of dimension 1 by n, where n=length(x),&lt;br /&gt;
% containing coefficients to approximate u^{(k)}(xbar), &lt;br /&gt;
% the k'th derivative of u evaluated at xbar,  based on n values&lt;br /&gt;
% of u at x(1), x(2), ... x(n).  &lt;br /&gt;
%&lt;br /&gt;
% If U is a column vector containing u(x) at these n points, then &lt;br /&gt;
% c*U will give the approximation to u^{(k)}(xbar).&lt;br /&gt;
%&lt;br /&gt;
% Note for k=0 this can be used to evaluate the interpolating polynomial &lt;br /&gt;
% itself.&lt;br /&gt;
%&lt;br /&gt;
% Requires length(x) &amp;gt; k.  &lt;br /&gt;
% Usually the elements x(i) are monotonically increasing&lt;br /&gt;
% and x(1) &amp;lt;= xbar &amp;lt;= x(n), but neither condition is required.&lt;br /&gt;
% The x values need not be equally spaced but must be distinct.  &lt;br /&gt;
%&lt;br /&gt;
% This program should give the same results as fdcoeffV.m, but for large&lt;br /&gt;
% values of n is much more stable numerically.&lt;br /&gt;
%&lt;br /&gt;
% Based on the program &amp;quot;weights&amp;quot; in &lt;br /&gt;
%   B. Fornberg, &amp;quot;Calculation of weights in finite difference formulas&amp;quot;,&lt;br /&gt;
%   SIAM Review 40 (1998), pp. 685-691.&lt;br /&gt;
%&lt;br /&gt;
% Note: Forberg's algorithm can be used to simultaneously compute the&lt;br /&gt;
% coefficients for derivatives of order 0, 1, ..., m where m &amp;lt;= n-1.&lt;br /&gt;
% This gives a coefficient matrix C(1:n,1:m) whose k'th column gives&lt;br /&gt;
% the coefficients for the k'th derivative.&lt;br /&gt;
%&lt;br /&gt;
% In this version we set m=k and only compute the coefficients for&lt;br /&gt;
% derivatives of order up to order k, and then return only the k'th column&lt;br /&gt;
% of the resulting C matrix (converted to a row vector).  &lt;br /&gt;
% This routine is then compatible with fdcoeffV.   &lt;br /&gt;
% It can be easily modified to return the whole array if desired.&lt;br /&gt;
%&lt;br /&gt;
% From  http://www.amath.washington.edu/~rjl/fdmbook/  (2007)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
n = length(x);&lt;br /&gt;
for ii=1:n&lt;br /&gt;
xbar=x(ii);&lt;br /&gt;
&lt;br /&gt;
if k &amp;gt;= n&lt;br /&gt;
   error('*** length(x) must be larger than k')&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
m = k;   % change to m=n-1 if you want to compute coefficients for all&lt;br /&gt;
         % possible derivatives.  Then modify to output all of C.&lt;br /&gt;
c1 = 1;&lt;br /&gt;
c4 = x(1) - xbar;&lt;br /&gt;
C = zeros(n-1,m+1);&lt;br /&gt;
C(1,1) = 1;&lt;br /&gt;
for i=1:n-1&lt;br /&gt;
  i1 = i+1;&lt;br /&gt;
  mn = min(i,m);&lt;br /&gt;
  c2 = 1;&lt;br /&gt;
  c5 = c4;&lt;br /&gt;
  c4 = x(i1) - xbar;&lt;br /&gt;
  for j=0:i-1&lt;br /&gt;
    j1 = j+1;&lt;br /&gt;
    c3 = x(i1) - x(j1);&lt;br /&gt;
    c2 = c2*c3;&lt;br /&gt;
    if j==i-1&lt;br /&gt;
      for s=mn:-1:1&lt;br /&gt;
        s1 = s+1;&lt;br /&gt;
        C(i1,s1) = c1*(s*C(i1-1,s1-1) - c5*C(i1-1,s1))/c2;&lt;br /&gt;
        end&lt;br /&gt;
      C(i1,1) = -c1*c5*C(i1-1,1)/c2;&lt;br /&gt;
      end&lt;br /&gt;
    for s=mn:-1:1&lt;br /&gt;
      s1 = s+1;&lt;br /&gt;
      C(j1,s1) = (c4*C(j1,s1) - s*C(j1,s1-1))/c3;&lt;br /&gt;
      end&lt;br /&gt;
    C(j1,1) = c4*C(j1,1)/c3;&lt;br /&gt;
    end&lt;br /&gt;
  c1 = c2;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
c(ii,:) = C(:,end)';            % last column of c gives desired row vector&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mmejia</name></author>	</entry>

	</feed>