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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 5. APPROXIMATION THEORY 193<br />

A[1,4]=sum(t->cos(2*pi*t/365),time)<br />

A[2,2]=sum(t->t^2,time)<br />

A[2,3]=sum(t->t*s<strong>in</strong>(2*pi*t/365),time)<br />

A[2,4]=sum(t->t*cos(2*pi*t/365),time)<br />

A[3,3]=sum(t->(s<strong>in</strong>(2*pi*t/365))^2,time)<br />

A[3,4]=sum(t->(s<strong>in</strong>(2*pi*t/365)*cos(2*pi*t/365)),time)<br />

A[4,4]=sum(t->(cos(2*pi*t/365))^2,time)<br />

for i=2:4<br />

for j=1:i<br />

A[i,j]=A[j,i]<br />

end<br />

end<br />

In [10]: A<br />

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

1056.0 558096.0 12.2957 -36.2433<br />

558096.0 3.93086e8 -50458.1 -38477.3<br />

12.2957 -50458.1 542.339 10.9944<br />

-36.2433 -38477.3 10.9944 513.661<br />

Now we def<strong>in</strong>e the vector r. The function dot(x,y) takes the dot product of the<br />

arrays x, y. For example, dot([1, 2, 3], [4, 5, 6]) = 1 × 4+2× 5+3× 6=32.<br />

In [11]: r=zeros(4,1)<br />

r[1]=sum(temp)<br />

r[2]=dot(temp,time)<br />

r[3]=dot(temp,map(t->s<strong>in</strong>(2*pi*t/365),time))<br />

r[4]=dot(temp,map(t->cos(2*pi*t/365),time));<br />

In [12]: r<br />

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

21861.499999999996<br />

1.1380310200000009e7<br />

1742.0770653857649<br />

2787.7612743690415

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

Saved successfully!

Ooh no, something went wrong!