finding mathematical function of set of points

244 visualizaciones (últimos 30 días)
mohammad
mohammad el 20 de Nov. de 2011
Comentada: friendly nadeem el 5 de Feb. de 2018
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Nov. de 2011
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 comentarios
Sofía Carrillo
Sofía Carrillo el 10 de Mzo. de 2015
@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 el 10 de Mzo. de 2015
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.

Iniciar sesión para comentar.

Más respuestas (3)

Morteza
Morteza el 18 de Ag. de 2015
Editada: Morteza el 18 de Ag. de 2015
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 el 20 de Nov. de 2011
  3 comentarios
mohammad
mohammad el 20 de Nov. de 2011
So nice, Is there any MATLAB code for this?
Image Analyst
Image Analyst el 20 de Nov. de 2011
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.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 20 de Nov. de 2011
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 comentarios
rahman sajadi
rahman sajadi el 18 de Ag. de 2015
this code gives a garph of points only, please help me to find out mathmatical function between X and Y
Walter Roberson
Walter Roberson el 18 de Ag. de 2015
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

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by