# Julia Notes

Notes on using Julia and Pluto.

## Using the Julia REPL

When I started using Python, I didn’t use the Python REPL much. I took a more conventional approach to running Python as a scripting utility using executable files. When I started using Julia, I found the REPL much more valuable than Python’s. It might be the same, however, I’ve found myself using Julia via the REPL far more than as a scripting language. A couple of pointers:

### To find out where you are in the directories (tab completion works as well):

julia> pwd()
"/Users/lkoepsel"
julia> cd("Desktop/")
julia> pwd()
"/Users/lkoepsel/Desktop"


### For symbols

With pi as an example: It can also be accessed via the unicode symbol (you can get it at the REPL or in a notebook via the TeX completion \pi followed by a tab)

## Simple graphing using Julia

To make it easy to create simple plots, I created a plotting function which takes the title and a 3 column array as arguments. Using a three column array for the measurements, makes it easy to record frequency, Vi and Vo in a single row (see below). For quick and easy plotting, I open my text editor and create a simple file for data then copy and paste into the Julia REPL. The example has both the graphing function and an example data sections in one file.

using Plots
# graphing function
function db_graph(graph_title, measurements)
samples = length(measurements[:,1]);
GainDB = Array{Float64, 2}(undef, samples, 1);
for i = 1:samples
GainDB[i] = 20 * log10(Measurements[i,3]/Measurements[i,2])
end
plot(measurements[:,1], GainDB,
title = graph_title,
label = ["f" "GDB"],
xlabel = "freq (Hz)",
xscale=:log10,
ylabel = "Gain dB",
size = (623, 655),
gridalpha = .25,
background_color = "#FFFDF6",
linewidth = 1)
savefig("juliaplot")
end

# CR Low-Pass Filter
gtitle = "Low-Pass Filter (CR) Frequency Response (Log Scale)"
#Frequency   Vin  Vout
Measurements = [
50 5.8 5.4;
100 5.8 5.4;
200 5.8 5.4;
300 5.8 5.4;
400 5.8 5.4;
500 5.8 5.4;
1000 5.8 5.4;
2000 5.8 5.1;
3000 5.8 4.9;
4000 5.8 4.4;
4600 5.8 4.2;
5000 5.8 4.0;
7500 5.9 3.1;
10000 5.9 2.6;
20000 5.9 1.1;
40000 5.9 0.4
]
db_graph(gtitle, Measurements)


## Using Julia and Pluto

I’ve found using Julia to plot data such as this, is incredibly easy. I’ve also found that using Pluto notebooks with Julia is a great way to document my work. To run the this program as a Julia notebook:

1. Start Julia
2. ‘import Pluto’ or if first time: ‘import Pkg; Pkg.add(“Pluto”)’
3. ‘import Plots’ or if first time: ‘import Pkg; Pkg.add(“Plots”)’
4. Pluto.run() This will result in browser window opening to a local web page.
5. Using a programming editor (Sublime Text, Atom etc) copy and paste the content below into a file then save as test.jl.
6. Go back to the browser window running Pluto and have it open the file test.jl.
7. It will take about 15 seconds to initialize then you will have a Pluto notebook to display your data!
### A Pluto.jl notebook ###
# v0.14.5

using Markdown
using InteractiveUtils

# ╔═╡ f0f35acd-ef6e-4350-b43f-e79cd42d9ebb
### A Pluto.jl notebook ###
# v0.14.2

using Markdown

# ╔═╡ 79bc63c9-15ae-4e22-bccf-45ef4130365a
using InteractiveUtils

# ╔═╡ 73d9f718-2c7a-4f42-9607-31791c199094
using Plots

# ╔═╡ e7438b6f-82db-49a1-a36f-d91aa632e20c
md"## Inverting Amplifier DC Sweep
An example Pluto notebook showing the plotted data a DC sweep for an
inverting amplifier."

# ╔═╡ eacf9337-fcd6-42b2-9ed9-01b5045a564a
#Vi   Vn  Vp Vo
Measurements = [
0 2.6 4.8 7.9;
1 2.9 4.8 7.9;
2 3.5 4.8 7.9;
3 4.2 4.8 7.9;
3.5 4.5 4.8 7.9;
3.9 4.8 4.8 7.6;
4.5 4.8 4.8 6.1;
5.0 4.8 4.8 4.6;
5.5 4.8 4.8 3.5;
6.0 4.8 4.8 2.1;
6.6 4.8 4.8 0.7;
7.0 5.1 4.8 0.7;
8.0 5.8 4.8 0.7;
9.0 6.5 4.8 0.7;
]

# ╔═╡ 605c3ffd-034a-487d-b00c-25e9ff3cb9da
plot(Measurements[:,1], Measurements,
title = "Inverting Amplifier DC Sweep",
label = ["Vi" "Vo" "Vn" "Vp"],
xlabel = "Vv Volts",
xlims = (-1.0, 10.0),
xticks = 0:1.0:10,
ylabel = "Volts",
ylims = (-1.0, 10.0),
yticks = 0:1.0:10,
size = (623, 655),
background_color = "#FFFDF6",
gridalpha = .25,
linewidth = 1)

# ╔═╡ Cell order:
# ╟─e7438b6f-82db-49a1-a36f-d91aa632e20c
# ╟─f0f35acd-ef6e-4350-b43f-e79cd42d9ebb
# ╟─79bc63c9-15ae-4e22-bccf-45ef4130365a
# ╟─73d9f718-2c7a-4f42-9607-31791c199094
# ╟─eacf9337-fcd6-42b2-9ed9-01b5045a564a
# ╟─605c3ffd-034a-487d-b00c-25e9ff3cb9da


To show the cells in order to make changes, click on the eye icon at the upper left-hand corner of each cell.