# finding mathematical function of set of points

186 views (last 30 days)

Show older comments

mohammad
on 20 Nov 2011

Commented: friendly nadeem
on 5 Feb 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?

##### 0 Comments

### Accepted Answer

Walter Roberson
on 20 Nov 2011

##### 6 Comments

Sofía Carrillo
on 10 Mar 2015

Image Analyst
on 10 Mar 2015

### More Answers (3)

Morteza
on 18 Aug 2015

Edited: Morteza
on 18 Aug 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
on 20 Nov 2011

##### 3 Comments

Image Analyst
on 20 Nov 2011

Image Analyst
on 20 Nov 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 Comments

rahman sajadi
on 18 Aug 2015

Walter Roberson
on 18 Aug 2015

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!