vittorio
vittorio

Reputation: 143

matlab interpolation

Starting from the plot of one curve, it is possible to obtain the parametric equation of that curve?

In particular, say x={1 2 3 4 5 6....} the x axis, and y = {a b c d e f....} the corresponding y axis. I have the plot(x,y).

Now, how i can obtain the equation that describe the plotted curve? it is possible to display the parametric equation starting from the spline interpolation?

Thank you

Upvotes: 2

Views: 3073

Answers (4)

Milad Greeneyes
Milad Greeneyes

Reputation: 3

Curve Fitting Tool provides a flexible graphical user interfacewhere you can interactively fit curves and surfaces to data and viewplots. You can:

Create, plot, and compare multiple fits

Use linear or nonlinear regression, interpolation,local smoothing regression, or custom equations

View goodness-of-fit statistics, display confidenceintervals and residuals, remove outliers and assess fits with validationdata

Automatically generate code for fitting and plottingsurfaces, or export fits to workspace for further analysis

Upvotes: 0

Doresoom
Doresoom

Reputation: 7458

If you want to display a polynomial fit function alongside your graph, the following example should help:

x=-3:.1:3;
y=4*x.^3-5*x.^2-7.*x+2+10*rand(1,61);
p=polyfit(x,y,3); %# third order polynomial fit, p=[a,b,c,d] of ax^3+bx^2+cx+d
yfit=polyval(p,x); %# evaluate the curve fit over x
plot(x,y,'.')
hold on
plot(x,yfit,'-g')
equation=sprintf('y=%2.2gx^3+%2.2gx^2+%2.2gx+%2.2g',p); %# format string for equation
equation=strrep(equation,'+-','-'); %# replace any redundant signs
text(-1,-80,equation) %# place equation string on graph
legend('Data','Fit','Location','northwest')

alt text

Upvotes: 6

zellus
zellus

Reputation: 9582

You're asking for the function/mapping between two data sets. Knowing the physics involved, the function can be derived by modeling the system. Write down the differential equations and solve it.

Left alone with just two data series, an input and an output with a 'black box' in between you may approximate the series with an arbitrary function. You may start with a polynomial function

y = a*x^2 + b*x + c

Given your input vector x and your output vector y, parameters a,b,c must be determined applying a fitness function.

There is an example of Polynomial Curve Fitting in the MathWorks documentation.

Upvotes: 2

user85109
user85109

Reputation:

Last year, I wrote up a set of three blogs for Loren, on the topic of modeling/interpolationg a curve. They may cover some of your questions, although I never did find the time to add another 3 blogs to finish the topic to my satisfaction. Perhaps one day I will get that done.

The problem is to recognize there are infinitely many curves that will interpolate a set of data points. A spline is a nice choice, because it can be made well behaved. However, that spline has no simple "equation" to write down. Instead, it has many polynomial segments, pieced together to be well behaved.

Upvotes: 5

Related Questions