1
0
mirror of https://gitlab.com/MisterBiggs/julia-for-matlabbers.git synced 2025-06-16 15:17:17 +00:00

brought back the scope a ton and finished

This commit is contained in:
Anson 2021-08-24 00:59:25 -07:00
parent 61634d9c6f
commit d9f18fc539
6 changed files with 82 additions and 347 deletions

View File

@ -1,28 +0,0 @@
Time,Thrust
0.01,16.81
0.03,22.34
0.11,22.23
0.26,21.49
0.37,20
0.47,20.21
0.67,18.09
0.99,15.74
1.31,13.4
1.81,10.85
2.49,10.21
3.13,8.94
3.6,8.83
4.11,8.62
4.95,8.62
5.45,8.62
5.58,8.51
5.88,8.72
6.22,8.51
6.46,8.51
6.6,7.77
6.71,7.02
6.79,5.64
6.91,3.83
6.95,2.23
7,0.96
7.05,0
1 Time Thrust
2 0.01 16.81
3 0.03 22.34
4 0.11 22.23
5 0.26 21.49
6 0.37 20
7 0.47 20.21
8 0.67 18.09
9 0.99 15.74
10 1.31 13.4
11 1.81 10.85
12 2.49 10.21
13 3.13 8.94
14 3.6 8.83
15 4.11 8.62
16 4.95 8.62
17 5.45 8.62
18 5.58 8.51
19 5.88 8.72
20 6.22 8.51
21 6.46 8.51
22 6.6 7.77
23 6.71 7.02
24 6.79 5.64
25 6.91 3.83
26 6.95 2.23
27 7 0.96
28 7.05 0

View File

@ -1,22 +0,0 @@
Time,Thrust
0.024,0.3704
0.066,0.8746
0.138,4.5044
0.246,6.6207
0.426,6.7351
1.218,7.3232
2.082,7.423
3.306,7.183
5.322,6.8385
6.978,6.7193
8.632,6.5512
10.144,6.4792
12.088,6.4254
15.472,6.3333
17.632,6.1305
19.108,6.0385
19.511,5.9607
19.804,4.4295
19.867,1.6687
19.937,0.3341
19.964,0
1 Time Thrust
2 0.024 0.3704
3 0.066 0.8746
4 0.138 4.5044
5 0.246 6.6207
6 0.426 6.7351
7 1.218 7.3232
8 2.082 7.423
9 3.306 7.183
10 5.322 6.8385
11 6.978 6.7193
12 8.632 6.5512
13 10.144 6.4792
14 12.088 6.4254
15 15.472 6.3333
16 17.632 6.1305
17 19.108 6.0385
18 19.511 5.9607
19 19.804 4.4295
20 19.867 1.6687
21 19.937 0.3341
22 19.964 0

View File

@ -1,28 +0,0 @@
Time,Thrust
0,0
0.148,7.638
0.228,12.253
0.294,16.391
0.353,20.21
0.382,22.756
0.419,25.26
0.477,23.074
0.52,20.845
0.593,19.093
0.688,17.5
0.855,16.225
1.037,15.427
1.205,14.948
1.423,14.627
1.452,15.741
1.503,14.785
1.736,14.623
1.955,14.303
2.21,14.141
2.494,13.819
2.763,13.338
3.12,13.334
3.382,13.013
3.404,9.352
3.418,4.895
3.45,0
1 Time Thrust
2 0 0
3 0.148 7.638
4 0.228 12.253
5 0.294 16.391
6 0.353 20.21
7 0.382 22.756
8 0.419 25.26
9 0.477 23.074
10 0.52 20.845
11 0.593 19.093
12 0.688 17.5
13 0.855 16.225
14 1.037 15.427
15 1.205 14.948
16 1.423 14.627
17 1.452 15.741
18 1.503 14.785
19 1.736 14.623
20 1.955 14.303
21 2.21 14.141
22 2.494 13.819
23 2.763 13.338
24 3.12 13.334
25 3.382 13.013
26 3.404 9.352
27 3.418 4.895
28 3.45 0

Binary file not shown.

File diff suppressed because one or more lines are too long

347
index.jl
View File

