gauss elimination or inverse

7 vues (au cours des 30 derniers jours)
deep
deep le 14 Jan 2019
Commenté : deep le 16 Jan 2019
Hi all,
I have a plynomial equation similar to the one iven below
Equation : ax^(n-1)+bx^(n-2)+.............+c=y
The equation must be satisfied for a set of x (say x1,x2,x3.....etc) and correspondig y (say y1,y2,y3......etc)
I need a suggestion to find the coefficient for the equation.(a,b,.....,c)
Should i use Gauss elimination method or simply do a inverse for the matrix [x] and find the solution.
Highly appreciate the responses.

Réponse acceptée

John D'Errico
John D'Errico le 14 Jan 2019
Modifié(e) : John D'Errico le 14 Jan 2019
People have said repeatedly that you want to use polyfit. This is the correct answer, IF you need to fit a polynomial.
At the same time, you should not use Gaussian elimination, or use a matrix inverse. Those tools will have you writing the code, and sadly, making many novice mistakes in the computations that are already dealt with in polyfit.
But even with polyfit, there are still massively serious issues when you are trying to fit a high order polynomial. These issues can make it almost impossible to do a high order polynomial fit in double precision arithmetic. The problem is the resulting linear system of equations will become nearly singular in double precision arithmetic. (It would be far worse had you tried to use Gaussian elimination or use a matrix inverse. Seriously so.)
The big problem is what domain the variable x lives in. What is the min and max for x? You don't show your data. How many datapoints do you have? How much noise is present in the data? Best, is if you provide your data. Use a .mat file, attached to a comment.
In order to have even a chance in hell of solving this problem, you need to use the centering and scaling options in polyfit. That will improve the condition of the solution. But even then, unless we know enough about your data, it is difficult to help you more, to know if you can actually do this fit. There is potentially a chance in the end that you can do nothing at all to solve the problem, but I cannot know that until I see your data.
Finally, I would ask if you really do need a polynomial to fit the data? High order polynomial fits are usually a terrribly bad idea, when far better tools, like spline models, are available.
  5 commentaires
John D'Errico
John D'Errico le 15 Jan 2019
Modifié(e) : John D'Errico le 15 Jan 2019
From your comments, you have no need for a polynomial form at all. All you seem to be looking to achieve is a fit that passes smoothly through the points. So there is not even a remote need to use polynomial models, or even the contrivance I came up with to model
Not surprisingly, this is what splines do very well. In fact, the word spline (lath is also used in this respect) can be found in ship building, a tool used to draw the smooth curves needed when lofting hull shapes.
You will still have a problem trying to interpolate this curve using the standard spline tools in MATLAB, because they are not designed to fit curves with derivative singularities in them. (Which is what you have.) Instead, you want to use a tool like my interparc. It can be freely downloaded from the file exchange, from this link:
Use of interparc is trivial once you download it. I don't even need to exclude the third point from this interpolation, even though I know the value of x was an error. That is because interparc has no problems with that tiny deviation. It still draws a smooth curve through the points.
XY = interparc(100,x,y);
plot(XY(:,1),XY(:,2),'-',x,y,'o')
So 100 points smoothly interpolated along that curve. They are chosen to be equidistant from each other along that curve. And the curve will pass exactly through those points.
So the answer to your problem is to NOT use any polynomial at all. Instead, just use interparc.
deep
deep le 16 Jan 2019
Thank you for your elaborate explanation.

Connectez-vous pour commenter.

Plus de réponses (3)

Stephan
Stephan le 14 Jan 2019
Hi,
use polyfit to do this.
Best regards
Stephan
  3 commentaires
Bruno Luong
Bruno Luong le 14 Jan 2019
How to work out this to get the coefficients correct?
Give up such high order fitting. Change the method.
deep
deep le 14 Jan 2019
This is my first look on the idea.
I will try to look for suitable alternative method.
Thank you for your advice.

Connectez-vous pour commenter.


Bruno Luong
Bruno Luong le 14 Jan 2019
P = polyfit(x(:),y(:),n-1);
a = P(1);
b = P(2);
...
c = P(n);
  3 commentaires
Bruno Luong
Bruno Luong le 14 Jan 2019
In general fitting polynomial with order >= 10 is not reliable.
deep
deep le 14 Jan 2019
I applied the polyfit method to my set of data and it does not result in the correct results as the order of my equations are expected to be higher than 10.
for eg:
y1=ax1^15+bx1^14+......+C1
y2=ax1^15+bx1^14+......+C2
.
.
.
.
.
Y16=ax16^15+bx16^14+......C16
How to work out this to get the coefficients correct?
Thank you in advance

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 14 Jan 2019
polyfit(x(:), y(:), n - 1)
  5 commentaires
Torsten
Torsten le 14 Jan 2019
If you insist on fitting your data with a polynomial of degree 15 (which is numerical nonsense in my opinion), use the centering and scaling option of "polyfit" as described here:
https://de.mathworks.com/help/matlab/ref/polyfit.html
deep
deep le 14 Jan 2019
This is my first look on the idea.
I will try to look for suitable alternative method.
Thank you for your advice.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by