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 3. INTERPOLATION 118<br />

end<br />

end<br />

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

a[2i-1]=y[i]<br />

a[2i]=y[i]<br />

end<br />

for i <strong>in</strong> reverse(collect(2:m)) # computes the first divided<br />

#differences us<strong>in</strong>g derivatives<br />

a[2i]=yprime[i]<br />

a[2i-1]=(a[2i-1]-a[2i-2])/(z[2i-1]-z[2i-2])<br />

end<br />

a[2]=yprime[1]<br />

for j <strong>in</strong> 3:l #computes the rest of the divided differences<br />

for i <strong>in</strong> reverse(collect(j:l))<br />

a[i]=(a[i]-a[i-1])/(z[i]-z[i-(j-1)])<br />

end<br />

end<br />

return(a)<br />

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

Let’s compute the divided differences of Example 62.<br />

In [3]: hdiff([-1.5, 1.6, 4.7],[0.071,-0.029,-0.012],<br />

[1,-1,1])<br />

Out[3]: 6-element Array{Float64,1}:<br />

0.071<br />

1.0<br />

-0.33298647242455776<br />

0.006713436944043511<br />

0.015476096374635765<br />

-0.005196626333767283<br />

Note that <strong>in</strong> the hand-calculations of Example 63, where two-digit round<strong>in</strong>g was<br />

used, we obta<strong>in</strong>ed 0.0065 as the first third divided difference. In the <strong>Julia</strong> output above,<br />

this divided difference is 0.0067.

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

Saved successfully!

Ooh no, something went wrong!