How to get polynomial equation from continuous curve.

3 次查看(过去 30 天)
I have some arbitrary curve. I don't have its x and y axis discrete value. Can anyone help to develop polynomial equation.

采纳的回答

Sathyamoorthy R
Sathyamoorthy R 2018-8-31
Sorry sir I didn't specify the problem exactly. Is it possible to calculate polynomial of a curve between 900nm to 1100nm in that image?
  3 个评论
John D'Errico
John D'Errico 2018-8-31
Polyfit is a really bad way to fit shapes like that. Really, really bad. Even over the restricted range of 900-1100. What happens is you get obscene oscillations in the tails, when the polynomial is a high enough order that it has any chance of fitting.
Extract the points. Then interpolate with a spline, thus pchip. You can use pchip, and ppval, or just use interp1.
If you absolutely need a function that you can write down in a paper, etc., (why???) then a nonlinear regression, using a Gaussian style model would be reasonable. So you could use the curve fitting toolbox then.
And please stop adding answer after answer. LEARN TO USE COMMENTS!!!!
Walter Roberson
Walter Roberson 2018-8-31
With the resolution of that image, I do not think a polynomial of order higher than 2 can be justified. I would probably just use the data cursor to read off the location of the peak and two places the line touches the axis, and do a three-point quadratic fit and say it was as good as you are going to be able to get. The result will be of little practical use, but fitting to a higher degree would not appear to have any practical use either.
Those are obviously not polynomial peaks; they are plausibly sum of gaussian, though.

请先登录,再进行评论。

更多回答(3 个)

Walter Roberson
Walter Roberson 2018-8-31
If you have an arbitrary curve but do not have the x and y values, then it follows that what you have must be the formula for the curve -- or possibly a function handle that generates y values given x values.
If what you have is the formula, then in general there might not be a finite polynomial corresponding to the curve, and any finite truncation might be infinitely wrong. Consider for example sin(x): any finite representation as a polynomial must go to either +infinity or -infinity as x approaches infinity, but sin(x) never goes outside the range -1 to +1. Any curve that does not go to +/- infinity at +/- infinity cannot have a finite approximating polynomial without being infinitely wrong.
In the case where the endpoints are +/- infinity, you can potentially approximate as a polynomial by taking the taylor or series expansion.
In the case where what you have is a generating function handle, then you can try passing in a symbolic parameter and see if you get a formula out, in which case the above applies. But if the function handle contains comparisons of the input to values then unless the function was very carefully written, the comparisons of the symbolic variable would fail. If that were to occur, then about the best you can do is generate a bunch of points and do a numeric polynomial fit. But if you do not happen to sample in the right places, you could end up with a rather different result than the function actually represents.

John D'Errico
John D'Errico 2018-8-31
编辑:John D'Errico 2018-8-31
As has been pointed out, there is no polynomial equation that will represent any particular curve. However, some curves will be more amenable to this task than others. In the end, you will generally never be able to extract an exact polynomial for any curve, for many good reasons.
If all you have is the curve, thus no points, but just a curve, then you must be able to evaluate it as a function. (Or do you have a picture of a curve? Sigh, so many ambiguities in this question. But IF you have a picture, then essentially, you have points ON that curve.)
So if you have the functional form itself, then you can differentiate it. In that case, then you can generate a (truncated) Taylor series (thus a polynomial), which depending on the function, may have a limited radius of convergence. In any case, any Taylor series will tend to be a poor approximation over a large domain, because you can take/compute only a finite number of terms.
So the simple answer is to just generate that truncated Taylor series. Of course, such an animal will tend to perform poorly out towards the ends of the region of interest, since that is where the terms you dropped by truncating the Taylor series will be most important.
For example, suppose we chose to approximate exp(x), over the interval[-1,1], by a third order truncated Taylor series? This part is easy, since we (should) know that series by heart.
E3 = @(x) 1 + x + x.^2/2 + x.^3/6;
ezplot(E3,[-1,1])
hold on
ezplot(@exp,[-1,1])
So not perfect, but not too bad either.
figure
ezplot(@(x) exp(x) - E3(x),[-1,1])
Looking at the error between the curves, we see it is worst near the ends of the domain. Of course, that is to be expected.
If what you want is a polynomial approximant to some curve that is "equally" valid over a large region of a curve, then you might want to use a minimax approximation. So now, we might wish to find that cubic approximant that minimizes the maximum absolute residual to the true curve. The simplest way to do this is to just use an optimization, on a discretized version of your function. The lazy way out, I know, but trivial to write.
I'll just evaluate the function at 1000 points, then use the max absolute residual.
xvec = linspace(-1,1,1000);
E3obj = @(abcd) max(abs(abcd*xvec.^((0:3)') - exp(xvec)));
You can see the maximum error is roughly 0.05.
E3obj([1 1 1/2 1/6])
ans =
0.0516151617923786
Throw that at fminunc, and we see:
[abcd,fval] = fminunc(E3obj,[1 1 1/2 1/6])
Solver stopped prematurely.
fminunc stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 400 (the default value).
abcd =
0.992671224351005 1.0013572700714 0.546092947890993 0.174121176615138
fval =
0.00733879073932897
So considerably better, with some subtle changes to the coefficients.
E3opt = @(x) abcd(1) + abcd(2)*x + abcd(3)*x.^2 + abcd(4)*x.^3
ezplot(@(x) exp(x) - E3opt(x),[-1,1])
hold on
ezplot(@(x) exp(x) - E3(x),[-1,1])
axis([-1,1,-.05 .05])
grid on
The green curve is the truncated Taylor series residual, the blue curve my approximate minimax version.
Just for kicks though, what polynomial best approximates the curve
y = 1./(1+x.^2)
over the domain [-3,3]? I'll leave that one to the student to play with. Try a nice, high order polynomial if you want some entertainment. It gets even worse if you use a Lagrange interpolating polynomial (a really bad idea there.)

Sathyamoorthy R
Sathyamoorthy R 2018-8-31
Thank you so much sir. I have image with me. I have attached here.i would like to know absorption coefficient value of 1064nm. Help me to find out sir.
  5 个评论
Walter Roberson
Walter Roberson 2018-9-2
That image is too low a resolution to get "exact" values at that point. pchip would possibly allow you to predict a smoothed value but not an exact value.
Have you considered writing to the authors and asking for the data?
Sathyamoorthy R
Sathyamoorthy R 2018-9-2
It's an image in text book sir. Thank you so much for sharing your knowledge.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by