<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623</link>
    <title>MATLAB Central Newsreader - Spline ,Histopolation or Histospline - Matlab</title>
    <description>Feed for thread: Spline ,Histopolation or Histospline - Matlab</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.es/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 08 Jul 2009 15:53:01 +0000</pubDate>
      <title>Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#663625</link>
      <author>Paul Meissner</author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I have a very tricky problem, I want to create an interpolation of a Step-Function. The problem is that the interpolation should keep the condition of area-preserving for every single step. This sounds like a histopolation, does it? Using Google (search: histopolation, histospline) had shown many theoretical abstracts but no Matlab-code. I found only a code-example for Mathematica but at all this is not working for me. (The spline is to "nervous"(rippled) for making a good interpolation)  &lt;br&gt;
&lt;br&gt;
I hope you can give me an advice, how to make such an interpolation in Matlab. I would also be happy if you know a software which is able to do such an interpolation.&lt;br&gt;
&lt;br&gt;
Best regards,&lt;br&gt;
Paul M.</description>
    </item>
    <item>
      <pubDate>Wed, 08 Jul 2009 16:11:24 +0000</pubDate>
      <title>Re: Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#663631</link>
      <author>John D'Errico</author>
      <description>"Paul Meissner" &amp;lt;magnesit@gmx.at&amp;gt; wrote in message &amp;lt;h32fct$aut$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a very tricky problem, I want to create an interpolation of a Step-Function. The problem is that the interpolation should keep the condition of area-preserving for every single step. This sounds like a histopolation, does it? Using Google (search: histopolation, histospline) had shown many theoretical abstracts but no Matlab-code. I found only a code-example for Mathematica but at all this is not working for me. (The spline is to "nervous"(rippled) for making a good interpolation)  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I hope you can give me an advice, how to make such an interpolation in Matlab. I would also be happy if you know a software which is able to do such an interpolation.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Best regards,&lt;br&gt;
&amp;gt; Paul M.&lt;br&gt;
&lt;br&gt;
So instead of using the spline to interpolate specific&lt;br&gt;
data points, you wish to find a piecewise cubic (C1?&lt;br&gt;
C2?) that reproduces the area in each interval?&lt;br&gt;
&lt;br&gt;
Should be doable. The spline is linear in its parameters.&lt;br&gt;
There will be a minimum energy configuration that&lt;br&gt;
satisfies the areal constraints. I already have such a&lt;br&gt;
constraint in my slm tools, but only for the overall&lt;br&gt;
area of the curve.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Wed, 08 Jul 2009 19:08:02 +0000</pubDate>
      <title>Re: Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#663691</link>
      <author>John D'Errico</author>
      <description>"John D'Errico" &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;h32gfc$d2q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Paul Meissner" &amp;lt;magnesit@gmx.at&amp;gt; wrote in message &amp;lt;h32fct$aut$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have a very tricky problem, I want to create an interpolation of a Step-Function. The problem is that the interpolation should keep the condition of area-preserving for every single step. This sounds like a histopolation, does it? Using Google (search: histopolation, histospline) had shown many theoretical abstracts but no Matlab-code. I found only a code-example for Mathematica but at all this is not working for me. (The spline is to "nervous"(rippled) for making a good interpolation)  &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I hope you can give me an advice, how to make such an interpolation in Matlab. I would also be happy if you know a software which is able to do such an interpolation.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Best regards,&lt;br&gt;
