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 1. INTRODUCTION 9<br />

Exercise 1.1-1:<br />

x 0 =0.<br />

F<strong>in</strong>d the second order Taylor polynomial for f(x) =e x s<strong>in</strong> x about<br />

a) Compute P 2 (0.4) to approximate f(0.4). Use the rema<strong>in</strong>der term R 2 (0.4) to f<strong>in</strong>d an<br />

upper bound for the error |P 2 (0.4)−f(0.4)|. Compare the upper bound <strong>with</strong> the actual<br />

error.<br />

b) Compute ∫ 1<br />

P 0 2(x)dx to approximate ∫ 1<br />

f(x)dx. F<strong>in</strong>d an upper bound for the error<br />

0<br />

us<strong>in</strong>g ∫ 1<br />

R 0 2(x)dx, and compare it to the actual error.<br />

1.2 <strong>Julia</strong> basics<br />

The first step is to download the <strong>Julia</strong> programm<strong>in</strong>g language from the <strong>Julia</strong> webpage<br />

https://julialang.org. In this book I used <strong>Julia</strong> 1.1.0. There are different environments<br />

and editors to run <strong>Julia</strong>. Here I will use the Jupyter environment https://jupyter.org.<br />

Instructions on how to <strong>in</strong>stall software do not age well: I ran the command us<strong>in</strong>g I<strong>Julia</strong>;<br />

jupyterlab() on the <strong>Julia</strong> term<strong>in</strong>al to <strong>in</strong>stall the Jupyter environment, but this could change<br />

<strong>in</strong> the future versions of the software. There are several tutorials and other resources on <strong>Julia</strong><br />

at https://julialang.org where one can f<strong>in</strong>d up-to-date <strong>in</strong>formation on <strong>in</strong>stall<strong>in</strong>g <strong>Julia</strong><br />

and Jupyter.<br />

The Jupyter environment uses the so-called Jupyter notebook where one can write and<br />

edit a <strong>Julia</strong> code, run the code, and export the work <strong>in</strong>to various file formats <strong>in</strong>clud<strong>in</strong>g<br />

Latex and pdf. Most of our <strong>in</strong>teraction <strong>with</strong> <strong>Julia</strong> will be through the Jupyter notebooks.<br />

One exception is when we need to <strong>in</strong>stall a package. A <strong>Julia</strong> package provides additional<br />

functionality to the core programs, and there are numerous packages from visualization to<br />

parallel comput<strong>in</strong>g and mach<strong>in</strong>e learn<strong>in</strong>g. To <strong>in</strong>stall a package, open <strong>Julia</strong> by click<strong>in</strong>g on<br />

the software icon, which will open the <strong>Julia</strong> term<strong>in</strong>al, called <strong>Julia</strong> REPL (Read-Evaluate-<br />

Pr<strong>in</strong>t-Loop). In the <strong>Julia</strong> REPL, press ] to enter the package mode. (To get back to the<br />

<strong>Julia</strong> REPL press backspace, delete, or shift C.) Once <strong>in</strong> the package mode, typ<strong>in</strong>g "add<br />

PackageName" will <strong>in</strong>stall the package. To learn more about packages, type Pkg <strong>in</strong> the <strong>Julia</strong><br />

1.1 documentation https://docs.julialang.org/en/v1/<strong>in</strong>dex.html.<br />

After <strong>in</strong>stall<strong>in</strong>g <strong>Julia</strong> and Jupyter, open a Jupyter notebook. Here is a screenshot of my<br />

notebook:

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

Saved successfully!

Ooh no, something went wrong!