‖ if x < 1 || ≔ ‖ || x ‖ || ‖ else if 1 ≤ x ≤ 3 | | ‖ ‖ || 2 ‖ − x − 1 + 1 | | ‖ ‖ || ‖ else if x > 3 || ‖ −3 | | | ‖
piecewise function
x ≔ −2 , − −11.9 ‥ 5
2 1 0
f x
-1 -2 -3 -4 -2
-1
0
1
2
3
4
5
x 3 of 6
Non-Commercial Use Only
MM/DD/YY
Full Name
S#
General programming programming problem example: find the sum of first N numbers divisible divisible by 3
N ≔ 10000
| | | | || || ‖ i ← i + 1 || mod i , 3 | | ‖ remainder ← || ‖ if remainder = 0 | || ‖ ‖ total ← t otal + i | || | ‖ ‖ | n ← n + 1 | || ‖ ‖ i tota totall |
‖i← results ≔ ‖ 0 0 ‖n← ‖ total ← 0 ‖ while n < N ‖ ‖ ‖‖ ‖ ‖ ‖ ‖ ‖
results =
3 ⋅ 10 4 1. 1.55 ⋅ 108
large lar gest st ≔ resu results lts
largest = 3 ⋅ 10 4
su sum m ≔ re resu sult ltss
sum = 1.5 ⋅ 10 8
0,0
0,1
alternative solution (for this problem)
i ≔ 3 , 6 ‥ 3 ⋅ N
sum = 1. 1.5 5 ⋅ 108
sum ≔ ∑ i i
other (even better) alternative solutions (for this problem): N
3 ⋅ ∑ i = 1. 1.5 5 ⋅ 108
N ⋅ N + 1 3 ⋅ ――― = 1.5⋅ 10 8 2
or
i= 1
Finding roots
f x
≔ 2 ⋅ x 2 − 4 ⋅sin x − 2
x≔ 1
f x
,x = 1.725
x≔ −1
f x
,x = −0.423 x ≔ −1 , − −00.9 ‥ 2
4 3 2 1
f x
0
marker added at 0 on vertical axis
0 -1 -2 -3 -4 -1
-0.5
0
0.5
1
1.5
2
x 4 of 6
Non-Commercial Use Only
MM/DD/YY
Full Name
S#
Solving a set of nonlinear equations s e u l a V s s e u G
x≔ 1 y≔ 1
s t n i a r t s n
x = 2 − y 2
o C
y = ―― x
r e v l o S
sin x
+x⋅y ⎤ ⎡ x , y = 0.252 ⎣ 1.322 ⎦
solution ≔
x ≔ solution
0
= 0.252
y ≔ solution
1
= 1.322
Checking results (solving symbolically and plotting)
x,y fa x
2
solve so lve , y
≔ x = 2 − y ――→
⎡
x− 2 ⋅ 1i
⎤
x− 2 ⋅ 1i ⎦ solve solve , y sin x
⎣− fb x
⎞ ⎛ sin x + x ⋅ y ――→ −――― ≔ y = ―― x x ⋅ x − 1 ⎠ ⎝ fa x
1
= 1.322
fb x
= 1.322
x ≔ 0.01 0. 01, 00.0 .055 ‥ 0.5 0.5 2 1.8
fa x
1
1.6 1.4
fb x
1.2 1 0
0.1
0.2
x
0.3
0.4
0.5
Iterative calculations with subscripts
i ≔ 1 ‥ 20 x
i
≔x
i− 1
x y i
x
0
≔1
y
0
≔1
+2
i− 1
+x
≔ ―― 2
i
x
=
⎡ 1⎤ ⎢ 3⎥ ⎢ ⎥ ⎢ 5⎥ ⎢ 7⎥ ⎢⎢ 9 ⎥⎥ 11 ⎢ 13 ⎥ ⎣ ⋮⎦
y
=
⎡ 1⎤ ⎢ 2⎥ ⎢ ⎥ ⎢ 4⎥ ⎢ 6⎥ ⎢⎢ 8 ⎥⎥ 10 ⎢ 12 ⎥ ⎣ ⋮⎦
5 of 6
Non-Commercial Use Only
MM/DD/YY
Full Name
S#
Finding an optimal solution given constraints
z x , y s e u l a V s s e u G s t n i a r t s n o C