forked from CalculusWithJulia/CalculusWithJulia.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_log_functions.html
3818 lines (3591 loc) · 123 KB
/
exp_log_functions.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
rel="stylesheet">
<style>
.julia {display: block; font-family: "Source Code Pro";
color:#0033CC;
}
.hljl {font-family: "Source Code Pro";
color:#0033CC;
}
body { padding-top: 60px; }
h5:before {content:"\2746\ ";}
h6:before {content:"\2742\ ";}
pre {display: block;}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {background-color: #f5f5f5;}
.admonition-title:before {content:"\2746\ ";}
.admonition-title { color:#0033CC}
</style>
<!-- .julia:before {content: "julia> "} -->
<style></style>
<script src="https://code.jquery.com/jquery.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["\$","\$"], ["\\(","\\)"]]
},
displayAlign: "left",
displayIndent: "5%"
});
</script>
<!-- not TeX-AMS-MML_HTMLorMML-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
</script>
<script>
window.PlotlyConfig = {MathJaxConfig: 'local'}
</script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$("h1").each(function(index) {
var title = $( this ).text()
$("#page_title").html("<strong>" + title + "</strong>");
document.title = title
});
$( "h2" ).each(function( index ) {
var nm = $( this ).text();
var id = $.trim(nm).replace(/ /g,'');
this.id = id
$("#page_dropdown").append("<li><a href='#" + id + "'>" + nm + "</a></li>");
});
$('[data-toggle="popover"]').popover();
});
</script>
</head>
<body data-spy="scroll" >
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#" id="page_title"></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Jump to... <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" id="page_dropdown"></ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<header>
</header>
<div class="title">
</div>
<div class="container-fluid">
<div class="span10 offset1">
<h1>Exponential and logarithmic functions</h1>
<p>The family of exponential functions is used to model growth and decay. The family of logarithmic functions is defined here as the inverse of the exponential functions, but have reach far outside of that.</p>
<h2>Exponential functions</h2>
<p>The family of exponential functions is defined by <span class="math">$f(x) = a^x, -\infty< x < \infty$</span> and <span class="math">$a > 0$</span>. For <span class="math">$0 < a < 1$</span> these functions decay or decrease, for <span class="math">$a > 1$</span> the functions grow or increase, and if <span class="math">$a=1$</span> the function is constantly <span class="math">$1$</span>.</p>
<p>For a given <span class="math">$a$</span>, defining <span class="math">$a^n$</span> for positive integers is straightforward, as it means multiplying <span class="math">$n$</span> copies of <span class="math">$a$</span>. From this, the key properties of exponents: <span class="math">$a^x \cdot a^y = a^{x+y}$</span>, and <span class="math">$(a^x)^y = a^{x \cdot y}$</span> are immediate consequences. For <span class="math">$a \neq 0$</span>, <span class="math">$a^0$</span> is defined to be <span class="math">$1$</span>. For positive, integer values of <span class="math">$n$</span>, we have <span class="math">$a^{-n} = 1/a^n$</span>. For <span class="math">$n$</span> a positive integer, we can define <span class="math">$a^{1/n}$</span> to be the unique positive solution to <span class="math">$x^n=a$</span>. And using the key properties of exponents extend this to a definition of <span class="math">$a^x$</span> for any rational <span class="math">$x$</span>.</p>
<p>Defining <span class="math">$a^x$</span> for any real number requires some more sophisticated mathematics. One method is to use a <a href="http://tinyurl.com/zk86c8r">theorem</a> that says a <em>bounded</em> monotonically increasing sequence will converge. Then for <span class="math">$a > 1$</span> we have if <span class="math">$q_n$</span> is a sequence of rational numbers increasing to <span class="math">$x$</span>, then <span class="math">$a^{q_n}$</span> will be a bounded sequence of increasing numbers, so will converge to a number defined to be <span class="math">$a^x$</span>. Something similar is possible for the <span class="math">$0 < a < 1$</span> case.</p>
<p>This definition can be done to ensure the rules of exponents hold for <span class="math">$a > 0$</span>:</p>
<p class="math">\[
~
a^{x + y} = a^x \cdot a^y, \quad (a^x)^y = a^{x \cdot y}.
~
\]</p>
<p>In <code>Julia</code> these functions are implemented using <code>^</code> or for a base of <span class="math">$e$</span> through <code>exp(x)</code>. Here are some representative graphs:</p>
<pre class='hljl'>
<span class='hljl-k'>using</span><span class='hljl-t'> </span><span class='hljl-n'>CalculusWithJulia</span><span class='hljl-t'> </span><span class='hljl-cs'># to load the `Plots` package</span><span class='hljl-t'>
</span><span class='hljl-nf'>f1</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-oB'>^</span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-nf'>f2</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>^</span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-nf'>f3</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-oB'>^</span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-nf'>f4</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>plot</span><span class='hljl-p'>([</span><span class='hljl-n'>f1</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>f2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>f3</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>f4</span><span class='hljl-p'>],</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>legend</span><span class='hljl-oB'>=</span><span class='hljl-kc'>false</span><span class='hljl-p'>)</span>
</pre>
<div id="29f7855d-5c92-4c10-bb4c-96cec54a58bc" style="width:576px;height:384px;"></div>
<script>
PLOT = document.getElementById('29f7855d-5c92-4c10-bb4c-96cec54a58bc');
Plotly.plot(PLOT, [
{
"xaxis": "x1",
"colorbar": {
"title": ""
},
"yaxis": "y1",
"text": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"x": [
-1.9804683619604238,
-1.9609367239208475,
-1.780338527623678,
-1.5997403313265088,
-1.4912083430520067,
-1.3826763547775045,
-1.2909139399572207,
-1.1991515251369371,
-0.9997921198677943,
-0.8160003818614874,
-0.6189562143740406,
-0.3906612226458709,
-0.18777957555591424,
-0.009870653839119958,
0.18409782662127785,
0.3792191150112484,
0.5949506504976171,
0.8002137629793739,
1.0136397740454022,
1.1932990146673805,
1.4126425839454564,
1.618832008514834,
1.9491634560642397
],
"showlegend": true,
"mode": "lines",
"name": "y1",
"zmin": -0.1,
"legendgroup": "y1",
"zmax": 0.1,
"line": {
"color": "rgba(0, 154, 250, 1.000)",
"shape": "linear",
"dash": "solid",
"width": 1
},
"y": [
3.946211723103527,
3.8931467408899274,
3.435067687995526,
3.030887558688235,
2.811243349497213,
2.6075164508949182,
2.4468301189246464,
2.2960459669667763,
1.9997118377063055,
1.7605184931112137,
1.535763658747144,
1.3109941270602803,
1.1390093385834241,
1.006865274570629,
0.880199326766431,
0.7688536340826392,
0.662067101787788,
0.5742640829410082,
0.4952950905636554,
0.43730173738830785,
0.3756230277830936,
0.32559895884731344,
0.2589663485709747
],
"type": "scatter",
"hoverinfo": "text"
},
{
"xaxis": "x1",
"colorbar": {
"title": ""
},
"yaxis": "y1",
"text": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"x": [
-1.9609367239208475,
-1.5997403313265088,
-1.3826763547775045,
-1.1991515251369371,
-0.9997921198677943,
-0.8160003818614874,
-0.6189562143740406,
-0.3906612226458709,
-0.18777957555591424,
-0.009870653839119958,
0.18409782662127785,
0.3792191150112484,
0.5949506504976171,
0.8002137629793739,
1.0136397740454022,
1.1932990146673805,
1.4126425839454564,
1.618832008514834,
1.9491634560642397
],
"showlegend": true,
"mode": "lines",
"name": "y2",
"zmin": -0.1,
"legendgroup": "y2",
"zmax": 0.1,
"line": {
"color": "rgba(227, 111, 71, 1.000)",
"shape": "linear",
"dash": "solid",
"width": 1
},
"y": [
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0
],
"type": "scatter",
"hoverinfo": "text"
},
{
"xaxis": "x1",
"colorbar": {
"title": ""
},
"yaxis": "y1",
"text": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"x": [
-1.9609367239208475,
-1.5997403313265088,
-1.3826763547775045,
-1.1991515251369371,
-0.9997921198677943,
-0.8160003818614874,
-0.6189562143740406,
-0.3906612226458709,
-0.18777957555591424,
-0.009870653839119958,
0.18409782662127785,
0.3792191150112484,
0.5949506504976171,
0.8002137629793739,
1.0136397740454022,
1.1932990146673805,
1.3029707993064186,
1.4126425839454564,
1.5157372962301452,
1.618832008514834,
1.7839977322895368,
1.9491634560642397,
1.9745817280321198
],
"showlegend": true,
"mode": "lines",
"name": "y3",
"zmin": -0.1,
"legendgroup": "y3",
"zmax": 0.1,
"line": {
"color": "rgba(62, 164, 78, 1.000)",
"shape": "linear",
"dash": "solid",
"width": 1
},
"y": [
0.2568616254550456,
0.3299363571352013,
0.38350668877152927,
0.4355313501502167,
0.5000720509546078,
0.5680144820477209,
0.651141856563911,
0.7627799235396723,
0.877955927247876,
0.9931815360564932,
1.1361062995511235,
1.300637671034948,
1.5104209185136785,
1.741359123277654,
2.0189984093361004,
2.286750576323544,
2.467364398724438,
2.662243595399209,
2.859449241403804,
3.0712628920565455,
3.443791340203445,
3.8615055798492315,
3.9301427861334663
],
"type": "scatter",
"hoverinfo": "text"
},
{
"xaxis": "x1",
"colorbar": {
"title": ""
},
"yaxis": "y1",
"text": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"x": [
-1.9609367239208475,
-1.5997403313265088,
-1.3826763547775045,
-1.1991515251369371,
-0.9997921198677943,
-0.8160003818614874,
-0.6189562143740406,
-0.3906612226458709,
-0.18777957555591424,
-0.009870653839119958,
0.18409782662127785,
0.3792191150112484,
0.5949506504976171,
0.8002137629793739,
0.9069267685123881,
1.0136397740454022,
1.1034693943563914,
1.1932990146673805,
1.3029707993064186,
1.4126425839454564,
1.5157372962301452,
1.618832008514834,
1.7014148704021854,
1.7839977322895368,
1.8665805941768883,
1.9491634560642397,
1.9618725920481799,
1.9745817280321198,
1.9872908640160598
],
"showlegend": true,
"mode": "lines",
"name": "y4",
"zmin": -0.1,
"legendgroup": "y4",
"zmax": 0.1,
"line": {
"color": "rgba(195, 113, 210, 1.000)",
"shape": "linear",
"dash": "solid",
"width": 1
},
"y": [
0.14072653724765471,
0.2019489510029758,
0.2509061398069358,
0.3014498760768803,
0.3679559239476582,
0.4421967404219614,
0.5385062294103061,
0.6766093371374287,
0.8287973743002874,
0.9901779011765799,
1.2021334179948595,
1.461143159069973,
1.8129414749928854,
2.2260167176032977,
2.4766993550456062,
2.755612591215265,
3.0146067616411285,
3.297943243656227,
3.6802136196220734,
4.106793624209382,
4.552776634741466,
5.04719179548211,
5.481697799493216,
5.9536098453533155,
6.466148169270634,
7.022810233289769,
7.112633663593073,
7.2036059571524556,
7.29574180820501
],
"type": "scatter",
"hoverinfo": "text"
}
]
, {
"showlegend": false,
"xaxis": {
"showticklabels": true,
"gridwidth": 0.5,
"tickvals": [
-2.0,
-1.0,
0.0,
1.0,
2.0
],
"visible": true,
"ticks": "inside",
"range": [
-2.0995011387397184,
2.1063236407953543
],
"domain": [
0.022267181880042772,
0.9931649168853892
],
"tickmode": "array",
"linecolor": "rgba(0, 0, 0, 1.000)",
"showgrid": true,
"title": "",
"mirror": false,
"tickangle": 0,
"showline": true,
"gridcolor": "rgba(0, 0, 0, 0.100)",
"titlefont": {
"color": "rgba(0, 0, 0, 1.000)",
"family": "sans-serif",
"size": 15
},
"tickcolor": "rgb(0, 0, 0)",
"ticktext": [
"-2",
"-1",
"0",
"1",
"2"
],
"zeroline": false,
"type": "-",
"tickfont": {
"color": "rgba(0, 0, 0, 1.000)",
"family": "sans-serif",
"size": 11
},
"zerolinecolor": "rgba(0, 0, 0, 1.000)",
"anchor": "y1"
},
"paper_bgcolor": "rgba(255, 255, 255, 1.000)",
"annotations": [],
"height": 384,
"margin": {
"l": 0,
"b": 20,
"r": 0,
"t": 20
},
"plot_bgcolor": "rgba(255, 255, 255, 1.000)",
"yaxis": {
"showticklabels": true,
"gridwidth": 0.5,
"tickvals": [
0.0,
2.0,
4.0,
6.0
],
"visible": true,
"ticks": "inside",
"range": [
-0.07392392088106592,
7.510392266333731
],
"domain": [
0.0391878098571012,
0.989747375328084
],
"tickmode": "array",
"linecolor": "rgba(0, 0, 0, 1.000)",
"showgrid": true,
"title": "",
"mirror": false,
"tickangle": 0,
"showline": true,
"gridcolor": "rgba(0, 0, 0, 0.100)",
"titlefont": {
"color": "rgba(0, 0, 0, 1.000)",
"family": "sans-serif",
"size": 15
},
"tickcolor": "rgb(0, 0, 0)",
"ticktext": [
"0",
"2",
"4",
"6"
],
"zeroline": false,
"type": "-",
"tickfont": {
"color": "rgba(0, 0, 0, 1.000)",
"family": "sans-serif",
"size": 11
},
"zerolinecolor": "rgba(0, 0, 0, 1.000)",
"anchor": "x1"
},
"width": 576
}
);
</script>
<p>We see examples of some general properties:</p>
<ul>
<li><p>The domain is all real <span class="math">$x$</span> and the range is all <em>positive</em> <span class="math">$y$</span> (provided <span class="math">$a \neq 1$</span>).</p>
</li>
<li><p>For <span class="math">$0 < a < 1$</span> the functions are monotonically decreasing.</p>
</li>
<li><p>For <span class="math">$a > 1$</span> the functions are monotonically increasing.</p>
</li>
<li><p>If <span class="math">$1 < a < b$</span> the and <span class="math">$x > 0$</span> we have <span class="math">$a^x < b^x$</span>.</p>
</li>
</ul>
<h5>Example</h5>
<p><a href="http://tinyurl.com/gsy939y">Continuously</a> compounded interest allows an initial amount <span class="math">$P_0$</span> to grow over time according to <span class="math">$P(t)=P_0e^{rt}$</span>. Investigate the difference between investing <span class="math">$1,000$</span> dollars in an account which earns <span class="math">$2$</span>% as opposed to an account which earns <span class="math">$8$</span>% over <span class="math">$20$</span> years.</p>
<p>The <span class="math">$r$</span> in the formula is the interest rate, so <span class="math">$r=0.02$</span> or <span class="math">$r=0.08$</span>. To compare the differences we have:</p>
<pre class='hljl'>
<span class='hljl-n'>r2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>r8</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nfB'>0.02</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-nfB'>0.08</span><span class='hljl-t'>
</span><span class='hljl-n'>P0</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1000</span><span class='hljl-t'>
</span><span class='hljl-n'>t</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>20</span><span class='hljl-t'>
</span><span class='hljl-n'>P0</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>r2</span><span class='hljl-oB'>*</span><span class='hljl-n'>t</span><span class='hljl-p'>),</span><span class='hljl-t'> </span><span class='hljl-n'>P0</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>r8</span><span class='hljl-oB'>*</span><span class='hljl-n'>t</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
(1491.8246976412704, 4953.0324243951145)
</pre>
<p>As can be seen, there is quite a bit of difference.</p>
<p>In 1494, <a href="http://tinyurl.com/gsy939y">Pacioli</a> gave the "Rule of 72", stating that to find the number of years it takes an investment to double when continuously compounded one should divide the interest rate into <span class="math">$72$</span>.</p>
<p>This formula is not quite precise, but a rule of thumb, the number is closer to <span class="math">$69$</span>, but <span class="math">$72$</span> has many divisors which makes this an easy to compute approximation. Let's see how accurate it is:</p>
<pre class='hljl'>
<span class='hljl-n'>t2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>t8</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>72</span><span class='hljl-oB'>/</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>72</span><span class='hljl-oB'>/</span><span class='hljl-ni'>8</span><span class='hljl-t'>
</span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>r2</span><span class='hljl-oB'>*</span><span class='hljl-n'>t2</span><span class='hljl-p'>),</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>r8</span><span class='hljl-oB'>*</span><span class='hljl-n'>t8</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
(2.0544332106438876, 2.0544332106438876)
</pre>
<p>So fairly close–after <span class="math">$72/r$</span> years the amount is <span class="math">$2.05...$</span> times more than the initial amount.</p>
<h5>Example</h5>
<p><a href="https://en.wikipedia.org/wiki/Bacterial_growth">Bacterial growth</a> (to Wikipedia) is the asexual reproduction, or cell division, of a bacterium into two daughter cells, in a process called binary fission. During the log phase "the number of new bacteria appearing per unit time is proportional to the present population." The article states that "Under controlled conditions, <em>cyanobacteria</em> can double their population four times a day..."</p>
<p>Suppose an initial population of <span class="math">$P_0$</span> bacteria, a formula for the number after <span class="math">$n$</span> <em>hours</em> is <span class="math">$P(n) = P_0 2^{n/6}$</span> where <span class="math">$6 = 24/4$</span>.</p>
<p>After two days what multiple of the initial amount is present if conditions are appropriate?</p>
<pre class='hljl'>
<span class='hljl-n'>n</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-ni'>24</span><span class='hljl-t'>
</span><span class='hljl-ni'>2</span><span class='hljl-oB'>^</span><span class='hljl-p'>(</span><span class='hljl-n'>n</span><span class='hljl-oB'>/</span><span class='hljl-ni'>6</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
256.0
</pre>
<p>That would be an enormous growth. Don't worry: "Exponential growth cannot continue indefinitely, however, because the medium is soon depleted of nutrients and enriched with wastes."</p>
<h5>Example</h5>
<p>The famous <a href="https://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci</a> numbers are <span class="math">$1,1,2,3,5,8,13,\dots$</span>, where <span class="math">$F_{n+1}=F_n+F_{n-1}$</span>. These numbers increase. To see how fast, if we <em>guess</em> that the growth is evenually exponential and assume <span class="math">$F_n \approx c \cdot a^n$</span>, then our equation is approximately <span class="math">$a^{n+1} = a^n + a^{n-1}$</span> which has solutions <span class="math">$a$</span> satisfying <span class="math">$a^2 - a -1 = 0$</span>. The positve solution is <span class="math">$(1 + \sqrt{5})/2\approx 1.618$</span></p>
<p>That is evidence that the <span class="math">$F_n \approx 1.618^n$</span>. (See <a href="https://en.wikipedia.org/wiki/Fibonacci_number#Relation_to_the_golden_ratio">Relation to golden ratio</a> for a related, but more explicit exact formula.</p>
<h5>Example</h5>
<p>In the previous example, the exponential family of functions is used to describe growth. Polynomial functions also increase. Could these be used instead? If so that would be great, as they are easier to reason about.</p>
<p>The key fact is that exponential growth is much greater than polynomial growth. That is for large enough <span class="math">$x$</span> and for any fixed <span class="math">$a>1$</span> and positive integer <span class="math">$n$</span> it is true that <span class="math">$a^x \gg x^n$</span>.</p>
<p>Later we will see an easy way to certify this statement.</p>
<h2>Logarithmic functions: the inverse of exponential functions</h2>
<p>As the exponential functions are strictly <em>decreasing</em> when <span class="math">$0 < a < 1$</span> and strictly <em>increasing</em> when <span class="math">$a>1$</span>, in both cases an inverse function will exist. (When <span class="math">$a=1$</span> the function is a constant and is not one-to-one.) The domain of an exponential function is all real <span class="math">$x$</span> and the range is all <em>positive</em> <span class="math">$x$</span>, so these are switched around for the inverse function.</p>
<p>The inverse function will solve for <span class="math">$x$</span> in the equation <span class="math">$a^x = y$</span>. The answer, formally, is the logarithm base <span class="math">$a$</span>, written <span class="math">$\log_a(x)$</span>.</p>
<p>That is <span class="math">$a^{\log_a(x)} = x$</span> and <span class="math">$\log_a(a^x) = x$</span> when defined.</p>
<p>To see how a logarithm is mathematically defined will have to wait, though the family of functions–one for each <span class="math">$a>0$</span>–are implemented in <code>Julia</code> through the function <code>log(a,x)</code>. There are special cases requiring just one argument: <code>log(x)</code> will compute the natural log, base <span class="math">$e$</span>–the inverse of <span class="math">$f(x) = e^x$</span>; <code>log2(x)</code> will compute the log base <span class="math">$2$</span>–the inverse of <span class="math">$f(x) = 2^x$</span>; and <code>log10(x)</code> will compute the log base <span class="math">$10$</span>–the inverse of <span class="math">$f(x)=10^x$</span>.</p>
<p>To see this in an example, we plot for base <span class="math">$2$</span> the exponential function <span class="math">$f(x)=2^x$</span>, its inverse, and the logarithm function with base <span class="math">$2$</span>:</p>
<pre class='hljl'>
<span class='hljl-nf'>f</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-oB'>^</span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-n'>xs</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>range</span><span class='hljl-p'>(</span><span class='hljl-oB'>-</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>stop</span><span class='hljl-oB'>=</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>length</span><span class='hljl-oB'>=</span><span class='hljl-ni'>100</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>ys</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-n'>f</span><span class='hljl-oB'>.</span><span class='hljl-p'>(</span><span class='hljl-n'>xs</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>plot</span><span class='hljl-p'>(</span><span class='hljl-n'>xs</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>ys</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>color</span><span class='hljl-oB'>=:</span><span class='hljl-n'>blue</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>legend</span><span class='hljl-oB'>=</span><span class='hljl-kc'>false</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-cs'># plot f</span><span class='hljl-t'>
</span><span class='hljl-nf'>plot!</span><span class='hljl-p'>(</span><span class='hljl-n'>ys</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>xs</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>color</span><span class='hljl-oB'>=:</span><span class='hljl-n'>red</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-cs'># plot f^(-1)</span><span class='hljl-t'>
</span><span class='hljl-n'>xs</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>range</span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-ni'>4</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>stop</span><span class='hljl-oB'>=</span><span class='hljl-ni'>4</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>length</span><span class='hljl-oB'>=</span><span class='hljl-ni'>100</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>plot!</span><span class='hljl-p'>(</span><span class='hljl-n'>xs</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>log2</span><span class='hljl-oB'>.</span><span class='hljl-p'>(</span><span class='hljl-n'>xs</span><span class='hljl-p'>),</span><span class='hljl-t'> </span><span class='hljl-n'>color</span><span class='hljl-oB'>=:</span><span class='hljl-n'>green</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-cs'># plot log2</span>
</pre>
<div id="a95e1676-a6e3-4c5f-b59a-20743fc7e955" style="width:576px;height:384px;"></div>
<script>
PLOT = document.getElementById('a95e1676-a6e3-4c5f-b59a-20743fc7e955');
Plotly.plot(PLOT, [
{
"xaxis": "x1",
"colorbar": {
"title": ""
},
"yaxis": "y1",
"text": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"x": [
-2.0,
-1.9595959595959596,
-1.9191919191919191,
-1.878787878787879,
-1.8383838383838385,
-1.797979797979798,
-1.7575757575757576,
-1.7171717171717171,
-1.6767676767676767,
-1.6363636363636365,
-1.595959595959596,
-1.5555555555555556,
-1.5151515151515151,
-1.4747474747474747,
-1.4343434343434343,
-1.393939393939394,
-1.3535353535353536,
-1.3131313131313131,
-1.2727272727272727,
-1.2323232323232323,
-1.1919191919191918,
-1.1515151515151516,
-1.1111111111111112,
-1.0707070707070707,
-1.0303030303030303,
-0.98989898989899,
-0.9494949494949495,
-0.9090909090909091,
-0.8686868686868687,
-0.8282828282828283,
-0.7878787878787878,
-0.7474747474747475,
-0.7070707070707071,
-0.6666666666666666,
-0.6262626262626263,
-0.5858585858585859,
-0.5454545454545454,
-0.5050505050505051,
-0.46464646464646464,
-0.42424242424242425,
-0.3838383838383838,
-0.3434343434343434,
-0.30303030303030304,
-0.26262626262626265,
-0.2222222222222222,
-0.18181818181818182,
-0.1414141414141414,
-0.10101010101010101,
-0.06060606060606061,
-0.020202020202020204,
0.020202020202020204,
0.06060606060606061,
0.10101010101010101,
0.1414141414141414,
0.18181818181818182,
0.2222222222222222,
0.26262626262626265,
0.30303030303030304,
0.3434343434343434,
0.3838383838383838,
0.42424242424242425,
0.46464646464646464,
0.5050505050505051,
0.5454545454545454,
0.5858585858585859,
0.6262626262626263,
0.6666666666666666,
0.7070707070707071,
0.7474747474747475,
0.7878787878787878,
0.8282828282828283,
0.8686868686868687,
0.9090909090909091,
0.9494949494949495,
0.98989898989899,
1.0303030303030303,
1.0707070707070707,
1.1111111111111112,
1.1515151515151516,
1.1919191919191918,
1.2323232323232323,
1.2727272727272727,
1.3131313131313131,
1.3535353535353536,
1.393939393939394,
1.4343434343434343,
1.4747474747474747,
1.5151515151515151,
1.5555555555555556,
1.595959595959596,
1.6363636363636365,
1.6767676767676767,
1.7171717171717171,
1.7575757575757576,
1.797979797979798,
1.8383838383838385,
1.878787878787879,
1.9191919191919191,
1.9595959595959596,
2.0
],
"showlegend": true,
"mode": "lines",
"name": "y1",
"zmin": -0.1,
"legendgroup": "y1",
"zmax": 0.1,
"line": {
"color": "rgba(0, 0, 255, 1.000)",
"shape": "linear",
"dash": "solid",
"width": 1
},
"y": [
0.25,
0.25710044999730297,
0.26440256555526276,
0.27191207433879777,
0.27963486668882004,
0.28757700024252586,
0.2957447046849116,
0.304144386635241,
0.31278263467229667,
0.32166622450235793,
0.33080212427395883,
0.3401975000435942,
0.3498597213966623,
0.3597963672280517,
0.37001523168690786,
0.3805243302902413,