-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro-to-julia.jl
2951 lines (2410 loc) · 101 KB
/
intro-to-julia.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.39
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ 60ea6a34-7d40-4527-a751-54ae0c691296
using PlutoUI
# ╔═╡ 33cf1e80-95f8-440f-8b10-f5ad180d94d4
# Why types are important in Julia
using BenchmarkTools
# ╔═╡ 9f6ac044-abd4-4c0f-a4a3-47081a925adb
using LinearAlgebra
# ╔═╡ 13aaeceb-e873-4865-a1c1-0d50251f7ed0
begin
# Example of plots
using Plots
gr() # for quick visualization
# pythonplot() # Python styled
# pgfplots() # for publication quality
# data
x = (rand(100))
y = x.^2
#plot(x, y, label=:"Line", framestyle=[:box :grid])
scatter(x, y, label="Scattered Data",legend=:topleft,
markersize=4, markercolor=:blue,
markerstrokewidth=0, markeralpha=0.9)
xaxis!("X-label"); xlims!(0,1); xticks!(-1:0.2:1)
yaxis!("Y-label"); ylims!(0,1); yticks!(0:0.1:1)
#savefig("examples/test01.pdf")
end
# ╔═╡ b7b978c9-10f9-41f9-abb2-cd44216165c4
begin
# Example of plots
using PythonPlot
# gr() # for quick visualization
pythonplot() # Python styled
#pgfplots() # for publication quality
# data same as above
#plot(x, y, label=:"Line", framestyle=[:box :grid])
PythonPlot.scatter(x, y, label="Scattered Data")
xaxis!("X-label"); xlims!(0,1); xticks!(-1:0.2:1)
yaxis!("Y-label"); ylims!(0,1); yticks!(0:0.1:1)
#savefig("examples/test01.pdf")
end
# ╔═╡ e3c72b48-8d17-4b4e-bfcc-a615e8547672
using PlutoExtras
# ╔═╡ da266718-431f-4bcf-9c5b-e8e440e65029
using DifferentialEquations
# ╔═╡ 91b30a34-bc11-4d78-a9b2-2d2c7f964fc9
html"<button onclick='present()'>present</button>"
# ╔═╡ 9672457b-650d-4970-87f1-d4d501abb566
struct TwoColumn{A, B}
left::A
right::B
end
# ╔═╡ 188d2334-c6c0-43ab-92bb-33440e785687
function Base.show(io, mime::MIME"text/html", tc::TwoColumn)
write(io,
"""
<div style="display: flex;">
<div style="flex: 50%;">
""")
show(io, mime, tc.left)
write(io,
"""
</div>
<div style="flex: 50%;">
""")
show(io, mime, tc.right)
write(io,
"""
</div>
</div>
""")
end
# ╔═╡ e3e52c62-d0d2-11ee-2402-df85ba2126b0
md"""
# Introduction to Julia Language
"""
# ╔═╡ 495e28d9-9a99-413b-8302-e334a47452ab
md"""
### Why Julia
- A reasonable compromise between slow, dynamic interpreted languages (e.g., Python) and fast, static compiled languages (e.g., C)
- Main focus is numerical computations, performance and ease of writing
- Robust package management and programming ecosystem
- It is time to move on from Fortran
"""
# ╔═╡ e1d9e83c-8179-4642-a626-0260eb5000f5
md"""
## [Download Julia](https://julialang.org/downloads/)
"""
# ╔═╡ 987c3716-b00d-4843-a294-23e723535675
LocalResource("/Users/pthakur8/workInbox/2024/workshops/intro-to-julia/julia_home.png")
# ╔═╡ 62e8a1db-94f0-45e6-9835-778fae3018c6
md"""
## Julia in a nutshell
##### Fast
Julia was designed for high performance. Julia programs automatically compile to efficient native code via LLVM, and support multiple platforms.
##### Dynamic
Julia is dynamically typed, feels like a scripting language, and has good support for interactive use, but can also optionally be separately compiled.
##### Reproducible
Reproducible environments make it possible to recreate the same Julia environment every time, across platforms, with pre-built binaries.
##### Composable
Julia uses multiple dispatch as a paradigm, making it easy to express many object-oriented and functional programming patterns. The talk on the Unreasonable Effectiveness of Multiple Dispatch explains why it works so well.
##### General
Julia provides asynchronous I/O, metaprogramming, debugging, logging, profiling, a package manager, and more. One can build entire Applications and Microservices in Julia.
##### Open source
Julia is an open source project with over 1,000 contributors. It is made available under the MIT license. The source code is available on GitHub.
"""
# ╔═╡ 1025dd46-3b73-4df7-9003-5a4c11a83037
md"""
## Create a virtual environment to work with
```julia
$ julia
]generate <package_name>
]activate <package_name>
]add Plots Pluto
```
### What this does?
```sh
➜ intro-to-julia tree intro_julia
intro_julia
├── Manifest.toml
├── Project.toml
└── src
└── intro_julia.jl
```
"""
# ╔═╡ f82fa353-64e5-430a-8dd4-2a424d91c98b
md"""
## Run the [pluto notebook](https://plutojl.org/)
```julia
julia> using Pluto
julia> Pluto.run()
```
Pluto: very similar to jupyter notebook, but it is reactive, and easier version control.
#### Reactivity example:
"""
# ╔═╡ 11fa1cc8-f855-442e-afe1-9f2953f11d61
a = 7 # Changing `a` here automatically makes changes throughout the notebook
# ╔═╡ 4738b2c4-89ad-41ce-8c3f-e32c761c7ddf
b = a + 2
# ╔═╡ 59b0bda6-d406-4d1a-a559-23762a52646b
md"""
## Hello world!
We can use the base function `println()` to print stuff!
"""
# ╔═╡ d37aa9ca-13f8-4d17-9cef-883618a4f22d
println("Hello, World!")
# ╔═╡ 55d4b6ea-e37e-48db-9234-d8bb031e92a1
md"""
## Data Types
**Static type system**: typical for compiled languages, where every expression must have a type computable before the execution of the program.
**Dynamic type system**: typical for interpreted languages, where the type of the expression is determined at run time, and nothing is known beforehand.
Julia has dynamic type system, and standard data types typical for most dynamic type programming languages:
* Primitive types: is a concrete type whose data consists of just bits.
* Numeric types: `Int64, Float64, BigFloat, Complex`, etc.
* `String` and `Char` for characters.
* Abstract types: `Any, Real, Number, Integer`. You can create your own abstract types as well. These are not instantiated, and only serve as describing sets of related types, i.e., they form a conceptual hierarchy but are not ascribed to a specific expression.
* Composite types: a collection of named fields, an instance of which can be treated as a single value.
* `struct`
Julia is a functional programming language, so you don't have classes and objects. In pure object-oriented languages (e.g., Ruby and Smalltalk), all values are objects, whether they are composite or not. In C++/Java, you have objects and standalone types (e.g., `int` or `float`).
In Julia, all values are objects, but functions are not bundled with the objects they operate on.
"""
# ╔═╡ 48f8f5da-d034-484b-8d07-f275ba41027c
md"""
#### Abstract types
```julia
abstract type «name» end
abstract type «name» <: «supertype» end
```
The default supertype is `Any`.
Examples:
```julia
abstract type Number end
abstract type Real <: Number end
abstract type AbstractFloat <: Real end
abstract type Integer <: Real end
```
"""
# ╔═╡ 32b771af-7cc3-49a7-8ee1-71fab5b79540
md"""
## Why types are important in Julia
"""
# ╔═╡ a6a9c9ac-b470-4222-81cf-95bd81113933
@btime begin
x = rand(Int, 1000);
sum_x = 0.0
for i in x
sum_x += i
end
sum_x
end
# ╔═╡ 6b94782f-204a-43b7-81eb-77d69c730fd1
@btime begin
x = rand(Int, 1000);
sum_x = 0
for i in x
sum_x += i
end
sum_x
end
# ╔═╡ 4ff83a18-3ae7-44db-8d35-2bcdbdfdc0c4
begin
function myplus_typed(x::Int, y::Int)
x+y
end
function myplus(x, y)
x+y
end
end
# ╔═╡ 87fda310-83f1-4d1b-9214-5e290eb98971
@btime begin
x = rand(Int, 1000);
sum_x = 0
for i in x
sum_x = myplus_typed(i,sum_x)
end
sum_x
end
# ╔═╡ aac2d40b-89b0-4180-a8b2-efed29d7cf99
@btime begin
x = rand(Int, 1000);
sum_x = 0.0
for i in x
sum_x = myplus(i,sum_x)
end
sum_x
end
# ╔═╡ 99f01a9b-a809-4979-af4d-643ac3eacec7
md"""
## Composite types:
```julia
struct Foo
bar
baz::Int
qux::Float64
end
```
Struct is immutable by default, i.e., it cannot be modified after construction.
We have a `mutable` keyword we can use before struct to make it modifiable.
"""
# ╔═╡ 08e1a92c-c057-4220-82ce-5bbb63e6b367
struct Foo
bar
baz::Int
qux::Float64
end
# ╔═╡ 42d6adf5-c3aa-4021-9dea-dd5c1ecd3658
begin
foo1 = Foo("Hello!", 23, 3.14)
foo2 = Foo(83, 55, 1.57)
end
# ╔═╡ 4ef44902-49d0-4816-8251-48d07a28f60b
typeof(foo1)
# ╔═╡ 5943015b-ad71-410f-99f7-b11de783c28d
fieldnames(Foo)
# ╔═╡ 3dd4c845-1733-4d57-a880-7ffa6b85a76b
foo1.bar
# ╔═╡ 0b7ff119-cfdc-440e-a609-f1d0702bdfe7
foo2.bar
# ╔═╡ 0d6f1f9d-8bc6-488d-8738-a72341a184f7
md"""
## Mutable structs
Allows you to modify the fields after construction
"""
# ╔═╡ 44b5ddc2-534a-4c4e-992f-1f307c35f38f
mutable struct Bar
baz
qux::Float64
end
# ╔═╡ 10604ac1-cbaa-4662-baa8-df82b796a4b0
bar = Bar("Hello!", 1.5)
# ╔═╡ 73e0aea1-36e6-4473-a11c-66d540bfb552
bar.qux
# ╔═╡ 0d1ecc3f-8d73-444d-8ddc-60475681de9f
# Change the fields of the object bar
bar.qux = 2.5
# ╔═╡ f5388b1b-e86b-43f4-bb53-cec28fd2c6b1
bar
# ╔═╡ 7dfe6956-acb0-4897-bfea-e73c46c08420
md"""
## Constructors for a struct
Constructors are functions that create new objects: specifically, instances of Composite types.
The examples above are outer constructor methods.
While Julia is not purely object-oriented, it allows us to define inner constructor methods (functions) within a struct. Thus, most of our object-oriented needs are taken care of.
Additionally, inner methods have access to a special local function `new()` that creates objects of the same type as the struct.
"""
# ╔═╡ db765ef0-caed-49d5-86a3-5408bea3035d
struct Square
height::Int
width::Int
area::Int
function Square(h, w)
a = h * w
return new(h, w, a)
end
end
# ╔═╡ 3fa8cb34-0703-46e8-ac22-a327626bc987
sq = Square(5,3)
# ╔═╡ c6d8ac20-fa3b-44fb-a7e0-f57ff8820821
sq.area
# ╔═╡ d7c3d3ca-975e-4bda-9617-67bf8ab25cc0
##sq2 = Square(2,5,10)
# ╔═╡ 0a876d5c-e2c1-49af-b8eb-43918186a100
md"""
## Collections in Julia
* Array (and Vector and Matrix)
* Tuple (and NamedTuple)
* Set
* Dict
"""
# ╔═╡ db90a28d-cd3b-445d-960c-705fd536efbb
md"""
#### Array type
```julia
a = [4, 3, 1] # create 1-dimensional Array (i.e., Vector)
B = [4 5 6; 1 2 3] # create 2-dimensional Array (i.e., Matrix)
```
##### Useful constructors:
Use `LinearAlgebra` library for some more fancy matrices
```julia
zeros(type, n,m) # nxm matrix of zeros
ones(type, n,m) # nxm matrix of ones
I(n) # n-dimensional identity matrix
falses(n,m) # array of falses, similar to zeros
trues(n,m) # array of trues, similar to ones
rand(type, n,m) # array of random numbers, sampled from uniform distribution
randn(type, n,m) # sampled from normal distribution
```
Array indexing starts from 1
```
a = rand(5,5)
a[2:3, 4] # will return 2x1 array, 2nd and 3rd column of 4th row
```
"""
# ╔═╡ 759e3317-d5ec-4324-8556-9c399518a6dc
zeros(5)
# ╔═╡ d20a96ab-8715-42cf-aed3-006bd02d0af4
zeros(Int,5)
# ╔═╡ 5c606960-9965-4464-a5ed-60e0b9491ecb
I(5)
# ╔═╡ d3d4e6c7-18bc-4a72-b3c8-6adc83e567fe
falses(5,2)
# ╔═╡ f6c5d603-56b0-4a75-8022-d91f3224f192
matrix1 = rand(5,5)
# ╔═╡ 266c2092-1b9f-4fd6-9bd2-3935b747fc5d
matrix1[2:3,4]
# ╔═╡ 4b79c499-1fb3-4f0e-84f5-25b9268b1feb
md"""
## Vectorized dot `.` operator
For every binary operation (e.g., `+, -, ^`) there is a corresponding operation (`.+, .-, .^`) to perform element-wise operation on arrays and matrices.
These are vectorized, and perform a broadcast operation. That is, this operator applies the given function element-wise, without using extra memory.
"""
# ╔═╡ f7f5ff8e-5c95-476a-8027-801ff6a4b65f
vec1 = 1:5
# ╔═╡ 4a510c79-17b3-4597-a7bc-11d10814ccb6
vec2 = vec1 .^2
# ╔═╡ 99690d03-7621-41f5-bbca-f5ef0a0a1687
vec2 .> 10
# ╔═╡ 72af35fe-546a-48a5-b0ae-4e0dac6bfe36
vec2[vec2 .> 10]
# ╔═╡ d3db7943-27fb-44f8-bee9-c4431427b399
md"""
## Tuples
Fixed length, immutable, can hold heterogeneous data
```julia
tuple1 = (3.14, "pie") # Create tuple with 2 elements
tuple1[2] # access elements
```
**Named tuple**
```julia
ntuple1 = (firstname = "Prithvi", lastname = "Thakur", id = 25)
# Can be accessed via name
ntuple1.firstname
# or via index
ntuple1[2]
```
"""
# ╔═╡ 75c9ab4b-caf8-4783-a9dd-33285eb8cd2a
ntuple1 = (firstname = "Prithvi", lastname = "Thakur", id = 25)
# ╔═╡ a59a94e3-379a-4ce3-8b0a-0e42f1a5db20
ntuple1[2]
# ╔═╡ 5cb652a5-25bf-465a-8745-41e798c6917d
md"""
## Sets
* Sets have efficient implementations of set operations such as in, union, intersection, symmetric difference, subset, etc.
* Elements in a Set are unique.
* Not ordered.
"""
# ╔═╡ c56679e6-cb34-4fd3-932b-d92c938e0135
begin
set1 = Set([1,2, 2, 3, 4, 5])
set2 = Set([3,5,7,9])
end
# ╔═╡ c9319016-5209-40d7-b106-8f51a7b3547c
intersect(set1, set2)
# ╔═╡ 2621f286-f4d9-430a-96e5-1e62fc5f382e
set1
# ╔═╡ 507001fc-b643-4029-88f6-e5155cb16201
md"""
## Dictionary `Dict` type
* (Key, Value) pair
Tuples are cheaper to construct than Dicts. Order is not important in Dict.
"""
# ╔═╡ dd481e6f-373b-4821-8c7e-62d4381ba0eb
dict1 = Dict("a" => 21, "b" => 25, "c" => 37)
# ╔═╡ 1936fe1f-4229-4c40-b836-3e273749aa9b
dict1["c"]
# ╔═╡ 782925e7-4de8-4157-86af-b895740b5c4e
md"""
## Functions (aka methods)
Conventional syntax:
```julia
function <name>(arguments)
operations
return value
end
```
Mathematical (or functional language) syntax, conventionally used for single-line functions:
```julia
f(x) = return value # where x is the input argument
```
"""
# ╔═╡ 323cfc3b-edfb-4892-8ef6-23f7465f5974
function add_one(n)
return n .+ 1
end
# ╔═╡ 9e3e00ba-4e7a-469f-ba16-4a35cc8dcd3c
f(x) = x + 1
# ╔═╡ e73fac51-33f2-4fd0-b146-c0f40867cd61
add_one(5)
# ╔═╡ e594d69c-e8f6-480c-9aa4-40e1ebc9aeaa
add_one(rand(5))
# ╔═╡ 02664a66-233b-4ed7-a5e6-02671a2553b4
md"""
## `!` notation: functions that modify the input
Similar to passing by reference in C++. Using this type of function will modify the input itself.
Obviously, this will not work for immutable types.
"""
# ╔═╡ 82a3a959-24e2-4805-bbf3-0c67fcfdb5c3
function add_one!(x)
x .= x .+ 1
end
# ╔═╡ e2a44032-0e9a-4495-bdf0-2d2dc99de8c9
begin
var1 = [5,6,7]
var2 = [1,2,3]
end
# ╔═╡ dcd3901d-59a0-4b96-b564-de2397ffc246
add_one(var1)
# ╔═╡ c3ad4e71-ff2b-41ed-8be0-142097b974f4
var1
# ╔═╡ 21d65a37-1c94-4828-a1d7-f1dbe157fdbd
add_one!(var2)
# ╔═╡ 5619aedf-9359-4938-8974-5e1d611c97a0
var2
# ╔═╡ 5547dad3-0ed3-45b5-9fc9-655896155fe8
md"""
## Plots:
Very similar to python, easy and convenient for 2D plots.
[Plots.jl](https://docs.juliaplots.org/latest/) provides a convenient way to switch backends without altering the code.
"""
# ╔═╡ 6a96e890-6637-4acd-9293-aad79ebe820c
# ╔═╡ 1b5461f3-2423-4277-b577-7c11a55dca2f
md"""
## Julia has a growing and robust ecosystem for numerical methods and solutions
#### Example: using DifferentialEquations.jl to solve lorenz equation
The Lorenz equations are given by:
"""
# ╔═╡ 1da6085f-4f3e-4278-b2d1-32712bc6b205
texeq"\frac{dx}{dt} = \sigma(y - x)"
# ╔═╡ b14c1316-d75a-495f-8b3c-5cc906e6cf55
texeq"\frac{dy}{dt} = x(\rho - z) - y"
# ╔═╡ a38dc093-35c8-40f1-a294-aa22ede230e1
texeq"\frac{dz}{dt} = xy - \beta z"
# ╔═╡ f97f8175-88de-46d9-8ec2-2ebf6bbb2228
begin
function lorenz!(du, u, p, t)
σ, ρ, β = p
du[1] = σ * (u[2] - u[1])
du[2] = u[1] * (ρ - u[3]) - u[2]
du[3] = u[1] * u[2] - β * u[3]
end
end
# ╔═╡ 9c5cc745-47eb-41c0-9c69-6eabf7fc7189
# Initial conditions and parameters
begin
u0 = [1.0, 0.0, 0.0]
p = [10.0, 28.0, 8/3]
end
# ╔═╡ 76694655-1cea-4aef-9c07-6f73e6967b29
# Solve the differential equations
begin
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz!, u0, tspan, p)
sol = solve(prob)
end
# ╔═╡ 87d59413-2389-47ba-bea4-520fe6db3280
# Plot the solution
begin
# @bind sol
Plots.plot(sol, idxs=(1,2,3))
end
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoExtras = "ed5d0301-4775-4676-b788-cf71e66ff8ed"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
PythonPlot = "274fc56d-3b97-40fa-a1cd-1b4a50311bf9"
[compat]
BenchmarkTools = "~1.5.0"
DifferentialEquations = "~7.13.0"
Plots = "~1.40.3"
PlutoExtras = "~0.7.12"
PlutoUI = "~0.7.58"
PythonPlot = "~1.0.3"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.9.3"
manifest_format = "2.0"
project_hash = "2e828298b9e0dc7af8ada113a4ef22f0efeb32c1"
[[deps.ADTypes]]
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "0.2.7"
[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "0f748c81756f2e5e6854298f11ad8b2dfae6911a"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.3.0"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "cde29ddf7e5726c9fb511f340244ea3481267608"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.7.2"
weakdeps = ["StaticArrays"]
[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "d57bd3762d308bded22c3b82d033bff85f6195c6"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.4.0"
[[deps.ArrayInterface]]
deps = ["Adapt", "LinearAlgebra", "Requires", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "c5aeb516a84459e0318a02507d2261edad97eb75"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.7.1"
[deps.ArrayInterface.extensions]
ArrayInterfaceBandedMatricesExt = "BandedMatrices"
ArrayInterfaceBlockBandedMatricesExt = "BlockBandedMatrices"
ArrayInterfaceCUDAExt = "CUDA"
ArrayInterfaceGPUArraysCoreExt = "GPUArraysCore"
ArrayInterfaceStaticArraysCoreExt = "StaticArraysCore"
ArrayInterfaceTrackerExt = "Tracker"
[deps.ArrayInterface.weakdeps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
[[deps.ArrayLayouts]]
deps = ["FillArrays", "LinearAlgebra"]
git-tree-sha1 = "0330bc3e828a05d1073553fb56f9695d73077370"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "1.9.1"
weakdeps = ["SparseArrays"]
[deps.ArrayLayouts.extensions]
ArrayLayoutsSparseArraysExt = "SparseArrays"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.BandedMatrices]]
deps = ["ArrayLayouts", "FillArrays", "LinearAlgebra", "PrecompileTools"]
git-tree-sha1 = "c946c5014cf4cdbfacacb363b110e7bffba3e742"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "1.6.1"
weakdeps = ["SparseArrays"]
[deps.BandedMatrices.extensions]
BandedMatricesSparseArraysExt = "SparseArrays"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
git-tree-sha1 = "f1dff6729bc61f4d49e140da1af55dcd1ac97b2f"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.5.0"
[[deps.BitFlags]]
git-tree-sha1 = "2dc09997850d68179b69dafb58ae806167a32b1b"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.8"
[[deps.BitTwiddlingConvenienceFunctions]]
deps = ["Static"]
git-tree-sha1 = "0c5f81f47bbbcf4aea7b2959135713459170798b"
uuid = "62783981-4cbd-42fc-bca8-16325de8dc4b"
version = "0.1.5"
[[deps.BoundaryValueDiffEq]]
deps = ["ADTypes", "Adapt", "ArrayInterface", "BandedMatrices", "ConcreteStructs", "DiffEqBase", "FastAlmostBandedMatrices", "ForwardDiff", "LinearAlgebra", "LinearSolve", "NonlinearSolve", "PreallocationTools", "PrecompileTools", "Preferences", "RecursiveArrayTools", "Reexport", "SciMLBase", "Setfield", "SparseArrays", "SparseDiffTools", "Tricks", "TruncatedStacktraces", "UnPack"]
git-tree-sha1 = "3ff968887be48760b0e9e8650c2d05c96cdea9d8"
uuid = "764a87c0-6b3e-53db-9096-fe964310641d"
version = "5.6.3"
[deps.BoundaryValueDiffEq.extensions]
BoundaryValueDiffEqODEInterfaceExt = "ODEInterface"
BoundaryValueDiffEqOrdinaryDiffEqExt = "OrdinaryDiffEq"
[deps.BoundaryValueDiffEq.weakdeps]
ODEInterface = "54ca160b-1b9f-5127-a996-1867f4bc2a2c"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9e2a6b69137e6969bab0152632dcb3bc108c8bdd"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+1"
[[deps.CEnum]]
git-tree-sha1 = "389ad5c84de1ae7cf0e28e381131c98ea87d54fc"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.5.0"
[[deps.CPUSummary]]
deps = ["CpuId", "IfElse", "PrecompileTools", "Static"]
git-tree-sha1 = "601f7e7b3d36f18790e2caf83a882d88e9b71ff1"
uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
version = "0.2.4"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "a4c43f59baa34011e303e76f5c8c91bf58415aaf"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.18.0+1"
[[deps.Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"
[[deps.CloseOpenIntervals]]
deps = ["Static", "StaticArrayInterface"]
git-tree-sha1 = "70232f82ffaab9dc52585e0dd043b5e0c6b714f1"
uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9"
version = "0.1.12"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "59939d8a997469ee05c4b4944560a820f9ba0d73"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.4"
[[deps.ColorSchemes]]
deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "PrecompileTools", "Random"]
git-tree-sha1 = "67c1f244b991cad9b0aa4b7540fb758c2488b129"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.24.0"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "b10d0b65641d57b8b4d5e234446582de5047050d"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.5"
[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "Requires", "Statistics", "TensorCore"]
git-tree-sha1 = "a1f44953f2382ebb937d60dafbe2deea4bd23249"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.10.0"
weakdeps = ["SpecialFunctions"]
[deps.ColorVectorSpace.extensions]
SpecialFunctionsExt = "SpecialFunctions"
[[deps.Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "fc08e5930ee9a4e03f84bfb5211cb54e7769758a"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.10"
[[deps.CommonSolve]]
git-tree-sha1 = "0eee5eb66b1cf62cd6ad1b460238e60e4b09400c"
uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
version = "0.2.4"
[[deps.CommonSubexpressions]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.0"
[[deps.Compat]]
deps = ["TOML", "UUIDs"]
git-tree-sha1 = "c955881e3c981181362ae4088b35995446298b80"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.14.0"
weakdeps = ["Dates", "LinearAlgebra"]
[deps.Compat.extensions]
CompatLinearAlgebraExt = "LinearAlgebra"
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.5+0"
[[deps.ConcreteStructs]]
git-tree-sha1 = "f749037478283d372048690eb3b5f92a79432b34"
uuid = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
version = "0.2.3"
[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"
[[deps.CondaPkg]]
deps = ["JSON3", "Markdown", "MicroMamba", "Pidfile", "Pkg", "Preferences", "TOML"]
git-tree-sha1 = "e81c4263c7ef4eca4d645ef612814d72e9255b41"
uuid = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
version = "0.2.22"
[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "260fd2400ed2dab602a7c15cf10c1933c59930a2"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.5.5"
[deps.ConstructionBase.extensions]
ConstructionBaseIntervalSetsExt = "IntervalSets"
ConstructionBaseStaticArraysExt = "StaticArrays"
[deps.ConstructionBase.weakdeps]
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[[deps.Contour]]
git-tree-sha1 = "439e35b0b36e2e5881738abc8857bd92ad6ff9a8"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.6.3"
[[deps.CpuId]]
deps = ["Markdown"]
git-tree-sha1 = "fcbb72b032692610bfbdb15018ac16a36cf2e406"
uuid = "adafc99b-e345-5852-983c-f28acb93d879"
version = "0.3.1"
[[deps.DataAPI]]
git-tree-sha1 = "abe83f3a2f1b857aac70ef8b269080af17764bbe"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.16.0"
[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "0f4b5d62a88d8f59003e43c25a8a90de9eb76317"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.18"
[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[deps.DelayDiffEq]]
deps = ["ArrayInterface", "DataStructures", "DiffEqBase", "LinearAlgebra", "Logging", "OrdinaryDiffEq", "Printf", "RecursiveArrayTools", "Reexport", "SciMLBase", "SimpleNonlinearSolve", "SimpleUnPack"]
git-tree-sha1 = "dd3dfeca90deb4b38be9598d7c51cd558816e596"
uuid = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
version = "5.45.1"
[[deps.DelimitedFiles]]
deps = ["Mmap"]
git-tree-sha1 = "9e2f36d3c96a820c678f2f1f1782582fcf685bae"
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
version = "1.9.1"
[[deps.DiffEqBase]]
deps = ["ArrayInterface", "DataStructures", "DocStringExtensions", "EnumX", "EnzymeCore", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "FunctionWrappersWrappers", "LinearAlgebra", "Logging", "Markdown", "MuladdMacro", "Parameters", "PreallocationTools", "PrecompileTools", "Printf", "RecursiveArrayTools", "Reexport", "SciMLBase", "SciMLOperators", "Setfield", "SparseArrays", "Static", "StaticArraysCore", "Statistics", "Tricks", "TruncatedStacktraces"]
git-tree-sha1 = "044648af911974c3928058c1f8c83f159dece274"
uuid = "2b5f629d-d688-5b77-993f-72d75c75574e"
version = "6.145.6"
[deps.DiffEqBase.extensions]
DiffEqBaseChainRulesCoreExt = "ChainRulesCore"
DiffEqBaseDistributionsExt = "Distributions"
DiffEqBaseEnzymeExt = ["ChainRulesCore", "Enzyme"]
DiffEqBaseGeneralizedGeneratedExt = "GeneralizedGenerated"
DiffEqBaseMPIExt = "MPI"
DiffEqBaseMeasurementsExt = "Measurements"
DiffEqBaseMonteCarloMeasurementsExt = "MonteCarloMeasurements"
DiffEqBaseReverseDiffExt = "ReverseDiff"
DiffEqBaseTrackerExt = "Tracker"
DiffEqBaseUnitfulExt = "Unitful"
[deps.DiffEqBase.weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[[deps.DiffEqCallbacks]]
deps = ["DataStructures", "DiffEqBase", "ForwardDiff", "Functors", "LinearAlgebra", "Markdown", "NLsolve", "Parameters", "RecipesBase", "RecursiveArrayTools", "SciMLBase", "StaticArraysCore"]