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

Control flow<br />

Let’s create an array of 10 entries of float<strong>in</strong>g-type. A simple way to do is by us<strong>in</strong>g the<br />

function zeros(n), which creates an array of size n, and sets each entry to zero. (A<br />

similar function is ones(n) which creates an array of size n <strong>with</strong> each entry set to 1.)<br />

In [52]: values=zeros(10)<br />

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

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

0.0<br />

Now we will set the elements of the array to values of s<strong>in</strong> function.<br />

In [53]: for n <strong>in</strong> 1:10<br />

values[n]=s<strong>in</strong>(n^2)<br />

end<br />

In [54]: values<br />

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

0.8414709848078965<br />

-0.7568024953079282<br />

0.4121184852417566<br />

-0.2879033166650653<br />

-0.13235175009777303<br />

-0.9917788534431158<br />

-0.9537526527594719<br />

0.9200260381967907

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

Saved successfully!

Ooh no, something went wrong!