<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208</link>
    <title>MATLAB Central Newsreader - An Interesting Real-World Problem...</title>
    <description>Feed for thread: An Interesting Real-World Problem...</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 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.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 02 Jul 2009 18:34:01 -0400</pubDate>
      <title>An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662313</link>
      <author>Geoffrey Akien</author>
      <description>I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related!  I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&lt;br&gt;
I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
(wish I could include this in the post but never mind)&lt;br&gt;
&lt;br&gt;
Because the data is quite noisy (and not random) this is quite awkward.  In that picture there are about 5000 points.  You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner).  Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&lt;br&gt;
I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it.  This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change.  However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&lt;br&gt;
Any other good suggestions?&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
&lt;br&gt;
Geoff</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 18:54:16 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662319</link>
      <author>Adam Chapman</author>
      <description>On Jul 2, 7:34&#160;pm, &quot;Geoffrey Akien&quot; &amp;lt;geoff.ak...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related! &#160;I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Because the data is quite noisy (and not random) this is quite awkward. &#160;In that picture there are about 5000 points. &#160;You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner). &#160;Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it. &#160;This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change. &#160;However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Any other good suggestions?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Geoff&lt;br&gt;
&lt;br&gt;
is the sharp drop always at the same gradient? Im thinking a step&lt;br&gt;
function might be adequate</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 18:55:40 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662320</link>
      <author>Adam Chapman</author>
      <description>On Jul 2, 7:34&#160;pm, &quot;Geoffrey Akien&quot; &amp;lt;geoff.ak...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related! &#160;I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Because the data is quite noisy (and not random) this is quite awkward. &#160;In that picture there are about 5000 points. &#160;You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner). &#160;Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it. &#160;This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change. &#160;However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Any other good suggestions?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Geoff&lt;br&gt;
&lt;br&gt;
Is the gradient of the sharp drop always the same? Im thinking a&lt;br&gt;
macauley step function might be useful</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 19:00:04 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662323</link>
      <author>Stan Bischof</author>
      <description>Geoffrey Akien &amp;lt;geoff.akien@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out &lt;br&gt;
&amp;gt; the dramatic change in gradient of:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
If you are looking for the &quot;edge&quot; and your data is always about the same shape&lt;br&gt;
as the picture that you have then I would suggest that your best answer&lt;br&gt;
would be the same as you would get from pencil-and-paper:&lt;br&gt;
&lt;br&gt;
I would draw three lines to model this data on paper, and the intersections&lt;br&gt;
of those three lines would bound the regions. The three lines would be the&lt;br&gt;
best fits in the three regions so in this case a upward sloped line,&lt;br&gt;
then a downward sloped line and then a flat line.&lt;br&gt;
&lt;br&gt;
Do exactly the same on your computer by modeling it with a&lt;br&gt;
piece-wise linear curve fit. You could chunk out the least-squares&lt;br&gt;
analytic solution but there's likely a piecewise linear&lt;br&gt;
function in Matlab curve-fitting toolbox.&lt;br&gt;
&lt;br&gt;
A linear spline fit would be about the same thing and then your control&lt;br&gt;
points would be the corners.&lt;br&gt;
&lt;br&gt;
Stan</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 19:16:59 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662333</link>
      <author>Rune Allnor</author>
      <description>On 2 Jul, 20:34, &quot;Geoffrey Akien&quot; &amp;lt;geoff.ak...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related! &#160;I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Because the data is quite noisy (and not random) this is quite awkward. &#160;In that picture there are about 5000 points. &#160;You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner). &#160;Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it. &#160;This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change. &#160;However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Any other good suggestions?&lt;br&gt;
&lt;br&gt;
Don't know about 'good', but at least a suggestion:&lt;br&gt;
&lt;br&gt;
1) Use a 5-7 pt median filter to get rid of noise&lt;br&gt;
2) Differentiate result&lt;br&gt;
3) Integrate twice&lt;br&gt;
4) Determine the threshold as where the cumulative&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;sum reaches, say, 99% of max.&lt;br&gt;
&lt;br&gt;
Or something like that.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 20:11:49 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662356</link>
      <author>TideMan</author>
      <description>On Jul 3, 6:34&#160;am, &quot;Geoffrey Akien&quot; &amp;lt;geoff.ak...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related! &#160;I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Because the data is quite noisy (and not random) this is quite awkward. &#160;In that picture there are about 5000 points. &#160;You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner). &#160;Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it. &#160;This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change. &#160;However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Any other good suggestions?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Geoff&lt;br&gt;
&lt;br&gt;
I'd use orthogonal wavelet decomposition.  Empirical mode&lt;br&gt;
decomposition is another alternative.&lt;br&gt;
Here's a web page where I show how you can apply wavelet decomposition&lt;br&gt;
to a signal similar to yours to extract information about the signal&lt;br&gt;
at different timescales:&lt;br&gt;
&lt;a href=&quot;http://www.tideman.co.nz/Salalah/OrthWaveDecomp.html&quot;&gt;http://www.tideman.co.nz/Salalah/OrthWaveDecomp.html&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 21:09:02 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662379</link>
      <author>John D'Errico</author>
      <description>&quot;Geoffrey Akien&quot; &amp;lt;geoff.akien@gmail.com&amp;gt; wrote in message &amp;lt;h2iuip$nm2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I've been using MATLAB for around 6 months now, and only now have I needed to do something that is actually mathematically-related!  I'm a chemist, so high-level maths is not my strong point.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have some real-world data that I'd like to pick out the dramatic change in gradient of:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.flickr.com/photos/40058045@N07/3681613485/&quot;&gt;http://www.flickr.com/photos/40058045@N07/3681613485/&lt;/a&gt;&lt;br&gt;
