finding mathematical function of set of points

179 ビュー (過去 30 日間)
mohammad
mohammad 2011 年 11 月 20 日
コメント済み: friendly nadeem 2018 年 2 月 5 日
There are some points on X-Y coordinates. Is it possible in MATLAB to find mathematical function between X and Y?
for example for X=1,3,5,7,8,9,23,25,30 respectively Y is equals to Y=1,3,5,7,9,12,13,17,20
now how MATLAB could find relation between X and Y in mathematical function form? ( finding Y=f(X) )
mathematical function must be algebra in this form: y=a+bx^2+cx^3+dx^4+...nx^K (Not sinusoidal and etc)
that a,b,...,n and K are unknown. Is it possible in MATLAB to find this parameters?

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 20 日
There are literally an infinite number of mathematical functions that fit any finite set of (X,Y) pairs exactly. Unless you have some prior information as to what the form of the mathematical function "should be", there is no way of distinguishing which of those infinite number of functions is the "right" one.
  6 件のコメント
Sofía Carrillo
Sofía Carrillo 2015 年 3 月 10 日
@WalterRoberson is there a demonstration of why there are infinite functions that contain the given points? Or how do you know so?
Image Analyst
Image Analyst 2015 年 3 月 10 日
Let's take a simple case: two points. Can you find a line that goes through them? Sure. How about a parabola? Sure, lot of them - an infinite number of them. What about a cubic? Of course? Can you find a 4th order polynomial? A 5th, a 6th, a 7th order polynomial? Of course you can. What about a circle that touches the two points? Yes. How about an ellipse or hyperbola? Yes and Yes. Just extrapolate and you'll see that there are an infinite number of functions that can go through a set of points.

サインインしてコメントする。

その他の回答 (3 件)

Morteza
Morteza 2015 年 8 月 18 日
編集済み: Morteza 2015 年 8 月 18 日
plot your data by below format:
X=[1,3,5,7,8,9,23,25,30]
Y=[1,3,5,7,9,12,13,17,20]
plot(X,Y)
then from ---tools find the ---Basic Fitting by activation the --show equation and select one or more fitting functions you will see the F(x) just on the your plot figure.

Image Analyst
Image Analyst 2011 年 11 月 20 日
  3 件のコメント
mohammad
mohammad 2011 年 11 月 20 日
So nice, Is there any MATLAB code for this?
Image Analyst
Image Analyst 2011 年 11 月 20 日
Well polyfit should do it - give you the Lagrange Interpolation coefficients - AS LONG AS the order of the polynomial is exactly equal to the number of coordinate points that you have. Otherwise if you put in an order less than the number of points, it's a regression and won't go through your points exactly. Make sense? See my code as an answer. I put it there so I could properly format it as code.

サインインしてコメントする。


Image Analyst
Image Analyst 2011 年 11 月 20 日
Try this:
fontSize = 16;
% Generate the sample data.
X=[1,3,5,7,8,9,23,25,30]
Y=[1,3,5,7,9,12,13,17,20]
% Find the coefficients.
coeffs = polyfit(X, Y, length(Y)+1)
plot(X, Y, 'ro', 'MarkerSize', 10);
% Make a finer sampling so we can see what it
% does in between the training points.
interpolatedX = linspace(min(X), max(X), 500);
interpolatedY = polyval(coeffs, interpolatedX);
% Plot the interpolated points.
hold on;
plot(interpolatedX, interpolatedY, 'b-', 'LineWidth', 3);
grid on;
title('Interpolating Polynomial', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Be aware of the drawback of using such a high order polynomial. Yes it will go through all your points but with such a high order, the oscillations between your training points grow wildly and the estimated values there are less reliable. You can see this on the plot given by the above code. Look what happens between 10 and 20 and between 25 and 30 - it goes crazy.
  3 件のコメント
rahman sajadi
rahman sajadi 2015 年 8 月 18 日
this code gives a garph of points only, please help me to find out mathmatical function between X and Y
Walter Roberson
Walter Roberson 2015 年 8 月 18 日
The variable coeffs gives the coefficients of the polynomial, highest degree first. For example if the coeffs was 7 4 13 -6 then it would represent 7*x^3 + 4*x^2 + 13*x^1 - 6

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by