Exponential Piecewise function creation.

12 Ansichten (letzte 30 Tage)
David Cook
David Cook am 24 Sep. 2020
Bearbeitet: John D'Errico am 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.

Akzeptierte Antwort

John D'Errico
John D'Errico am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 25 Sep. 2020
Bearbeitet: John D'Errico am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by