Interpolation Methods in MatLab for Plotting Car Fender Coordinates

In summary: However, I don't have an equation to input; I just have two thousand points that seem to make a smooth curve. Can Matlab find the equation to the curve?Unfortunately, there is no function in MATLAB that can find the equation of a curve given a set of points. Polyfit may be able to approximate the equation if you input the order of the polynomial, but it would be a bit of a guess.
  • #1
beatboxbo
5
0
Hello, I'm having a really hard time doing some work in Matlab, I have a book but it just isn't making sense to me, the problem I have to do is in four parts so Ill just show the first part for now...

The following coordinates specify the
shape of a certain cars’ front fender. Interpolate and plot lines connecting these points
using linear, spline and cubic options.
x (ft) 0 0.25 0.75 1.25 1.5 1.75 1.875 2 2.215 2.25
y (ft) 1.2 1.18 1.1 1.0 0.92 0.8 0.7 0.55 0.35 0

Now do I have to interpolate the coordinates first, or do I interpolate the data when I plot the lines?
 
Physics news on Phys.org
  • #2
The question is asking you to use MATLAB to "connect the dots", that is, interpolation, using piecewise linear, cubic or spline functions, that is, to connect the dots with straight lines, cubics, or spines. You do this using Matlab's interp1 function. Look at the help file in Matlab. interp1 works like this:

>> yi = interp1(x,y,xi,method)

the vectors x and y are as you have them, they give the coordinates of the points. xi is a vector of points at which you would like Matlab to interpolate. In your case, x ranges between 0 and 2.25, so say you want Matlab to interpolate the date at increments of 0.1, say. Then you will have
>> xi = 0:0.1:2.25

The "method" referred to in
>> yi = interp1(x,y,xi,method)
is the method you would like Matlab to use to do the interpolation, so in place of "method" you would put "linear", "cubic", or "spline", according to the method you want (without the quotation marks ofcourse.)

And then you can plot the interpolation:
>> plot(xi,yi)
If you would like to see the original points as well, then
>> plot(x,y,'o',xi,yi)
 
  • #3
Hi,

I have done the above and now would like to both integrate and find the derivative of the function created by the interpolation. How do I go about doing this?
 
  • #4
Matlab is capable of finding the derivative of the line created by the interpolation right?
 
  • #5
mherna48 said:
Hi,

I have done the above and now would like to both integrate and find the derivative of the function created by the interpolation. How do I go about doing this?

mherna48 said:
Matlab is capable of finding the derivative of the line created by the interpolation right?

Qspeechc's example leaves you with a set of interpolated points yi, interpolated at values xi. You can then do numerical differentiation (using whichever method you feel is most appropriate) and numerical integration on the resulting vector.

A primer on numerical differentiation:
http://en.wikipedia.org/wiki/Numerical_differentiation

The MATLAB trapezoid rule (probably the easiest way of doing numerical integration) page:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/trapz.html
http://en.wikipedia.org/wiki/Numerical_integration
 
  • #6
Thanks dude,

The integration worked well. to differentiate, I understand the method, but I feel like there's a function that should do that in MATLAB. Maybe pdeval(m,x,ui,xout)??
 
  • #7
mherna48 said:
Thanks dude,

The integration worked well. to differentiate, I understand the method, but I feel like there's a function that should do that in MATLAB. Maybe pdeval(m,x,ui,xout)??

Unfortunately, AFAIK there isn't one (for the reasons mentioned in the link I sent you to: you can take forward difference, backwards difference, three-point, etc. The closest thing there is to such a thing is the diff function (which just subtract element n from element n-1):
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/diff.html
 
Last edited by a moderator:
  • #8
The gradient function does numerical derivatives.
 
  • #9
Thanks for the help. However, I don't have an equation to input; I just have two thousand points that seem to make a smooth curve. Can Matlab find the equation to the curve?
 
  • #10
polyfit fits a polynomial of a specified order to the the data. It returns the coefficients of the polynomial.
 

Related to Interpolation Methods in MatLab for Plotting Car Fender Coordinates

1. What is interpolation in MatLab?

Interpolation in MatLab is the process of estimating values between known data points. It involves creating a function that passes through the given data points and can be used to predict values at intermediate points.

2. How can I perform interpolation using MatLab?

MatLab provides several built-in functions for interpolation, such as interp1, interp2, and interp3. These functions use various interpolation methods, such as linear, spline, and nearest neighbor, to generate a curve or surface that passes through the given data points.

3. Can I choose the interpolation method in MatLab?

Yes, MatLab allows users to specify the interpolation method they want to use. This can be done by providing additional parameters in the interpolation function, such as 'linear', 'cubic', or 'nearest' for different methods.

4. Is interpolation the same as curve fitting?

No, interpolation and curve fitting are two different techniques. While interpolation involves estimating values between known data points, curve fitting involves finding a mathematical function that best fits a given set of data points.

5. Are there any limitations to interpolation in MatLab?

Yes, like any other mathematical technique, interpolation also has its limitations. It may not be accurate if the given data points are too far apart or if the data contains significant noise. It is always recommended to analyze the data and choose an appropriate interpolation method based on the data set.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
19K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
Replies
36
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
Back
Top