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

We can solve the matrix equation now.<br />

In [13]: A\r<br />

Out[13]: 4×1 Array{Float64,2}:<br />

20.28975634590378<br />

0.0011677302061853312<br />

2.7211617643953634<br />

6.88808560736693<br />

Recall that these constants are the values of a, b, c, d <strong>in</strong> the def<strong>in</strong>ition of f(t). Here<br />

is the best fitt<strong>in</strong>g function to the data:<br />

In [14]: f(t)=20.2898+0.00116773*t+2.72116*s<strong>in</strong>(2*pi*t/365)+<br />

6.88809*cos(2*pi*t/365)<br />

Out[14]: f (generic function <strong>with</strong> 1 method)<br />

We next plot the data together <strong>with</strong> f(t):<br />

In [15]: xaxis=1:1:1056<br />

yvals=map(t->f(t),xaxis)<br />

plot(xaxis,yvals,label="Least squares approximation")<br />

xlabel("time (t)")<br />

ylabel("Temperature (T)")<br />

plot(temp,l<strong>in</strong>estyle="-",alpha=0.5,label="Data")<br />

legend(loc="upper center");

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

Saved successfully!

Ooh no, something went wrong!