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

end<br />

for j <strong>in</strong> 1:m<br />

sum=sum+x[j]^(i-1)<br />

end<br />

p[i]=sum<br />

end<br />

# We next compute the upper triangular part of the<br />

# coefficient matrix A, and its diagonal<br />

for k <strong>in</strong> 1:d<br />

for j <strong>in</strong> k:d<br />

A[k,j]=p[k+j-1]<br />

end<br />

end<br />

# The lower triangular part of the matrix is def<strong>in</strong>ed us<strong>in</strong>g<br />

# the fact the matrix is symmetric<br />

for i <strong>in</strong> 2:d<br />

for j <strong>in</strong> 1:i-1<br />

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

end<br />

end<br />

a=A\b<br />

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

Here is the data used to produce the first plot of the chapter: Arya’s data:<br />

In [3]: xd=[1,2,3,4,5,6];<br />

yd=[3,5,9.2,11,14.5,19];<br />

We fit a least squares l<strong>in</strong>e to the data:<br />

In [4]: leastsqfit(xd,yd,1)<br />

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

-0.7466666666666616<br />

3.1514285714285704

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

Saved successfully!

Ooh no, something went wrong!