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

There are eight equations and eight unknowns. However, a 0 = c 0 =0, so that reduces the<br />

number of equations and unknowns to six. We rewrite the equations below, substitut<strong>in</strong>g<br />

a 0 = c 0 =0, and simplify<strong>in</strong>g when possible:<br />

b 0 + d 0 =1<br />

a 1 + b 1 + c 1 + d 1 =1<br />

a 1 +2b 1 +4c 1 +8d 1 =0<br />

b 0 +3d 0 = b 1 +2c 1 +3d 1<br />

3d 0 = c 1 +3d 1<br />

c 1 +6d 1 =0<br />

We will use <strong>Julia</strong> to solve this system of equations. To do that, we first rewrite the system<br />

of equations as a matrix equation<br />

Ax = v<br />

where<br />

⎡<br />

⎤ ⎡ ⎤ ⎡ ⎤<br />

1 1 0 0 0 0 b 0 1<br />

0 0 1 1 1 1<br />

d 0<br />

1<br />

0 0 1 2 4 8<br />

a 1<br />

0<br />

A =<br />

,x=<br />

,v =<br />

.<br />

1 3 0 −1 −2 −3<br />

b 1<br />

0<br />

⎢<br />

⎣0 3 0 0 −1 −3<br />

⎥ ⎢<br />

⎦ ⎣c ⎥ ⎢<br />

1 ⎦ ⎣0<br />

⎥<br />

⎦<br />

0 0 0 0 1 6 d 1 0<br />

We enter the matrices A, v <strong>in</strong> <strong>Julia</strong> and solve the equation Ax = v us<strong>in</strong>g the command<br />

A\v.<br />

In [1]: A=[1 1 0 0 0 0 ; 0 0 1 1 1 1; 0 0 1 2 4 8; 1 3 0 -1 -2 -3;<br />

0 3 0 0 -1 -3; 0 0 0 0 1 6]<br />

Out[1]: 6×6 Array{Int64,2}:<br />

1 1 0 0 0 0<br />

0 0 1 1 1 1<br />

0 0 1 2 4 8<br />

1 3 0 -1 -2 -3<br />

0 3 0 0 -1 -3<br />

0 0 0 0 1 6

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

Saved successfully!

Ooh no, something went wrong!