&amp;gt; &amp;gt; Paul M.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So instead of using the spline to interpolate specific&lt;br&gt;
&amp;gt; data points, you wish to find a piecewise cubic (C1?&lt;br&gt;
&amp;gt; C2?) that reproduces the area in each interval?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Should be doable. The spline is linear in its parameters.&lt;br&gt;
&amp;gt; There will be a minimum energy configuration that&lt;br&gt;
&amp;gt; satisfies the areal constraints. I already have such a&lt;br&gt;
&amp;gt; constraint in my slm tools, but only for the overall&lt;br&gt;
&amp;gt; area of the curve.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
Very much hacked together, this uses my lse from the&lt;br&gt;
file exchange. The result is in the form of a SLM&lt;br&gt;
spline. If you wish a pp form, my slm tools include a&lt;br&gt;
converter slm2pp.&lt;br&gt;
&lt;br&gt;
A quick test is all I have time for. In a few days I'll&lt;br&gt;
have time to clean up the code, but not now. Sorry.&lt;br&gt;
I've not even written the help, or cleaned up any&lt;br&gt;
error checks.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
bins = 0:.1:1;&lt;br&gt;
areas  = sqrt(bins(2:end));&lt;br&gt;
areas = areas / sum(areas);&lt;br&gt;
&lt;br&gt;
slm = histospline(bins,areas)&lt;br&gt;
slm = &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;form: 'slm'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;degree: 3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;knots: [11x1 double]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;coef: [11x2 double]&lt;br&gt;
&lt;br&gt;
slmpar(slm,'integral')&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.999999999999997&lt;br&gt;
&lt;br&gt;
plotslm(slm)&lt;br&gt;
&lt;br&gt;
All seems reasonable. &lt;br&gt;
&lt;br&gt;
====================================&lt;br&gt;
function slm = histospline(bins,areas,histstyle,continuity)&lt;br&gt;
% generates a cubic spline that integrates to the given set of areas in each bin&lt;br&gt;
&lt;br&gt;
if (nargin &amp;lt; 3) || isempty(histstyle)&lt;br&gt;
&amp;nbsp;&amp;nbsp;% set the default&lt;br&gt;
&amp;nbsp;&amp;nbsp;histstyle = 'area';&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;% check to see that either 'height' or 'area'&lt;br&gt;
&amp;nbsp;&amp;nbsp;% was provided here.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
if (nargin &amp;lt; 4) || isempty(continuity)&lt;br&gt;
&amp;nbsp;&amp;nbsp;% set the default&lt;br&gt;
&amp;nbsp;&amp;nbsp;continuity = 'C2';&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;% 'C1' or 'C2' are the options.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
x = bins(:);&lt;br&gt;
areas = areas(:);&lt;br&gt;
&lt;br&gt;
nk = length(x);&lt;br&gt;
nc = 2*nk;&lt;br&gt;
if (nk-1) ~= length(areas)&lt;br&gt;
&amp;nbsp;&amp;nbsp;error('HISTOSPLINE:incompatibledata', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'There must be exactly one more bin boundary than area supplied')&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% the knots are just the bin boundaries&lt;br&gt;
dx = diff(x);&lt;br&gt;
&lt;br&gt;
if strcmp(histstyle,'height')&lt;br&gt;
&amp;nbsp;&amp;nbsp;% if the heights were specified, then scale to form an area&lt;br&gt;
&amp;nbsp;&amp;nbsp;areas = areas .* dx;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% Regularizer&lt;br&gt;
% We are integrating the piecewise linear f''(x), as&lt;br&gt;
% a quadratic form in terms of the (unknown) second&lt;br&gt;
% derivatives at the knots.&lt;br&gt;
Mreg=zeros(nk,nk);&lt;br&gt;
Mreg(1,1:2)=[dx(1)/3 , dx(1)/6];&lt;br&gt;
Mreg(nk,nk+[-1 0])=[dx(end)/6 , dx(end)/3];&lt;br&gt;
for i=2:(nk-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;Mreg(i,i+[-1 0 1])=[dx(i-1)/6 , (dx(i-1)+dx(i))/3 , dx(i)/6];&lt;br&gt;
end&lt;br&gt;
% do a matrix square root. cholesky is simplest &amp; ok since regmat is&lt;br&gt;
% positive definite. this way we can write the quadratic form as:&lt;br&gt;
%    s'*r'*r*s,&lt;br&gt;
% where s is the vector of second derivatives at the knots.&lt;br&gt;
Mreg=chol(Mreg);&lt;br&gt;
&lt;br&gt;
% next, write the second derivatives as a function of the&lt;br&gt;
% function values and first derivatives.   s = [sf,sd]*[f;d]&lt;br&gt;
sf = zeros(nk,nk);&lt;br&gt;
sd = zeros(nk,nk);&lt;br&gt;
for i = 1:(nk-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;sf(i,i+[0 1]) = [-1 1].*(6/(dx(i)^2));&lt;br&gt;
&amp;nbsp;&amp;nbsp;sd(i,i+[0 1]) = [-4 -2]./dx(i);&lt;br&gt;
end&lt;br&gt;
sf(nk,nk+[-1 0]) = [1 -1].*(6/(dx(end)^2));&lt;br&gt;
sd(nk,nk+[-1 0]) = [2 4]./dx(end);&lt;br&gt;
Mreg = Mreg*[sf,sd];&lt;br&gt;
rhsreg = zeros(nk,1);&lt;br&gt;
&lt;br&gt;
if strcmp(continuity,'C2')&lt;br&gt;
&amp;nbsp;&amp;nbsp;% C2 continuity across knots&lt;br&gt;
&amp;nbsp;&amp;nbsp;Meq = zeros(nk-2,nc);&lt;br&gt;
&amp;nbsp;&amp;nbsp;rhseq = zeros(nk-2,1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;for i = 1:(nk-2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Meq(i,[i,i+1]) = [6 -6]./(dx(i).^2);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Meq(i,[i+1,i+2]) = Meq(i,[i+1,i+2]) + [6 -6]./(dx(i+1).^2);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Meq(i,nk+[i,i+1]) = [2 4]./dx(i);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Meq(i,nk+[i+1,i+2]) = Meq(i,nk+[i+1,i+2]) + [4 2]./dx(i+1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;% allow the spline to be C1&lt;br&gt;
&amp;nbsp;&amp;nbsp;Meq = zeros(0,nc);&lt;br&gt;
&amp;nbsp;&amp;nbsp;rhseq = zeros(0,1);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% set up the integral equality constraints. We can&lt;br&gt;
% be very lazy here. Simpson's rule over the support&lt;br&gt;
% will be exact, evaluating at each midpoint. Don't&lt;br&gt;
% forget that the effective "stepsize" is actually&lt;br&gt;
% dx(i)/2&lt;br&gt;
Mint = zeros(nk-1,nc);&lt;br&gt;
for i = 1:(nk-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;Mint(i,i+[0 1]) = dx(i)/6;&lt;br&gt;
&amp;nbsp;&amp;nbsp;% the midpoint&lt;br&gt;
&amp;nbsp;&amp;nbsp;Mint(i,i+[0 1 nk nk+1]) = Mint(i,i+[0 1 nk nk+1]) + ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[1/2 , 1/2 , (1/8).*dx(i) , (-1/8).*dx(i)]*4*dx(i)/6;&lt;br&gt;
end&lt;br&gt;
Meq = [Meq;Mint];&lt;br&gt;
rhseq = [rhseq;areas];&lt;br&gt;
&lt;br&gt;
% Solve for the spline coefficients. I could have&lt;br&gt;
% set this up in a quadprog form, but I hacked the&lt;br&gt;
% pieces for this out of slmengine. So lse is&lt;br&gt;
% perfect for the task, since it does not require&lt;br&gt;
% the optimization toolbox and there are no&lt;br&gt;
% inequality constraints. Use the pinv solver in lse.&lt;br&gt;
solverflag = 'pinv';&lt;br&gt;
coef = lse(Mreg,rhsreg,Meq,rhseq,solverflag);&lt;br&gt;
&lt;br&gt;
% output in a slm form&lt;br&gt;
slm.form = 'slm';&lt;br&gt;
slm.degree = 3;&lt;br&gt;
slm.knots = bins';&lt;br&gt;
slm.coef = reshape(coef,nk,2);&lt;br&gt;
&lt;br&gt;
=================================</description>
    </item>
    <item>
      <pubDate>Thu, 09 Jul 2009 11:13:02 +0000</pubDate>
      <title>Re: Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#663897</link>
      <author>Paul Meissner</author>
      <description>"John D'Errico" &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;h32qqi$l71$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "John D'Errico" &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;h32gfc$d2q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; "Paul Meissner" &amp;lt;magnesit@gmx.at&amp;gt; wrote in message &amp;lt;h32fct$aut$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have a very tricky problem, I want to create an interpolation of a Step-Function. The problem is that the interpolation should keep the condition of area-preserving for every single step. This sounds like a histopolation, does it? Using Google (search: histopolation, histospline) had shown many theoretical abstracts but no Matlab-code. I found only a code-example for Mathematica but at all this is not working for me. (The spline is to "nervous"(rippled) for making a good interpolation)  &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I hope you can give me an advice, how to make such an interpolation in Matlab. I would also be happy if you know a software which is able to do such an interpolation.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Best regards,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Paul M.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; So instead of using the spline to interpolate specific&lt;br&gt;
&amp;gt; &amp;gt; data points, you wish to find a piecewise cubic (C1?&lt;br&gt;
&amp;gt; &amp;gt; C2?) that reproduces the area in each interval?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Should be doable. The spline is linear in its parameters.&lt;br&gt;
&amp;gt; &amp;gt; There will be a minimum energy configuration that&lt;br&gt;
&amp;gt; &amp;gt; satisfies the areal constraints. I already have such a&lt;br&gt;
&amp;gt; &amp;gt; constraint in my slm tools, but only for the overall&lt;br&gt;
&amp;gt; &amp;gt; area of the curve.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; John&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Very much hacked together, this uses my lse from the&lt;br&gt;
&amp;gt; file exchange. The result is in the form of a SLM&lt;br&gt;
&amp;gt; spline. If you wish a pp form, my slm tools include a&lt;br&gt;
&amp;gt; converter slm2pp.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A quick test is all I have time for. In a few days I'll&lt;br&gt;
&amp;gt; have time to clean up the code, but not now. Sorry.&lt;br&gt;
&amp;gt; I've not even written the help, or cleaned up any&lt;br&gt;
&amp;gt; error checks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; bins = 0:.1:1;&lt;br&gt;
&amp;gt; areas  = sqrt(bins(2:end));&lt;br&gt;
&amp;gt; areas = areas / sum(areas);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; slm = histospline(bins,areas)&lt;br&gt;
&amp;gt; slm = &lt;br&gt;
&amp;gt;       form: 'slm'&lt;br&gt;
&amp;gt;     degree: 3&lt;br&gt;
&amp;gt;      knots: [11x1 double]&lt;br&gt;
&amp;gt;       coef: [11x2 double]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; slmpar(slm,'integral')&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt;          0.999999999999997&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plotslm(slm)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; All seems reasonable. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ====================================&lt;br&gt;
&amp;gt; function slm = histospline(bins,areas,histstyle,continuity)&lt;br&gt;
&amp;gt; % generates a cubic spline that integrates to the given set of areas in each bin&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if (nargin &amp;lt; 3) || isempty(histstyle)&lt;br&gt;
&amp;gt;   % set the default&lt;br&gt;
&amp;gt;   histstyle = 'area';&lt;br&gt;
&amp;gt; else&lt;br&gt;
&amp;gt;   % check to see that either 'height' or 'area'&lt;br&gt;
&amp;gt;   % was provided here.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; if (nargin &amp;lt; 4) || isempty(continuity)&lt;br&gt;
&amp;gt;   % set the default&lt;br&gt;
&amp;gt;   continuity = 'C2';&lt;br&gt;
&amp;gt; else&lt;br&gt;
&amp;gt;   % 'C1' or 'C2' are the options.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = bins(:);&lt;br&gt;
&amp;gt; areas = areas(:);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; nk = length(x);&lt;br&gt;
&amp;gt; nc = 2*nk;&lt;br&gt;
&amp;gt; if (nk-1) ~= length(areas)&lt;br&gt;
&amp;gt;   error('HISTOSPLINE:incompatibledata', ...&lt;br&gt;
&amp;gt;     'There must be exactly one more bin boundary than area supplied')&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % the knots are just the bin boundaries&lt;br&gt;
&amp;gt; dx = diff(x);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if strcmp(histstyle,'height')&lt;br&gt;
&amp;gt;   % if the heights were specified, then scale to form an area&lt;br&gt;
&amp;gt;   areas = areas .* dx;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Regularizer&lt;br&gt;
&amp;gt; % We are integrating the piecewise linear f''(x), as&lt;br&gt;
&amp;gt; % a quadratic form in terms of the (unknown) second&lt;br&gt;
&amp;gt; % derivatives at the knots.&lt;br&gt;
&amp;gt; Mreg=zeros(nk,nk);&lt;br&gt;
&amp;gt; Mreg(1,1:2)=[dx(1)/3 , dx(1)/6];&lt;br&gt;
&amp;gt; Mreg(nk,nk+[-1 0])=[dx(end)/6 , dx(end)/3];&lt;br&gt;
&amp;gt; for i=2:(nk-1)&lt;br&gt;
&amp;gt;   Mreg(i,i+[-1 0 1])=[dx(i-1)/6 , (dx(i-1)+dx(i))/3 , dx(i)/6];&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; % do a matrix square root. cholesky is simplest &amp; ok since regmat is&lt;br&gt;
&amp;gt; % positive definite. this way we can write the quadratic form as:&lt;br&gt;
&amp;gt; %    s'*r'*r*s,&lt;br&gt;
&amp;gt; % where s is the vector of second derivatives at the knots.&lt;br&gt;
&amp;gt; Mreg=chol(Mreg);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % next, write the second derivatives as a function of the&lt;br&gt;
&amp;gt; % function values and first derivatives.   s = [sf,sd]*[f;d]&lt;br&gt;
&amp;gt; sf = zeros(nk,nk);&lt;br&gt;
&amp;gt; sd = zeros(nk,nk);&lt;br&gt;
&amp;gt; for i = 1:(nk-1)&lt;br&gt;
&amp;gt;   sf(i,i+[0 1]) = [-1 1].*(6/(dx(i)^2));&lt;br&gt;
&amp;gt;   sd(i,i+[0 1]) = [-4 -2]./dx(i);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; sf(nk,nk+[-1 0]) = [1 -1].*(6/(dx(end)^2));&lt;br&gt;
&amp;gt; sd(nk,nk+[-1 0]) = [2 4]./dx(end);&lt;br&gt;
&amp;gt; Mreg = Mreg*[sf,sd];&lt;br&gt;
&amp;gt; rhsreg = zeros(nk,1);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if strcmp(continuity,'C2')&lt;br&gt;
&amp;gt;   % C2 continuity across knots&lt;br&gt;
&amp;gt;   Meq = zeros(nk-2,nc);&lt;br&gt;
&amp;gt;   rhseq = zeros(nk-2,1);&lt;br&gt;
&amp;gt;   &lt;br&gt;
&amp;gt;   for i = 1:(nk-2)&lt;br&gt;
&amp;gt;     Meq(i,[i,i+1]) = [6 -6]./(dx(i).^2);&lt;br&gt;
&amp;gt;     Meq(i,[i+1,i+2]) = Meq(i,[i+1,i+2]) + [6 -6]./(dx(i+1).^2);&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     Meq(i,nk+[i,i+1]) = [2 4]./dx(i);&lt;br&gt;
&amp;gt;     Meq(i,nk+[i+1,i+2]) = Meq(i,nk+[i+1,i+2]) + [4 2]./dx(i+1);&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt; else&lt;br&gt;
&amp;gt;   % allow the spline to be C1&lt;br&gt;
&amp;gt;   Meq = zeros(0,nc);&lt;br&gt;
&amp;gt;   rhseq = zeros(0,1);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % set up the integral equality constraints. We can&lt;br&gt;
&amp;gt; % be very lazy here. Simpson's rule over the support&lt;br&gt;
&amp;gt; % will be exact, evaluating at each midpoint. Don't&lt;br&gt;
&amp;gt; % forget that the effective "stepsize" is actually&lt;br&gt;
&amp;gt; % dx(i)/2&lt;br&gt;
&amp;gt; Mint = zeros(nk-1,nc);&lt;br&gt;
&amp;gt; for i = 1:(nk-1)&lt;br&gt;
&amp;gt;   Mint(i,i+[0 1]) = dx(i)/6;&lt;br&gt;
&amp;gt;   % the midpoint&lt;br&gt;
&amp;gt;   Mint(i,i+[0 1 nk nk+1]) = Mint(i,i+[0 1 nk nk+1]) + ...&lt;br&gt;
&amp;gt;     [1/2 , 1/2 , (1/8).*dx(i) , (-1/8).*dx(i)]*4*dx(i)/6;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; Meq = [Meq;Mint];&lt;br&gt;
&amp;gt; rhseq = [rhseq;areas];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Solve for the spline coefficients. I could have&lt;br&gt;
&amp;gt; % set this up in a quadprog form, but I hacked the&lt;br&gt;
&amp;gt; % pieces for this out of slmengine. So lse is&lt;br&gt;
&amp;gt; % perfect for the task, since it does not require&lt;br&gt;
&amp;gt; % the optimization toolbox and there are no&lt;br&gt;
&amp;gt; % inequality constraints. Use the pinv solver in lse.&lt;br&gt;
&amp;gt; solverflag = 'pinv';&lt;br&gt;
&amp;gt; coef = lse(Mreg,rhsreg,Meq,rhseq,solverflag);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % output in a slm form&lt;br&gt;
&amp;gt; slm.form = 'slm';&lt;br&gt;
&amp;gt; slm.degree = 3;&lt;br&gt;
&amp;gt; slm.knots = bins';&lt;br&gt;
&amp;gt; slm.coef = reshape(coef,nk,2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; =================================&lt;br&gt;
&lt;br&gt;
Hallo John,&lt;br&gt;
&lt;br&gt;
I am very happy that you answered so quick! Thank you for your code example!  I had downloaded your SLM Toolpak und your LSE function. Nice work! &lt;br&gt;
&lt;br&gt;
I have uploaded two examples (h**p://yfrog.com/09ex1ktljx), both based on the same data. By viewing the examples you will see my problem, the first picture is made by your code-example, works fine, but is not following the shape. The second picture shows a spline which is hand-drawn by me ;=) (sorry it is not exact and the last section spline is really bad, but it should be enough for illustrating the problem). &lt;br&gt;
&lt;br&gt;
Maybe you are interested why I need such a spline? I study Mineral-Processing and therefore I have to analyse some data for my master-thesis This data represents the quality of separating mineral grains by there characteristics. An old DIN standard exists of creating such a diagram by smoothing the step-function with a spline (area-preserving). In practise it is necessary to draw the spline by hand, there is no automated standard-conform solution available. Everyone is drawing the splines in an other way and so you cannot reproduce the analysis again.&lt;br&gt;
&lt;br&gt;
Thanking you in anticipation,&lt;br&gt;
&lt;br&gt;
Paul M.&lt;br&gt;
&amp;nbsp;&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Thu, 09 Jul 2009 12:44:02 +0000</pubDate>
      <title>Re: Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#663924</link>
      <author>John D'Errico</author>
      <description>"Paul Meissner" &amp;lt;magnesit@gmx.at&amp;gt; wrote in message &amp;lt;h34jbu$27q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; Hallo John,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am very happy that you answered so quick! Thank you for your code example!  I had downloaded your SLM Toolpak und your LSE function. Nice work! &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have uploaded two examples (h**p://yfrog.com/09ex1ktljx), both based on the same data. By viewing the examples you will see my problem, the first picture is made by your code-example, works fine, but is not following the shape. The second picture shows a spline which is hand-drawn by me ;=) (sorry it is not exact and the last section spline is really bad, but it should be enough for illustrating the problem). &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Maybe you are interested why I need such a spline? I study Mineral-Processing and therefore I have to analyse some data for my master-thesis This data represents the quality of separating mineral grains by there characteristics. An old DIN standard exists of creating such a diagram by smoothing the step-function with a spline (area-preserving). In practise it is necessary to draw the spline by hand, there is no automated standard-conform solution available. Everyone is drawing the splines in an other way and so you cannot reproduce the analysis again.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Hi Paul,&lt;br&gt;
&lt;br&gt;
To be honest, I'd suggest that the best solution is not&lt;br&gt;
to use the code I posted in this thread. It was an&lt;br&gt;
interesting exercise, but not of tremendous value, as&lt;br&gt;
it is not that intelligent. Better is to use a tool that can&lt;br&gt;
employ your knowledge of the system - my SLM tools.&lt;br&gt;
I don't have an explicit area preserving constraint built&lt;br&gt;
in there, although this is an idea that I'll follow up on if&lt;br&gt;
I can think of the proper way to provide that information&lt;br&gt;
to slmengine.&lt;br&gt;
&lt;br&gt;
Using the slm tools, I might specify the midpoints of the&lt;br&gt;
bars from your histogram as your data points. Then use&lt;br&gt;
a monotonicity constraint on the curve, and force it to&lt;br&gt;
be everywhere positive.&lt;br&gt;
&lt;br&gt;
It appears from your figures that you are working with a&lt;br&gt;
cumulative histogram. So the call with slmengine might&lt;br&gt;
look like this:&lt;br&gt;
&lt;br&gt;
S = slmengine(x,y,'plot','on','knots',10,'incr','on', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'leftvalue',0,'rightvalue',100);&lt;br&gt;
&lt;br&gt;
- Thus, I've told it to generate a plot with the data and&lt;br&gt;
the resulting curve overlaid on top.&lt;br&gt;
&lt;br&gt;
- I set the number of knots to be 10, equally spaced along&lt;br&gt;
the curve by default. You may choose more or fewer knots&lt;br&gt;
as you find necessary, but the curve shape itself will often&lt;br&gt;
be more controlled by an intelligent set of constraints&lt;br&gt;
applied by the user.&lt;br&gt;
&lt;br&gt;
- The curve will be a monotone increasing function.&lt;br&gt;
&lt;br&gt;
- It will be everywhere positive, since it is an increasing&lt;br&gt;
function that is zero at the left hand end point of the&lt;br&gt;
domain of the spline.&lt;br&gt;
&lt;br&gt;
- Since this is apparently a cumulative distribution, the&lt;br&gt;
right end point is set to 100%.&lt;br&gt;
&lt;br&gt;
You should find that the curve drawn, while it is not&lt;br&gt;
forced to have the exact areal constraints for each bin&lt;br&gt;
of the histogram, will be quite reasonable. If not, then&lt;br&gt;
only a moderate amount of tweaking should allow a&lt;br&gt;
reasonable fit. For example, you might even choose a&lt;br&gt;
few more knots, then add an extra property to the list,&lt;br&gt;
like this:&lt;br&gt;
&lt;br&gt;
S = slmengine(x,y,'plot','on','knots',15,'incr','on', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'leftvalue',0,'rightvalue',100,'regularization','cross');&lt;br&gt;
&lt;br&gt;
As I said above, if I can think of the proper format&lt;br&gt;
to input data oints to be interpreted as a histogram, I'll&lt;br&gt;
see if I might implement explicit areal constraints in a&lt;br&gt;
future release. Until then, I hope the prescriptive rules&lt;br&gt;
above might be acceptable for your task.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 00:35:05 +0000</pubDate>
      <title>Re: Spline ,Histopolation or Histospline - Matlab</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/255623#690860</link>
      <author>Irma Hernandez</author>
      <description>Dear John,&lt;br&gt;
&lt;br&gt;
I am not sure if my question is related to the one posted by Paul. I am interested in the case where we think in 2d and data is grouped in regions (bins) I want to fit a 2d spline where the conservation of volume is happening in each region. It is sometimes called "thin plate histospline".&lt;br&gt;
&lt;br&gt;
Do you know if there is a matlab code related to this problem? Thanks&lt;br&gt;
&lt;br&gt;
Irma</description>
    </item>
  </channel>
</rss>
