From: Didi Cvet on 25 Jun 2010 04:40 Hello I want to approximate cubic curve with straight segments with given tolerance. The point is that I want to have fewer segments where curve is mostly flat and more segments where curve bends. Is there any function in matlab that can do this? Thanks, Didi
From: Bruno Luong on 25 Jun 2010 06:07 "Didi Cvet" <didi_cvet(a)yahoo.com> wrote in message <i01q1e$5sf$1(a)fred.mathworks.com>... > Hello > > I want to approximate cubic curve with straight segments with given tolerance. The point is that I want to have fewer segments where curve is mostly flat and more segments where curve bends. > > Is there any function in matlab that can do this? > > Thanks, > Didi You might check out the BSFK tool on FEX: % Data x = linspace(-2,2); P = randn(4,1); y = polyval(P,x); sigma = 0.05; y = y+sigma*randn(size(y)); pp = BSFK(x,y,2,[],[],struct('Animation',1,'sigma',sigma)) % Bruno
From: John D'Errico on 25 Jun 2010 06:20 "Didi Cvet" <didi_cvet(a)yahoo.com> wrote in message <i01q1e$5sf$1(a)fred.mathworks.com>... > Hello > > I want to approximate cubic curve with straight segments with given tolerance. The point is that I want to have fewer segments where curve is mostly flat and more segments where curve bends. > > Is there any function in matlab that can do this? No. Of course, it may take many breaks to give you the accuracy you desire. I once wrote a function for this purpose. I suppose I can post it on the FEX, though I'll need to clean it up before I do so. For example, on a simple cubic polynomial, how many linear segments will it take to give a maximum error of 0.00001 on the interval [0,1]? fun = @(x) x.^3; pp = optspline(fun,[0 1],.00001,'linear') pp = form: 'pp' breaks: [1x249 double] coefs: [248x2 double] pieces: 248 order: 2 dim: 1 249 break points were required using the scheme in optspline. John
From: Richard Willey on 25 Jun 2010 07:42 Hey there I present a webinar last year titled "Generating Optimal Tables with MATLAB products" which focuses on this precise topic. The "core" of the demo is an optimization algorithm that will automatically place break points to minimize the discrepancy between a parametric model and an LUT which approxoimates said model. You can view the webinar at: http://www.mathworks.com/company/events/webinars/wbnr40143.html?id=40143&s_cid=sp_e_rw All of the code is available at: http://www.mathworks.com/matlabcentral/fileexchange/26021-optimizing-breakpoints-for-tables The demo uses a 2D lookup table to approximate a surface, however, it can be easily modified for curves. Please note: This is a pretty dumb "brute force" solution. You can improve convergence time considerably if you choose some intelligent starting conditions. (Inflection points on the curve are often a good place to start) regards, Richard "Didi Cvet" <didi_cvet(a)yahoo.com> wrote in message news:i01q1e$5sf$1(a)fred.mathworks.com... > Hello > > I want to approximate cubic curve with straight segments with given > tolerance. The point is that I want to have fewer segments where curve is > mostly flat and more segments where curve bends. > Is there any function in matlab that can do this? > > Thanks, > Didi >
|
Pages: 1 Prev: xlsread function does not work in Linux environment Next: Using light on specific object |