Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Adjusting the recto/curvlinearity of a polynomial fit

  • 23-12-2014 6:10pm
    #1
    Registered Users, Registered Users 2 Posts: 17,154 ✭✭✭✭


    I was wondering if a procedure exists (ideally one that can be programmed in MATLAB) to adjust how curvlinear or rectolinear a polynomial fit is.

    For example:

    Computing 10 points around 0:

    [HTML]apexes = randn(1,11);
    x = [-5 -4 -3 -2 -1 0 1 2 3 4 5];
    plot(x,apexes,'xk');hold on;
    axis([-6 6 -6 6]);[/HTML]

    332591.jpg

    and fitting a 5th order polynomial (for the purpose of demonstration) across a range of x values between -5 and 5 in steps of .01.

    [HTML]x2 = -5:.01:5;
    order = polyfit(x,apexes,5);
    curve = polyval(order,x2);
    plot(x2,curve);[/HTML]

    332592.jpg

    changing the rate of change in x2 to whole units, the fitted curve becomes rectolinear; at least, this is the term I have been using to describe peaks and troughs that have sudden angular change, as opposed to gradual curves.

    [HTML]x2 = -5:1:5;
    order = polyfit(x,apexes,5);
    curve = polyval(order,x2);
    plot(x2,curve);[/HTML]

    332593.jpg

    What I'd now like to do is vary the degree to which the curves are curvelinear and rectolinear in a graded fashion. Is this possible? Fitting higher order polynomials kind of achieves this, but (a) they go a bit wonky once the order excedes the number of datapoints and (b) I'd ideally like a procedure that won't alter the overall curvelength. I would also like something that maintains the number of kinks in the curve, as opposed to, say, simply adjusting the rate of change of x2 for a value between 0 and 1, in which case you get something like this:

    [HTML]x2 = -5:.5:5;
    order = polyfit(x,apexes,5);
    curve = polyval(order,x2);
    plot(x2,curve);[/HTML]

    332597.jpg

    Any help greatly appreciated, I hope I've explained that well!


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 1,852 Mod ✭✭✭✭Michael Collins


    I don't have an answer to your question, but I do have a question about your question!

    It's almost like you're suggesting that the fit itself is changing? I'm guessing you're not because you seem fairly familiar with MATLAB...

    All that's happening is that MATLAB is evaluating the polynomial at fewer points, and hence the curve appears to be (but is not actually) developing corners - which of course a polynomial can never have.

    If you want the actual fit itself to change, you'll need to look at a different interpolation method (splines, for example).


Advertisement