06.09.2021 Views

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 5. APPROXIMATION THEORY 187<br />

The correspond<strong>in</strong>g error is:<br />

In [13]: leastsqerror(a,xd,yd)<br />

Out[13]: 1.2664285714285708<br />

The next polynomial is of degree four:<br />

In [14]: a=leastsqfit(xd,yd,4)<br />

xaxis=1:1/100:6<br />

yvals=map(x->poly(x,a),xaxis)<br />

plot(xaxis,yvals)<br />

scatter(xd,yd);<br />

The least squares error is:<br />

In [15]: leastsqerror(a,xd,yd)<br />

Out[15]: 0.7232142857142789<br />

F<strong>in</strong>ally, we try a fifth degree polynomial. Recall that the normal equations have a<br />

unique solution when x i are dist<strong>in</strong>ct, and n ≤ m − 1. S<strong>in</strong>ce m =6<strong>in</strong> this example,<br />

n =5is the largest degree <strong>with</strong> guaranteed unique solution.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!