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 188<br />

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

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

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

plot(xaxis,yvals)<br />

scatter(xd,yd);<br />

The approximat<strong>in</strong>g polynomial of degree five is the <strong>in</strong>terpolat<strong>in</strong>g polynomial! What<br />

is the least squares error?<br />

Least squares <strong>with</strong> non-polynomials<br />

The method of least squares is not only for polynomials. For example, suppose we want to<br />

f<strong>in</strong>d the function<br />

f(t) =a + bt + c s<strong>in</strong>(2πt/365) + d cos(2πt/365) (5.3)<br />

that has the best fit to some data (t 1 ,T 1 ), ..., (t m ,T m ) <strong>in</strong> the least-squares sense. This function<br />

is used <strong>in</strong> model<strong>in</strong>g weather temperature data, where t denotes time, and T denotes the<br />

temperature. The follow<strong>in</strong>g figure plots the daily maximum temperature dur<strong>in</strong>g a period<br />

of 1,056 days, from 2016 until November 21, 2018, as measured by a weather station at<br />

Melbourne airport, Australia 1 .<br />

1 http://www.bom.gov.au/climate/data/

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

Saved successfully!

Ooh no, something went wrong!