Results 1 to 8 of 8

Math Help - Findind function y=f(x) to for piecewise linear functions

  1. #1
    Junior Member
    Joined
    Jul 2005
    Posts
    25

    Findind function y=f(x) to for piecewise linear functions

    I am looking for way(s) of finding a general method to solve the following problem:

    Given certain piecewise linear functions y=ki * x, how to find a general function y=f(x) that, error of f(x) to these piecewise lines are minimum?

    For example, on [-1,0) is y=x, on [0,1] is y=2x, how to find a function y=f(x) on [-1,1] that has least quare root of errors.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Site Founder MathGuru's Avatar
    Joined
    Mar 2005
    From
    San Diego
    Posts
    478
    Awards
    1

    Using a polynomial to represent piecewise functions

    A polynomial can pretty accurately fit piecewise functions.

    Excel can do a polynomial up to 6 degrees (x^6 - x^5 . . . . ) The higher the degree polynomial the better the fit.

    I used a 6 degree polynomial for the case you described in your posting, and came up with an R^2 value pretty close to 1. Check out the attached files and see if this helps you.
    Attached Thumbnails Attached Thumbnails Findind function y=f(x) to for piecewise linear functions-piecewise.jpg  
    Attached Files Attached Files
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Site Founder Math Help's Avatar
    Joined
    Apr 2005
    Posts
    171

    Polynomial representation

    I think that Maple and other math software will automatically generate polynomials to represent piecewise functions up to the degree of your choice. Remember the higher the degree of the polynomial the more accurate the curve will be. As you can see in the previous post the curve does not go through 0,0. In excel as you are adding the trendline, you can choose to force the curve through 0,0.

    Good luck
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Junior Member
    Joined
    Jul 2005
    Posts
    25
    Thanks for the help! However, this topic is for theorectical study purpose, that a general formula is prefered. I am looking for analytical tool that can solve this kind of problem in general. Not sure if Variation calculas, Integeral equations, or partial differential equations could be of help here, are there any papers or books touch on such topic?

    In real world of control, models can be represented in piecewise linear models and controller based on such kind of model are hard to design. However, if a general function to approximate these piecewise models is available, in analytical form, things may get easier.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    hpe
    hpe is offline
    Member hpe's Avatar
    Joined
    Apr 2005
    Posts
    158
    Quote Originally Posted by WangTaoSG
    I am looking for analytical tool that can solve this kind of problem in general.
    The special piecewise linear function f(x) = max(0,x) may be approximated by the smooth function <br />
g(x) = (\sqrt{\epsilon^2 + x^2}+x)/2<br />
with arbitrary  \epsilon > 0. General piecewise linear functions can then be approximated as superpositions of this function. An example is shown in the picture, with \epsilon = 0.1.
    Attached Thumbnails Attached Thumbnails Findind function y=f(x) to for piecewise linear functions-piecewise.bmp  
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member
    Joined
    Jul 2005
    Posts
    25

    May I have more details on your topic

    Thank you hpe! Your reply is very interesting, sorry to miss it for so many days! Is there any paper touching on this subject in depth, or would it be so trouble to provide more details...
    Follow Math Help Forum on Facebook and Google+

  7. #7
    hpe
    hpe is offline
    Member hpe's Avatar
    Joined
    Apr 2005
    Posts
    158
    Quote Originally Posted by WangTaoSG
    Thank you hpe! Your reply is very interesting, sorry to miss it for so many days! Is there any paper touching on this subject in depth, or would it be so trouble to provide more details...
    Suppose you want to approximate a piecewise linear function that has corners at a_1 < a_2 <  \dots < a_n and that the function is given by f(x) = k_0x + b for x<a_1, continuing with slope k_1 for a_1 < x < a_2, slope k_2 for a_2 < x < a_3 and so on.

    Fix the constant  \epsilon > 0 and set  g(x) = (\sqrt{\epsilon^2 + x^2}+ x)/2 as before.

    Then the function \tilde f(x) = k_0 x + b + \sum_{i=1}^n (k_i - k_{i-1})g(x-a_i) does a reasonable job. If n is large and the  a_i are closely spaced, you have to choose  \epsilon sufficiently small.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Junior Member
    Joined
    Jul 2005
    Posts
    25

    I start to understand...

    and I believe it is the one I am looking for, but how do you come up with this solution, very impressive indeed!

    Thanks very much again, HPE!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 14
    Last Post: October 7th 2011, 10:45 PM
  2. Heaviside/Unit Step Function and other piecewise functions
    Posted in the Differential Equations Forum
    Replies: 2
    Last Post: November 19th 2010, 05:48 PM
  3. Piecewise functions
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: March 23rd 2010, 03:08 PM
  4. piecewise linear approx?
    Posted in the Advanced Applied Math Forum
    Replies: 0
    Last Post: March 3rd 2010, 12:11 AM
  5. Piecewise Functions
    Posted in the Calculus Forum
    Replies: 0
    Last Post: September 29th 2009, 10:02 PM

Search Tags


/mathhelpforum @mathhelpforum