MATLAB Answers

Exponential Piecewise function creation.

11 views (last 30 days)
David Cook
David Cook on 24 Sep 2020
Edited: John D'Errico on 25 Sep 2020
Hey everyone, I'm new, not very well-versed in mathmatics, but hopefully someone can help me.
My data is currently:
x = [10 20 30 40 50 60 70 80 90 100]
y = [1000000 3000000 6000000 10000000 30000000 60000000 100000000 300000000 600000000 1000000000]
I am trying to find an exponential piecewise function that will fit each interval. So a function for the line between 0 and 10 that is always increasing exponentially, then a new exponential function from 10 to 20 and so on.
I have entered a spline command and found the coefficients, but I do not know where to go from there.
I know this is probably a simple question, but any and all help would be greatly appreciated.

  0 Comments

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 24 Sep 2020
A spline is not a piecewise exponential function, so using spline directly would be a waste of time, IF you truly need a piecewise exponential.
I think the valid question is why do you think you need a piecewise exponential function? Is that because your data seems to be exponentially increasing?
log10(y)
ans =
6 6.4771 6.7782 7 7.4771 7.7782 8 8.4771 8.7782 9
In that case, just fit a spline to the LOG of y. For example:
spl = spline(x,log10(y));
Now, if you want to predict any intermediate points, this is trivial.
10.^fnval(spl,42)
ans =
1.2069e+07

  3 Comments

David Cook
David Cook on 24 Sep 2020
This all works and I can find the intermediate points after downloading the toolbox.
I want my data to be increasing on their own exponential trajectory between each 10s value of x. Is there a way to pull out a function that demonstrates that? It would have to be a piecewise I assume because of the different trajectories.
I can use the commands you gave to help find when x = 9, y would be 878490. I am looking for a piecewise function so if I plug 32 into the equation, I would have to use the specific exponential tradjectory between 30 and 40 to find y at 6541000.
When plotting the graph, I can select basic fitting in tools. When I select linear, 4th or 5th degree polynomials, it shows an equation. When I select spline there is no such equation. Would there be a way to find that equation where I can put in any x from 0-100 and recieve y from anywhere between 0-1000000000?
Thank you for putting up with my limited knowledge.
Walter Roberson
Walter Roberson on 24 Sep 2020
spline() creates a piecewise polynomial (pp) . You can use ppval() on spline() of the log of the data, feeding in 32, and it will automatically predict the log of y at that location. Or you can use unmkpp() to get at the details of the breaks and coefficients, and then replicate the code that ppval() already does.
John D'Errico
John D'Errico on 25 Sep 2020
I think you do not understand.
Computing a piecewise exponential is not a trivial thing to do, IF you wish the curve to be a nice smooth thing. And I would guess that what you would not want is some nasty looking thing with sharp corners in it.
Years ago, I recall reading papers on twice differentiable exponential interpolating splines. These were often called tension splines, because the spline allowed you to control the shape using a tension parameter. However, those codes were not totally simple to write. (Not difficult, as I wrote codes for them many years ago, written in both APL and in MATLAB, and as I think, even in Fortran.) It is not just a simple exponential function though, at least not if you want something that does not have corners in it at every data point.
(Note that you can formulate a tension spline as the solution to a different differential equation than applies for a classic interpolating spline. It is close, but the tension parameter introduces hyperbolic functions into the solution. So not simply exponential but using exponential functions.)
On the curve you show of course, one simple exponential will fit through everything perfectly.
As it is, I showed exactly how to compute any point along the curve. You have no need to know how to write the function. Just use the code I wrote.
If you want something more complicated than that, where you can write down the actual functions in each segment, then you need to learn about exponential splines, and how to write the code yourself. I won't write it for you. Those codes were never really that useful, and always more of a problem than I wanted to deal with. You also needed to deal with numerical problems, as you should always expect with any exponential.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!