gauss elimination or inverse

조회 수: 10 (최근 30일)
deep
deep 2019년 1월 14일
댓글: deep 2019년 1월 16일
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.

채택된 답변

John D'Errico
John D'Errico 2019년 1월 14일
편집: John D'Errico 2019년 1월 14일
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
John D'Errico
John D'Errico 2019년 1월 15일
편집: John D'Errico 2019년 1월 15일
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 2019년 1월 16일
Thank you for your elaborate explanation.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

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

댓글을 달려면 로그인하십시오.


Bruno Luong
Bruno Luong 2019년 1월 14일
P = polyfit(x(:),y(:),n-1);
a = P(1);
b = P(2);
...
c = P(n);
  댓글 수: 3
Bruno Luong
Bruno Luong 2019년 1월 14일
In general fitting polynomial with order >= 10 is not reliable.
deep
deep 2019년 1월 14일
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

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2019년 1월 14일
polyfit(x(:), y(:), n - 1)
  댓글 수: 5
Torsten
Torsten 2019년 1월 14일
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 2019년 1월 14일
This is my first look on the idea.
I will try to look for suitable alternative method.
Thank you for your advice.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by