@ -16,21 +16,17 @@ using LinearAlgebra
# ╔═╡ 52819547-9593-446a-91e7-a08e08723e66 # ╔═╡ 52819547-9593-446a-91e7-a08e08723e66
using Plots using Plots
# ╔═╡ c231f030-5861-4b30-a182-efc06b5c08fe
using BenchmarkTools
# ╔═╡ 3228a21e-cab8-4738-bdc5-a6827c764c06 # ╔═╡ 3228a21e-cab8-4738-bdc5-a6827c764c06
using Unitful using Unitful
# ╔═╡ 3f7ae2df-9d4d-46d3-b12e-22107a560b66
begin
using CSV
using DataFrames
using FileIO
end
# ╔═╡ bb461e00-c0aa-11eb-2c7d-1bd1591779c6 # ╔═╡ bb461e00-c0aa-11eb-2c7d-1bd1591779c6
md""" md"""
# Julia for People That Were Unfortunate Enough to Learn MATLAB # Julia for People That Were Unfortunate Enough to Learn MATLAB
Julia is an incredily performant _(2 order of magnitude faster than Matlab)_, Dynamic _(Data types dont need to be declared unlike C)_, Composable _(The compiler is smart enough to allow functions you write to work for multiple different types of data)_, and most importantly for our use case Julia has very simple syntax that focuses on engineering / science applications. Julia is an incredily [performant](https://julialang.org/benchmarks/) _(2 order of magnitude faster than Matlab)_, Dynamic _(Data types dont need to be declared unlike C)_, Composable _(The compiler is smart enough to allow functions you write to work for multiple different types of data)_, and most importantly for our use case Julia has very simple syntax that focuses on engineering / science applications.
!!! info "Pluto Notebooks" !!! info "Pluto Notebooks"
The code in this notebook is running in something called Pluto.jl. Pluto notebooks are similar to Matlab Livescript but have a stricter focus on cells and are immutable meaning that a variable can only be declared once and cannot be changed in other cells. This feels very restricting at first but guarantees that the code you are currently looking at is correct, and allows reactive updating of dependant code. It's important to note that these are Pluto.jl features and not Julia features. The code in this notebook is running in something called Pluto.jl. Pluto notebooks are similar to Matlab Livescript but have a stricter focus on cells and are immutable meaning that a variable can only be declared once and cannot be changed in other cells. This feels very restricting at first but guarantees that the code you are currently looking at is correct, and allows reactive updating of dependant code. It's important to note that these are Pluto.jl features and not Julia features.
@ -42,8 +38,6 @@ md"""
To get started, I want to focus on things that Matlab does that are outlandish and make little sense and compare them to things Julia does. Julia is obviously not perfect, but being that it's one of the newest and fastest-growing languages, it's easy to argue that Julia's syntax and language design are the most modern and sane currently available in programming, primarily if you are focusing on engineering or science workloads. To get started, I want to focus on things that Matlab does that are outlandish and make little sense and compare them to things Julia does. Julia is obviously not perfect, but being that it's one of the newest and fastest-growing languages, it's easy to argue that Julia's syntax and language design are the most modern and sane currently available in programming, primarily if you are focusing on engineering or science workloads.
In future chapters, I will focus more on how Julia shines rather than why Matlab doesn't.
### Enviroments ### Enviroments
A significant pain point for large Matlab projects is managing installed Toolboxes and Packages. In Matlab, once something is installed it is available globally and doesn't have to be imported to a script to be used. There are quite a few downsides to this, the largest in my opinion: it is very easy to crowd your namespace. To make it even worse, Matlab usually doesn't even warn you about the issue so if two packages offer a function of the same name, it is just going to choose one and hope it works out. Another big issue this can cause is version conflicts. This is why there are so many issues trying to run code between Matlab versions. A significant pain point for large Matlab projects is managing installed Toolboxes and Packages. In Matlab, once something is installed it is available globally and doesn't have to be imported to a script to be used. There are quite a few downsides to this, the largest in my opinion: it is very easy to crowd your namespace. To make it even worse, Matlab usually doesn't even warn you about the issue so if two packages offer a function of the same name, it is just going to choose one and hope it works out. Another big issue this can cause is version conflicts. This is why there are so many issues trying to run code between Matlab versions.
@ -56,6 +50,11 @@ The best way to install packages is to open the Julia REPL (basically Matlab's c
Pluto will automatically install any of the packages in this notebook that you are missing, but this can take a long time since Julia is still very slow to compile new packages. Pluto will automatically install any of the packages in this notebook that you are missing, but this can take a long time since Julia is still very slow to compile new packages.
""" """
# ╔═╡ 072e459a-1423-45df-b269-8402b1683ea6
md"""
Since you have to import packages in order to use them there is never any ambiguity as to what package you need to run a script. In Matlab you simply get a warning saying it doesn't know what the function you are trying to use is but with Julia the compiler will even tell you the commands needed to install that package.
"""
# ╔═╡ 16a7201a-4ce0-4102-9874-96733514ef08 # ╔═╡ 16a7201a-4ce0-4102-9874-96733514ef08
md""" md"""
!!! warning !!! warning
@ -69,7 +68,7 @@ md"""
In Matlab its very common to grow an array in a for loop using `array(end+1)` _(You really should never do this since it creates a new array every loop which gets very inefficent, but I'm not here to teach you Matlab)_. In Julia, you use `push!` for adding a single number to the end of a `Vector` and `append!` to add collections _(also known as arrays or lists)_ to the end of a `Vector`. You'll notice that `!` at the end of the push and append functions. In Julia the exclamation point at the end of a function name means that the function modifies the function inputs in place compared to returning a new copy of the object. In Matlab its very common to grow an array in a for loop using `array(end+1)` _(You really should never do this since it creates a new array every loop which gets very inefficent, but I'm not here to teach you Matlab)_. In Julia, you use `push!` for adding a single number to the end of a `Vector` and `append!` to add collections _(also known as arrays or lists)_ to the end of a `Vector`. You'll notice that `!` at the end of the push and append functions. In Julia the exclamation point at the end of a function name means that the function modifies the function inputs in place compared to returning a new copy of the object.
!!! note "Indexing Syntax" !!! note "Indexing Syntax"
Array index syntax uses square brackets `[]` in Julia instead of parenthesis in Matlab `()`. Julia uses square brackets `[]` to index compared to parenthesis in Matlab `()`.
""" """
# ╔═╡ 0a4dc275-04b3-43e3-8a0d-cb921d769a0a # ╔═╡ 0a4dc275-04b3-43e3-8a0d-cb921d769a0a
@ -84,11 +83,14 @@ sort!(a); a # a is now sorted since sort!(a) sorts in place.
# ╔═╡ 58c883b6-3682-424d-a1e9-8ac561bb0dbf # ╔═╡ 58c883b6-3682-424d-a1e9-8ac561bb0dbf
a[end+1] = 5 # Can't grow array by indexing like in Matlab a[end+1] = 5 # Can't grow array by indexing like in Matlab
# ╔═╡ a0748b65-171a-49e3-a018-8cb7b8c0bc31
push!(a, 5) # Correct way to grow the array.
# ╔═╡ a74e7cad-8dae-41cd-b77a-65ba082956a3 # ╔═╡ a74e7cad-8dae-41cd-b77a-65ba082956a3
md""" md"""
### Functions ### Functions
Matlab functions have a ton of weird behaviors. The weirdest being that optional function returns are done based on the amount of return values so: Matlab functions have a ton of weird behaviors. The weirdest being that optional function returns are done based on the amount of return values like the follwing:
```julia ```julia
% Matlab Example % Matlab Example
@ -97,7 +99,7 @@ P = polyfit(X,Y,N)
[P,S,MU] = polyfit(X,Y,N) [P,S,MU] = polyfit(X,Y,N)
``` ```
all return different things. In this case, it's simple to tell what is going on, but if you had no idea what the `polyfit` function did in the first place it is totally unintuitive what the extra returned values are. If a function has optional returns in other languages, it is usually idiomatic to return those values with an optional keyword argument or just have a completely different function to get the different data. In the case of `polyfit`, calculating S and MU are unrelated to calculating P, so it is not like the data was already calculated and can be quickly returned like you would generally expect to be the case with optional returns. To make things even worse, `S` is designed to be an input to a different function, `POLYVAL`, so why wouldn't you just make polyval take `X`, `Y`, and `N` as inputs? Matlab is dumb `/endrant`. All of those function calls to `polyfit` return different things. In this case, it's simple to tell what is going on, but if you had no idea what the `polyfit` function did in the first place it is totally unintuitive what the extra returned values are. If a function has optional returns in other languages, it is usually idiomatic to return those values with an optional keyword argument or just have a completely different function to get the different data. In the case of `polyfit`, calculating S and MU are unrelated to calculating P, so it is not like the data was already calculated and can be quickly returned like you would generally expect to be the case with optional returns. To make things even worse, `S` is designed to be an input to a different function, `POLYVAL`, so why wouldn't you just make polyval take `X`, `Y`, and `N` as inputs? Matlab is dumb `/endrant`.
Another weird thing is where functions can be placed in Matlab. In livescripts they can only be placed at the end of the file, and there's also the ability to make files that are only a function. In Julia, functions can be anywhere, and files can contain as many functions as you want and can be imported by any other file. The function syntax in Julia is also very sane. Another weird thing is where functions can be placed in Matlab. In livescripts they can only be placed at the end of the file, and there's also the ability to make files that are only a function. In Julia, functions can be anywhere, and files can contain as many functions as you want and can be imported by any other file. The function syntax in Julia is also very sane.
""" """
@ -129,7 +131,7 @@ end
# ╔═╡ 3c921f2d-3972-4b88-990d-36ced0764bc5 # ╔═╡ 3c921f2d-3972-4b88-990d-36ced0764bc5
# Julia will always use the closest matching function. # Julia will always use the closest matching function.
function g(x::Int, y::Int) # x and y need to be integers function g(x::Int, y::Int) # x and y need to be integers
z = x+y # last line is returned, so really could just be x+y without the z x + y # last line in a function gets returned
end end
# ╔═╡ b7ae33bc-5edd-4741-a578-d210521b1698 # ╔═╡ b7ae33bc-5edd-4741-a578-d210521b1698
@ -139,7 +141,7 @@ g(14) # Since there are 4 different methods for g Julia will find and use the cl
g(5.0, 6.0) # Normal g function used since inputs are floats g(5.0, 6.0) # Normal g function used since inputs are floats
# ╔═╡ 8688fe79-00ad-497f-a466-dc86af9e03b0 # ╔═╡ 8688fe79-00ad-497f-a466-dc86af9e03b0
g() # Uses normal g function since there is no match for g that has a Int and a Float specified as inputs. g(4, 2.1) # Uses most generic g function since there is no match for g that has a Int and a Float specified as inputs.
# ╔═╡ 9440e0bc-7920-4b81-b88a-0b1046d24b4c # ╔═╡ 9440e0bc-7920-4b81-b88a-0b1046d24b4c
g(5, 6) # Integer method used since inputs are both integers. g(5, 6) # Integer method used since inputs are both integers.
@ -161,7 +163,7 @@ Matlab generally does broadcasting for you which can be dangerous since sometime
b = 1:5 # Ranges are similar to Matlab, but will discussed later in the text b = 1:5 # Ranges are similar to Matlab, but will discussed later in the text
# ╔═╡ 6124f6b4-6315-4d74-9067-4553ce1d54bc # ╔═╡ 6124f6b4-6315-4d74-9067-4553ce1d54bc
sin(b) # gotta broadcast! sin(b) # Error, gotta broadcast!
# ╔═╡ 95e30983-f305-41aa-a1e2-f38fa0d0c1c3 # ╔═╡ 95e30983-f305-41aa-a1e2-f38fa0d0c1c3
sin.(b) # Nice! sin.(b) # Nice!
@ -188,11 +190,11 @@ Matlab evaluates arrays when they are made which is very common in programming l
# ╔═╡ e3c28497-29e9-447e-aba0-650aaaa52d88 # ╔═╡ e3c28497-29e9-447e-aba0-650aaaa52d88
typeof(1:10) typeof(1:10)
# ╔═╡ 4fd4f72d-45e0-4760-bc0b-5ebb78636e2c # ╔═╡ cc419cd3-75fc-4ae6-b41f-17bf5b537771
enumerate(1:.25:2) # returns an enumerate object collect(1:10)
# ╔═╡ cf125fe2-c754-4218-92c9-3f491f3109c1 # ╔═╡ 4fd4f72d-45e0-4760-bc0b-5ebb78636e2c
collect(enumerate(1:.25:2)) # Returns an an array of tuples as expected enumerate([5 4 3 2 1]) # enumeration is also lazy
# ╔═╡ 4802d903-e87c-4ef0-a184-e4ae7af69a28 # ╔═╡ 4802d903-e87c-4ef0-a184-e4ae7af69a28
md""" md"""
@ -207,10 +209,10 @@ Plots use very similar syntax to Matlab with the exception that there is no `hol
""" """
# ╔═╡ a4665e30-4c64-46d1-8349-a49f40763a0b # ╔═╡ a4665e30-4c64-46d1-8349-a49f40763a0b
plot(sin) plot(sin) # We can plot functions
# ╔═╡ 09303ffe-6cf8-4273-b697-9fbd7cb82cc1 # ╔═╡ 09303ffe-6cf8-4273-b697-9fbd7cb82cc1
plot(cos) # Makes a new plot! plot(cos) # Makes a new plot since we didnt use plot!
# ╔═╡ e3b51038-2e57-4a5a-9b5d-7bf7148d700b # ╔═╡ e3b51038-2e57-4a5a-9b5d-7bf7148d700b
begin begin
@ -222,6 +224,23 @@ end
# ╔═╡ 55e0d022-faca-40f8-a4a9-3a501eb5d19e # ╔═╡ 55e0d022-faca-40f8-a4a9-3a501eb5d19e
plot!(atan, label="atan") # Returns a new plot with all the elements of the old plot. plot!(atan, label="atan") # Returns a new plot with all the elements of the old plot.
# ╔═╡ 4cd38b1c-e85c-49c7-9871-b893bc53c686
let
x = -10:10
y = x.^2
plot(x, y, title="We can also plot x-y data", label="")
end
# ╔═╡ 2f3b1426-5e16-4d24-9ade-e5c88d8cb9b7
let
t = 0:.001:2π
x = sin.(t)
y = cos.(t)
z = sin.(4t)
plot(x,y,z, title="We can even do 3d plots!", label="3 Dimensions!")
end
# ╔═╡ dc89d08d-29bf-4e04-8470-c79c88ab4689 # ╔═╡ dc89d08d-29bf-4e04-8470-c79c88ab4689
md""" md"""
!!! note !!! note
@ -262,20 +281,20 @@ md"""
There are a few ways that Julia really shines that make it perfect for engineering and science. Below are a few examples. There are a few ways that Julia really shines that make it perfect for engineering and science. Below are a few examples.
## Symbols ### Symbols
Julia supports a wide variety of unicode symbols in the language that can be accessed with the syntax `\pi{tab}` to get π. This is a great way to make code closer to LaTex or handwritten examples which makes it easier to read or understand. Julia supports a wide variety of unicode symbols in the language that can be accessed with the syntax `\pi{tab}` to get π. This is a great way to make code closer to $\LaTeX$ or handwritten examples which makes it easier to read or understand.
* `\theta{tab}` θ * `\theta{tab}` θ
* `q\bar{tab}` * `q\bar{tab}`
* `x\ddot{tab}` * `x\ddot{tab}`
## List Comprehension ### List Comprehension
List comprehensions can be thought of single line for loops and can be very handy in a variety of scenarios. The syntax is: List comprehensions can be thought of single line for loops and can be very handy in a variety of scenarios. The syntax is:
```julia ```julia
# Add 1 to each number in a list of numbers # Add 1 to each number in the list called numbers
[number + 1 for number in numbers] [number + 1 for number in numbers]
``` ```
@ -288,6 +307,9 @@ List comprehensions are especially useful instead of one line for loops, or when
# ╔═╡ 2172de3a-7dba-4cbc-9c04-444db595c328 # ╔═╡ 2172de3a-7dba-4cbc-9c04-444db595c328
[x for x in 1:12 if x % 3 == 0] [x for x in 1:12 if x % 3 == 0]
# ╔═╡ b519ad43-dd1f-41f2-8b6c-f6196ae1df76
@benchmark 1+1; # This just makes sure benchmark is precompiled to ensure the tests below are accurate
# ╔═╡ fd0f5cf6-c90b-4492-9c72-9e707803e736 # ╔═╡ fd0f5cf6-c90b-4492-9c72-9e707803e736
md""" md"""
Since `append!` is usually very slow you can see below that using a list comprehension to create a vector is almost 10x faster. Since `append!` is usually very slow you can see below that using a list comprehension to create a vector is almost 10x faster.
@ -295,15 +317,22 @@ Since `append!` is usually very slow you can see below that using a list compreh
# ╔═╡ a2c7e472-2460-428e-bfec-acf925fad89d # ╔═╡ a2c7e472-2460-428e-bfec-acf925fad89d
begin begin
function f()
t = [] t = []
for i in 1:1e6 for i in 1:1e6
append!(t,i) append!(t,i)
end end
t end
@benchmark f()
end end
# ╔═╡ bce2eecc-dc01-4bf6-9eaa-880fd8a69768 # ╔═╡ bce2eecc-dc01-4bf6-9eaa-880fd8a69768
[i for i in 1:1e6] @benchmark [i for i in 1:1e6]
# ╔═╡ 881367d3-a247-4bdc-92d4-f3e205982837
md"""
Note that not only is it much faster, but the memory usage and allocations are much lower aswell.
"""
# ╔═╡ a2df1c35-c0b2-45bb-86b7-57e208287392 # ╔═╡ a2df1c35-c0b2-45bb-86b7-57e208287392
md""" md"""
@ -350,183 +379,32 @@ weight |> u"N"
# ╔═╡ 8d4de01a-197f-40cb-942f-bfec335e3844 # ╔═╡ 8d4de01a-197f-40cb-942f-bfec335e3844
md""" md"""
Units can also be stripped to give a normal number again. Units can also be stripped to give a normal number again. This is important since most other packages don't have support for units. Yet.
""" """
# ╔═╡ 86da848f-1e84-47c8-8a79-373f241b6025 # ╔═╡ 86da848f-1e84-47c8-8a79-373f241b6025
ustrip(u"N", weight) ustrip(u"N", weight)
# ╔═╡ dc898d32-b30b-4baa-a595-b83ccd1dc86d # ╔═╡ ee5aad93-0437-429d-969e-fee239e6a577
md""" md"""
# Everything below isn't close to being finished ## Conclusion
"""
# ╔═╡ 9ea4584c-8177-4f69-9739-b2faa93281a8 This is only scratching the surface of the differences between the two languages, but I hope this can serve as a starting point. In the future, I would like to dig more into the differences since I do think that Julia will eclipse Matlab in use in engineering before too long.
md"""
---
### Matrix Math I am currently rewriting large amounts of code from Matlab to Julia, so hopefully, through that experience, I can provide a more detailed explanation and, ideally, some information that will be useful to other people making the same transition.
"""
# ╔═╡ f43812d2-9f87-489a-9317-e7aa19ffd3bc
md"""
---
### Custom Data Types
"""
# ╔═╡ f6d87354-ac46-4202-92f8-b39a0db13327
μ = 3.986004418e14u"m^3/s^2" # Standard Gravitational Parameter for Earth
# ╔═╡ f8039870-2570-47d0-8d46-30922415ec9d
earth_radius = 6378u"km"
# ╔═╡ 863cd607-a459-49ae-9049-983f3374f523
abstract type Orbit end
# ╔═╡ 44daff45-f608-47e3-ad6e-fca43532f322
struct Circular_Orbit <: Orbit
"""Simple 2d circular orbit"""
r::typeof(.1u"km") # altitude
end
# ╔═╡ efb58b79-24e4-45c6-ad45-aeaa339d82fd
ISS = Circular_Orbit(420u"km")
# ╔═╡ ad3a2b19-5639-4d11-8d89-bc54772d639b
struct Elliptic_Orbit <: Orbit
"""Simple 2d elliptic orbit"""
r::typeof(.1u"km") # altitude
a::typeof(.1u"km") # semimajor axis
e::Float64 # eccentricity
function Elliptic_Orbit(r, a, e)
@assert e < 1 "Eccentricity must be less than 1!"
@assert 0 < e "Eccentricity must be greater than 0!"
new(r, a, e)
end
function Elliptic_Orbit(perigee, apogee)
a = (perigee + apogee) / 2
e = 1 - (perigee/a)
r = a*((1-e^2)/(1+e)) # Assume θ is 0 since we aren't keeping track of it
Elliptic_Orbit(r,a,e)
end
end
# ╔═╡ b4e08868-d48a-4f66-9d20-f45ea4d83f00
sat = Elliptic_Orbit(earth_radius+537.0u"km", earth_radius+9040.9u"km")
# ╔═╡ 3efd8a29-6a56-4f5c-9cab-0f08875b2064
function get_velocity(o::Circular_Orbit)
v = sqrt(μ/o.r)
return v |> u"km/s"
end
# ╔═╡ 59207a25-fa6d-4369-979d-cd9cc2f094cf
function get_velocity(o::Elliptic_Orbit)
v = sqrt(μ*(2/o.r - 1/o.a))
return v |> u"km/s"
end
# ╔═╡ 11fb3a28-edf3-46ff-8c4a-5286793b6e43
get_velocity(ISS)
# ╔═╡ 79a9ab94-06a8-4613-8f60-358e08f0f32e
get_velocity(sat)
# ╔═╡ c3d943b4-809d-4a96-a99d-be7653ba2c8b
begin
function Plots.plot(orbit::Elliptic_Orbit)
a = orbit.a |> u"km" |> ustrip
b = orbit.a*sqrt(1-orbit.e^2) |> u"km" |> ustrip
t = 0:.01:2π
x_orbit(t) = a*cos(t)
y_orbit(t) = b*sin(t)
plot(x_orbit, y_orbit, t)
x_earth(t) = ustrip(earth_radius)*cos(t) + a*orbit.e
y_earth(t) = ustrip(earth_radius)*sin(t)
plot!(x_earth,y_earth, t, c=:gray,fill=(0,:blue), legend=false,aspect_ratio=:equal)
title!("Satellite Orbiting Earth")
end
plot(sat)
end
# ╔═╡ 01ba1742-d26e-4271-ab62-0bd9ce5e291d
function get_ΔV(start::Orbit, final::Orbit)
get_velocity(start) - get_velocity(final)
end
# ╔═╡ ad4d24a8-f601-4522-a3eb-c01f6fd68aec
get_ΔV(ISS,sat)
# ╔═╡ 2d0de5db-5558-41e0-96d5-a3317d151aff
# ╔═╡ 8924673f-e99c-44b3-be6d-2abf0b2f5e23
md"""
---
### Tabular Data
"""
# ╔═╡ c460478a-db52-4a15-a723-9ff64eed9aec
# download_csv(url) = DataFrame(CSV.File(download(url)))
download_csv(url) = url |> download |> CSV.File |> DataFrame
# ╔═╡ 9ccbea0d-6463-4533-88a6-0267879eb263
F10 = download_csv("julia.ansonbiggs.com/AeroTech_F10.csv")
# ╔═╡ 4ffebbb2-7021-4c08-82ac-95366dab3d48
G8 = download_csv("julia.ansonbiggs.com/AeroTech_G8ST.csv")
# ╔═╡ 2e83292e-8e8c-43e4-82ee-951a2f6a98c1
F15 = download_csv("julia.ansonbiggs.com/Estes_F15.csv")
# ╔═╡ c7e2a7f8-626f-45d8-b771-6f9e74a86bd8
let
plot(title = "Rocket Motor Comparison", xlabel="Time (s)", ylabel="Thrust (N)")
plot!(F10.Time, F10.Thrust,label="F10")
plot!(G8.Time, G8.Thrust,label="G8")
plot!(F15.Time, F15.Thrust,label="F15")
end
# ╔═╡ 8ec4af16-1a19-468e-b097-59985bf28f5c
describe(F10)
# ╔═╡ 9f886419-7259-442e-b068-d0e4c886a886
maximum.([F10.Thrust, G8.Thrust, F15.Thrust])
# ╔═╡ fbc06121-d53a-4a64-9497-63d7f3583fbb
md"""
## Things Julia Does Poorly
- Time to First Plot
- Libraries
- Still young and breaking things
""" """
# ╔═╡ 00000000-0000-0000-0000-000000000001 # ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """ PLUTO_PROJECT_TOML_CONTENTS = """
[deps] [deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8" PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[compat] [compat]
CSV = "~0.8.5" BenchmarkTools = "~1.1.3"
DataFrames = "~1.2.0"
FileIO = "~1.11.0"
Plots = "~1.19.0" Plots = "~1.19.0"
PlutoUI = "~0.7.9" PlutoUI = "~0.7.9"
Unitful = "~1.8.0" Unitful = "~1.8.0"
@ -551,18 +429,18 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[Base64]] [[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Statistics", "UUIDs"]
git-tree-sha1 = "aa3aba5ed8f882ed01b71e09ca2ba0f77f44a99e"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.1.3"
[[Bzip2_jll]] [[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c3598e525718abcc440f69cc6d5f60dda0a1b61e" git-tree-sha1 = "c3598e525718abcc440f69cc6d5f60dda0a1b61e"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.6+5" version = "1.0.6+5"
[[CSV]]
deps = ["Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"]
git-tree-sha1 = "b83aa3f513be680454437a0eee21001607e5d983"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.8.5"
[[Cairo_jll]] [[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"] deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "e2f47f6d8337369411569fd45ae5753ca10394c6" git-tree-sha1 = "e2f47f6d8337369411569fd45ae5753ca10394c6"
@ -609,22 +487,11 @@ git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7" version = "0.5.7"
[[Crayons]]
git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.0.4"
[[DataAPI]] [[DataAPI]]
git-tree-sha1 = "ee400abb2298bd13bfc3df1c412ed228061a2385" git-tree-sha1 = "ee400abb2298bd13bfc3df1c412ed228061a2385"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.7.0" version = "1.7.0"
[[DataFrames]]
deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "1dadfca11c0e08e03ab15b63aaeda55266754bad"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.2.0"
[[DataStructures]] [[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"] deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677" git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677"
@ -676,12 +543,6 @@ git-tree-sha1 = "3cc57ad0a213808473eafef4845a74766242e05f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.3.1+4" version = "4.3.1+4"
[[FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "937c29268e405b6808d958a9ac41bfe1a31b08e7"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.11.0"
[[FixedPointNumbers]] [[FixedPointNumbers]]
deps = ["Statistics"] deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
@ -712,10 +573,6 @@ git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c" uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0" version = "1.0.10+0"
[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
[[GLFW_jll]] [[GLFW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"]
git-tree-sha1 = "dba1e8614e98949abfa60480b13653813d8f0157" git-tree-sha1 = "dba1e8614e98949abfa60480b13653813d8f0157"
@ -773,12 +630,6 @@ version = "0.5.0"
deps = ["Markdown"] deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[InvertedIndices]]
deps = ["Test"]
git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.0.0"
[[IterTools]] [[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
@ -1024,24 +875,12 @@ git-tree-sha1 = "44e225d5837e2a2345e69a1d1e01ac2443ff9fcb"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8" uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.9" version = "0.7.9"
[[PooledArrays]]
deps = ["DataAPI", "Future"]
git-tree-sha1 = "cde4ce9d6f33219465b55162811d8de8139c0414"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "1.2.1"
[[Preferences]] [[Preferences]]
deps = ["TOML"] deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250" uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2" version = "1.2.2"
[[PrettyTables]]
deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"]
git-tree-sha1 = "0d1245a357cc61c8cd61934c07447aa569ff22e6"
uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
version = "1.1.0"
[[Printf]] [[Printf]]
deps = ["Unicode"] deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@ -1091,12 +930,6 @@ git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda"
uuid = "6c6a2e73-6563-6170-7368-637461726353" uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.1.0" version = "1.1.0"
[[SentinelArrays]]
deps = ["Dates", "Random"]
git-tree-sha1 = "ffae887d0f0222a19c406a11c3831776d1383e3d"
uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
version = "1.3.3"
[[Serialization]] [[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
@ -1413,12 +1246,14 @@ version = "0.9.1+5"
# ╟─307cbf7a-1ac5-47a5-8031-3458f9dd1887 # ╟─307cbf7a-1ac5-47a5-8031-3458f9dd1887
# ╟─11ed58ac-1289-4b64-88a8-17cb7f0b6cd2 # ╟─11ed58ac-1289-4b64-88a8-17cb7f0b6cd2
# ╠═7d7820ff-c0f5-41ee-be29-5006e7f4361d # ╠═7d7820ff-c0f5-41ee-be29-5006e7f4361d
# ╟─072e459a-1423-45df-b269-8402b1683ea6
# ╟─16a7201a-4ce0-4102-9874-96733514ef08 # ╟─16a7201a-4ce0-4102-9874-96733514ef08
# ╟─3cad3f5f-f6a5-405b-aeb0-495ebd8cca45 # ╟─3cad3f5f-f6a5-405b-aeb0-495ebd8cca45
# ╠═0a4dc275-04b3-43e3-8a0d-cb921d769a0a # ╠═0a4dc275-04b3-43e3-8a0d-cb921d769a0a
# ╠═193c6a29-4f53-4c96-acc7-b5359043b471 # ╠═193c6a29-4f53-4c96-acc7-b5359043b471
# ╠═6fa90db6-9d2b-47bc-9f41-925b447912e8 # ╠═6fa90db6-9d2b-47bc-9f41-925b447912e8
# ╠═58c883b6-3682-424d-a1e9-8ac561bb0dbf # ╠═58c883b6-3682-424d-a1e9-8ac561bb0dbf
# ╠═a0748b65-171a-49e3-a018-8cb7b8c0bc31
# ╟─a74e7cad-8dae-41cd-b77a-65ba082956a3 # ╟─a74e7cad-8dae-41cd-b77a-65ba082956a3
# ╠═f4d655a2-8539-43f7-9356-56a3e3f9de91 # ╠═f4d655a2-8539-43f7-9356-56a3e3f9de91
# ╠═289727e4-fb29-4ba8-97c5-cce62da725bc # ╠═289727e4-fb29-4ba8-97c5-cce62da725bc
@ -1440,22 +1275,27 @@ version = "0.9.1+5"
# ╟─3ef67004-2f85-4aa1-a1b5-5cbf62b292f7 # ╟─3ef67004-2f85-4aa1-a1b5-5cbf62b292f7
# ╠═1025e3a8-59c9-4725-bc1a-a0b94e6bd6af # ╠═1025e3a8-59c9-4725-bc1a-a0b94e6bd6af
# ╠═e3c28497-29e9-447e-aba0-650aaaa52d88 # ╠═e3c28497-29e9-447e-aba0-650aaaa52d88
# ╠═cc419cd3-75fc-4ae6-b41f-17bf5b537771
# ╠═4fd4f72d-45e0-4760-bc0b-5ebb78636e2c # ╠═4fd4f72d-45e0-4760-bc0b-5ebb78636e2c
# ╠═cf125fe2-c754-4218-92c9-3f491f3109c1
# ╟─4802d903-e87c-4ef0-a184-e4ae7af69a28 # ╟─4802d903-e87c-4ef0-a184-e4ae7af69a28
# ╠═52819547-9593-446a-91e7-a08e08723e66 # ╠═52819547-9593-446a-91e7-a08e08723e66
# ╠═a4665e30-4c64-46d1-8349-a49f40763a0b # ╠═a4665e30-4c64-46d1-8349-a49f40763a0b
# ╠═09303ffe-6cf8-4273-b697-9fbd7cb82cc1 # ╠═09303ffe-6cf8-4273-b697-9fbd7cb82cc1
# ╠═e3b51038-2e57-4a5a-9b5d-7bf7148d700b # ╠═e3b51038-2e57-4a5a-9b5d-7bf7148d700b
# ╠═55e0d022-faca-40f8-a4a9-3a501eb5d19e # ╠═55e0d022-faca-40f8-a4a9-3a501eb5d19e
# ╠═4cd38b1c-e85c-49c7-9871-b893bc53c686
# ╠═2f3b1426-5e16-4d24-9ade-e5c88d8cb9b7
# ╟─dc89d08d-29bf-4e04-8470-c79c88ab4689 # ╟─dc89d08d-29bf-4e04-8470-c79c88ab4689
# ╟─b30e6f73-fe46-45e7-898e-dd1205dffe68 # ╟─b30e6f73-fe46-45e7-898e-dd1205dffe68
# ╟─916f5f09-1aa3-47a7-9c66-c42513eaccea # ╟─916f5f09-1aa3-47a7-9c66-c42513eaccea
# ╠═2172de3a-7dba-4cbc-9c04-444db595c328 # ╠═2172de3a-7dba-4cbc-9c04-444db595c328
# ╠═c231f030-5861-4b30-a182-efc06b5c08fe
# ╟─b519ad43-dd1f-41f2-8b6c-f6196ae1df76
# ╟─fd0f5cf6-c90b-4492-9c72-9e707803e736 # ╟─fd0f5cf6-c90b-4492-9c72-9e707803e736
# ╠═a2c7e472-2460-428e-bfec-acf925fad89d # ╠═a2c7e472-2460-428e-bfec-acf925fad89d
# ╠═bce2eecc-dc01-4bf6-9eaa-880fd8a69768 # ╠═bce2eecc-dc01-4bf6-9eaa-880fd8a69768
# ╟─a2df1c35-c0b2-45bb-86b7-57e208287392 # ╠═881367d3-a247-4bdc-92d4-f3e205982837
# ╠═a2df1c35-c0b2-45bb-86b7-57e208287392
# ╠═3228a21e-cab8-4738-bdc5-a6827c764c06 # ╠═3228a21e-cab8-4738-bdc5-a6827c764c06
# ╟─7b9b11f2-c6d3-4dab-ab30-6e47a3a4bfb3 # ╟─7b9b11f2-c6d3-4dab-ab30-6e47a3a4bfb3
# ╠═09bc71cd-7bc0-4d5a-bcf8-984abe273375 # ╠═09bc71cd-7bc0-4d5a-bcf8-984abe273375
@ -1466,33 +1306,6 @@ version = "0.9.1+5"
# ╠═ade2979d-155e-4f20-82db-6da141bb8eaa # ╠═ade2979d-155e-4f20-82db-6da141bb8eaa
# ╟─8d4de01a-197f-40cb-942f-bfec335e3844 # ╟─8d4de01a-197f-40cb-942f-bfec335e3844
# ╠═86da848f-1e84-47c8-8a79-373f241b6025 # ╠═86da848f-1e84-47c8-8a79-373f241b6025
# ╟─dc898d32-b30b-4baa-a595-b83ccd1dc86d # ╟─ee5aad93-0437-429d-969e-fee239e6a577
# ╠═9ea4584c-8177-4f69-9739-b2faa93281a8
# ╠═f43812d2-9f87-489a-9317-e7aa19ffd3bc
# ╠═f6d87354-ac46-4202-92f8-b39a0db13327
# ╠═f8039870-2570-47d0-8d46-30922415ec9d
# ╠═863cd607-a459-49ae-9049-983f3374f523
# ╠═44daff45-f608-47e3-ad6e-fca43532f322
# ╠═efb58b79-24e4-45c6-ad45-aeaa339d82fd
# ╠═ad3a2b19-5639-4d11-8d89-bc54772d639b
# ╠═b4e08868-d48a-4f66-9d20-f45ea4d83f00
# ╠═3efd8a29-6a56-4f5c-9cab-0f08875b2064
# ╠═59207a25-fa6d-4369-979d-cd9cc2f094cf
# ╠═11fb3a28-edf3-46ff-8c4a-5286793b6e43
# ╠═79a9ab94-06a8-4613-8f60-358e08f0f32e
# ╠═c3d943b4-809d-4a96-a99d-be7653ba2c8b
# ╠═01ba1742-d26e-4271-ab62-0bd9ce5e291d
# ╠═ad4d24a8-f601-4522-a3eb-c01f6fd68aec
# ╠═2d0de5db-5558-41e0-96d5-a3317d151aff
# ╠═8924673f-e99c-44b3-be6d-2abf0b2f5e23
# ╠═3f7ae2df-9d4d-46d3-b12e-22107a560b66
# ╠═c460478a-db52-4a15-a723-9ff64eed9aec
# ╠═9ccbea0d-6463-4533-88a6-0267879eb263
# ╠═4ffebbb2-7021-4c08-82ac-95366dab3d48
# ╠═2e83292e-8e8c-43e4-82ee-951a2f6a98c1
# ╠═c7e2a7f8-626f-45d8-b771-6f9e74a86bd8
# ╠═8ec4af16-1a19-468e-b097-59985bf28f5c
# ╠═9f886419-7259-442e-b068-d0e4c886a886
# ╠═fbc06121-d53a-4a64-9497-63d7f3583fbb
# ╟─00000000-0000-0000-0000-000000000001 # ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002 # ╟─00000000-0000-0000-0000-000000000002