## How to find a polynomial of degree 2 that fits the given data with minimal approximation error? and then sketch discrete points and the graph of the polynomial

Asked by Kate Smith

### Kate Smith (view profile)

on 7 Apr 2019
Latest activity Edited by Stephan

### Stephan (view profile)

on 7 Apr 2019
Suppose you have the following data: (0, 1.0000), (0.25, 1.2840), (0.50, 1.6487), (0.75, 2.1170) and (1.00, 2.7183) . Find a polynomial P (x) of degree 2 that fits the data with the minimal approximation error. Calculate this error. Then sketch these discrete points and the graph of the polynomial P(x) in a figure using MATLAB.

### Products

Answer by the cyclist

### the cyclist (view profile)

on 7 Apr 2019

You could use the polyfit and plot commands (and of course a few more fundamental calculations like subtraction) to do this.

### Stephan (view profile)

on 7 Apr 2019
Edited by Stephan

### Stephan (view profile)

on 7 Apr 2019

Hi,
polyfit does the job:
[p,S,mu] = polyfit(x,y,n)
in your case n=2.
Best regards
Stephan