&amp;gt; (wish I could include this in the post but never mind)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Because the data is quite noisy (and not random) this is quite awkward.  In that picture there are about 5000 points.  You cannot smooth too much (in practice &amp;gt;300) without losing the information about the point at which the gradient changes (the smoothed data starts to cut the corner).  Even when the data is smoothed, the presence of non-random noise means that the &quot;flat&quot; part of the curve is not actually flat, and there are several stationary points (calculated thanks to STATIONARY from FEX) along that flat part.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I've also tried fitting a least-squares linear regression using POLYFIT for each of the data points with ~500 points either side of it.  This was with the aim of picking out the part of the graph with the lowest R2 value - this I assumed would represent the fast gradient change.  However, this still does not pick out the right point, selecting a point about 0.1 hours before it should be, and I can't think why this is the case.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any other good suggestions?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Geoff&lt;br&gt;
&lt;br&gt;
I'd use my slmtools. It is a least squares spline&lt;br&gt;
tool that can be constrained to have various&lt;br&gt;
properties.&lt;br&gt;
&lt;br&gt;
You can force it to be a constant function above&lt;br&gt;
a certain point, and monotone decreasing above&lt;br&gt;
another point. Throw enough knots at the curve&lt;br&gt;
to be able to resolve the break, and then constrain&lt;br&gt;
it to behave as you know it should.&lt;br&gt;
&lt;br&gt;
Alternatively, use the ability of this tool to fit a&lt;br&gt;
piecewise linear least squares function, where it&lt;br&gt;
will then choose the location of the break points&lt;br&gt;
to best fit the data. It can use all of the abilities&lt;br&gt;
to constrain the curve shape as the cubic version.&lt;br&gt;
&lt;br&gt;
The call in the latter case might look like &lt;br&gt;
&lt;br&gt;
model = slmengine(x,y,'knots',4,'rightslope',0, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'degree',1,'interiorknots','free','plot','on');&lt;br&gt;
&lt;br&gt;
1. This fits the curve as a piecewise linear spline,&lt;br&gt;
with exactly 3 segments (therefore 4 knots).&lt;br&gt;
&lt;br&gt;
2. It forces the piece on the right end to have a&lt;br&gt;
zero slope, i.e. it will be a constant segment.&lt;br&gt;
&lt;br&gt;
3. The placement of the middle two knots will be&lt;br&gt;
chosen by the tool itself. (It uses fmincon, so you&lt;br&gt;
will need the optimization toolbox.)&lt;br&gt;
&lt;br&gt;
4. It plots the data and the curve overlaid upon it.&lt;br&gt;
&lt;br&gt;
To fit the curve using a cubic spline, I might have&lt;br&gt;
tried something vaguely like this instead,&lt;br&gt;
&lt;br&gt;
model = slmengine(x,y,'knots',20,'rightslope',0, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'degree',3,'plot','on','decreasing',[1.3,max(x)], ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'concavedown',[min(x),1.4]);&lt;br&gt;
&lt;br&gt;
1. This fits a curve that has 20 knots, equally spaced.&lt;br&gt;
Just use a lot of knots here, then as I said, constrain&lt;br&gt;
the curve to do as you expect.&lt;br&gt;
&lt;br&gt;
2. Build it as a C2 cubic spline.&lt;br&gt;
&lt;br&gt;
3. Plot the results.&lt;br&gt;
&lt;br&gt;
4. Make the curve a monotone decreasing function&lt;br&gt;
above x = 1.3.&lt;br&gt;
&lt;br&gt;
5. Force it to have a non-positive second derivative&lt;br&gt;
below x = 1.4.&lt;br&gt;
&lt;br&gt;
As I said, it will require the optimization toolbox.&lt;br&gt;
Find SLM for download from the file exchange. There&lt;br&gt;
are an extensive set of examples to show how it can&lt;br&gt;
be used there.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/24443&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/24443&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 03 Jul 2009 17:25:03 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662535</link>
      <author>Geoffrey Akien</author>
      <description>Alright!  SLMtools worked a treat with the piece-wise linear fit - I got exactly what I wanted out of it.  Thanks!</description>
    </item>
    <item>
      <pubDate>Fri, 03 Jul 2009 19:17:01 -0400</pubDate>
      <title>Re: An Interesting Real-World Problem...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255208#662543</link>
      <author>John D'Errico</author>
      <description>&quot;Geoffrey Akien&quot; &amp;lt;geoff.akien@gmail.com&amp;gt; wrote in message &amp;lt;h2letf$nbb$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Alright!  SLMtools worked a treat with the piece-wise linear fit - I got exactly what I wanted out of it.  Thanks!&lt;br&gt;
&lt;br&gt;
Good. If you find you need to provide starting values&lt;br&gt;
for the knots to get convergence, just pass them in as&lt;br&gt;
a vector for the knots parameter.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

