This repository has been archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP7_CUBE_ROOT_APPROXIMATION.html
2106 lines (1709 loc) · 72.2 KB
/
P7_CUBE_ROOT_APPROXIMATION.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
<hr>
<p><strong>CUBE_ROOT_APPROXIMATION</strong></p>
<hr>
<p><span style="background:#ffff00">The <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank" rel="noopener">C++</a> program featured in this tutorial web page computes the approximate cube root of a real number using an iterative algorithm.</span></p>
<p><em>To view hidden text inside each of the preformatted text boxes below, scroll horizontally.</em></p>
<pre>Y := cube_root(X). // Y = X ^ (1/3).
(Y * Y * Y) = X. // X = Y ^ 3.
</pre>
<hr>
<p><strong>SOFTWARE_APPLICATION_COMPONENTS</strong></p>
<hr>
<p>C++_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation.cpp</a></p>
<p>plain-text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation_output.txt</a></p>
<hr>
<p><strong>PROGRAM_COMPILATION_AND_EXECUTION</strong></p>
<hr>
<p>STEP_0: Copy and paste the C++ <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation.cpp" target="_blank" rel="noopener">source code</a> into a new text editor document and save that document as the following file name:</p>
<pre>cube_root_approximation.cpp</pre>
<p>STEP_1: Open a <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Unix" target="_blank" rel="noopener">Unix</a> command line terminal application and set the current directory to wherever the C++ program file is located on the local machine (e.g. Desktop).</p>
<pre>cd Desktop</pre>
<p>STEP_2: Compile the C++ file into machine-executable instructions (i.e. object file) and then into an executable piece of software named <strong>app</strong> using the following command:</p>
<pre>g++ cube_root_approximation.cpp -o app</pre>
<p>STEP_3: If the program compilation command does not work, then use the following commands (in top-down order) to install the C/C++ compiler (which is part of the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/GNU_Compiler_Collection" target="_blank" rel="noopener">GNU Compiler Collection (GCC)</a>):</p>
<pre>sudo apt install build-essential</pre>
<pre>sudo apt-get install g++</pre>
<p>STEP_4: After running the <strong>g++</strong> command, run the executable file using the following command:</p>
<pre>./app</pre>
<p>STEP_5: Once the application is running, the following prompt will appear:</p>
<pre>Enter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than 100:</pre>
<p>STEP_6: Enter a value for N using the keyboard.</p>
<p>STEP_7: Statements showing program throughput and the value returned by the cube root function which computes the approximate value of x raised to the power of (1/3) will be printed to the command line terminal and to the file output stream and then the following prompt will appear:</p>
<pre>Would you like to continue inputting program values? (Enter 1 if YES. Enter 0 if NO):</pre>
<p>STEP_8: Enter a value according to your preference until you decide to close the program (and save your program data to the <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation_output.txt" target="_blank" rel="noopener">output file</a>).</p>
<hr>
<p><strong>PROGRAM_SOURCE_CODE</strong></p>
<hr>
<p>Note that the text inside of each of the the preformatted text boxes below appears on this web page (while rendered correctly by the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Web_browser" target="_blank" rel="noopener">web browser</a>) to be identical to the content of that preformatted text box text’s respective <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Plain_text" target="_blank" rel="noopener">plain-text</a> file or <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Source_code" target="_blank" rel="noopener">source code</a> output file (whose <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/URL" target="_blank" rel="noopener">Uniform Resource Locator</a> is displayed as the <strong style="background:#000000;color:#00ff00">green</strong> <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Hyperlink" target="_blank" rel="noopener">hyperlink</a> immediately above that preformatted text box (if that hyperlink points to a <strong>source code file</strong>) or whose Uniform Resource Locator is displayed as the <strong style="background:#000000;color:#ff9000">orange</strong> hyperlink immediately above that preformatted text box (if that hyperlink points to a <strong>plain-text file</strong>)).</p>
<p>A <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer" target="_blank" rel="noopener">computer</a> interprets a C++ source code as a series of programmatic instructions (i.e. <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Software" target="_blank" rel="noopener">software</a>) which govern how the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_hardware" target="_blank" rel="noopener">hardware</a> of that computer behaves).</p>
<p><em>(Note that angle brackets which resemble <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a> tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’)) displayed on this web page have been replaced (at the source code level of this web page) with the Unicode symbols <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Less-than_sign" target="_blank" rel="noopener">U+003C</a> (which is rendered by the web browser as ‘<‘) and <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Greater-than_sign" target="_blank" rel="noopener">U+003E</a> (which is rendered by the web browser as ‘>’). That is because the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/WordPress.com" target="_blank" rel="noopener">WordPress</a> web page editor or web browser interprets a plain-text version of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor or web browser deletes or fails to display those (plain-text) inequality symbols and the content between those (plain-text) inequality symbols)).</em></p>
<p>C++_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation.cpp</a></p>
<hr>
<pre>
/**
* file: cube_root_approximation.cpp
* type: C++ (source file)
* date: 19_JUNE_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
/* preprocessing directives */
#include <iostream> // standard input (std::cin), standard output (std::cout)
#include <fstream> // file input, file output
#define MAXIMUM_X 1000 // constant which represents maximum absolute value of the program input value
#define E 0.00000001 // constant which represents the degree of accuracy of the square root approximation
/* function prototypes */
float absolute_value(float x);
long double difference(long double n, long double b);
long double compute_cube_root_of_real_number(float x, std::ostream & output);
/**
* Return the absolute value of a real number input, x.
*/
float absolute_value(float x)
{
if (x < 0) return -1 * x;
return x;
}
/**
* Return the absolute value of (n - (b * b * b)).
*/
long double difference(long double n, long double b)
{
if (n > (b * b * b)) return (n - (b * b * b));
return ((b * b * b) - n);
}
/**
* Compute the approximate cube root of a real number, x, using an iterative method.
*
* The cube root of x is x raised to the power of (1/3).
*
* Assume that x is a float type value and that output is an output stream object.
*
* This function returns a value whose data type is long double (which is a floating-point number).
*/
long double compute_cube_root_of_real_number(float x, std::ostream & output)
{
int i = 0;
float original_x = x;
long double A = 0.0, B = 0.0, C = 0.0, epsilon = 0.0;
x = absolute_value(x);
x = ((x > MAXIMUM_X) || (x < 1)) ? 0 : x; // If x is out of range, then set x to 0. Also, to avoid an infinite loop as a result of the absolute value of x being too small, set x to 0 if the absolute value of x is smaller than 1.
C = x;
output << "\n\nC = " << C << ". // real number to take the cube root of";
output << "\nB = " << B << ". // variable for storing the approximate cube root of x";
output << "\nA = " << A << ". // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i";
output << "\nepsilon = " << epsilon << ". // variable for storing the difference between the input value and B raised to the power of 3";
while (true)
{
output << "\n\ni := " << i << ".";
output << "\nC := " << C << ".";
output << "\nA := " << A << ".";
B = (A + C) / 2;
epsilon = difference(x, B);
output << "\nB := (A + C) / 2 = " << B << ".";
output << "\nepsilon = difference(x , B) = " << epsilon << ".";
if (epsilon <= E)
{
if (original_x < 0) return -1 * B;
return B;
}
if ((B * B * B) > x) C = B;
else A = B;
i += 1;
}
}
/* program entry point */
int main()
{
// Declare a float type variable and set its initial value to zero.
float x = 0.0;
// Declare a double type variable and set its initial value to zero.
long double S = 0.0;
// Declare a variable for storing the program user's answer of whether or not to continue inputting values.
int input_additional_values = 1;
// Declare a file output stream object.
std::ofstream file;
// Set the number of digits of floating-point numbers which are printed to the command line terminal to 100 digits.
std::cout.precision(100);
// Set the number of digits of floating-point numbers which are printed to the file output stream to 100 digits.
file.precision(100);
/**
* If cube_root_approximation_output.txt does not already exist in the same directory as cube_root_approximation.cpp,
* create a new file named cube_root_approximation_output.txt.
*
* Open the plain-text file named cube_root_approximation_output.txt
* and set that file to be overwritten with program data.
*/
file.open("cube_root_approximation_output.txt");
// Print an opening message to the command line terminal.
std::cout << "\n\n--------------------------------";
std::cout << "\nStart Of Program";
std::cout << "\n--------------------------------";
// Print an opening message to the file output stream.
file << "--------------------------------";
file << "\nStart Of Program";
file << "\n--------------------------------";
// Prompt the user to enter an x value as many times as the user chooses to.
while (input_additional_values != 0)
{
// Print "Enter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than {MAXIMUM_X}: " to the command line terminal.
std::cout << "\n\nEnter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than " << MAXIMUM_X << ": ";
// Scan the command line terminal for the most recent keyboard input value.
std::cin >> x;
// Print "The value which was entered for x is {x}." to the command line terminal.
std::cout << "\nThe value which was entered for x is " << x << ".";
// Print "The value which was entered for x is {x}." to the file output stream.
file << "\n\nThe value which was entered for x is " << x << ".";
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
// Print "Computing the approximate cube root of x:" to the command line terminal.
std::cout << "\n\nComputing the approximate cube root of x:";
// Print "Computing the approximate cube root of x:" to the file output stream.
file << "\n\nComputing the approximate cube root of x:";
// Compute the approximate cube root of x using the Bijection Method, print the computational steps to the command line terminal, and store the function result in S.
S = compute_cube_root_of_real_number(x, std::cout);
// Compute the approximate square root of x using Heron's Method and print the computational steps to the file output stream.
compute_cube_root_of_real_number(x, file);
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
// Print "S = approximate_cube_root({x}) = {S}." to the command line terminal.
std::cout << "\n\nS = approximate_cube_root(" << x << ") = " << S << ".";
// Print "S = approximate_cube_root({x}) = {S}." to the file output stream.
file << "\n\nS = approximate_cube_root(" << x << ") = " << S << ".";
// Print "(S * S * S) = " << {(S * S * S)} << ". // the approximate value of x" to the command line terminal.
std::cout << "\n\n(S * S * S) = " << (S * S * S) << ". // the approximate absolute value of x";
// Print "(S * S * S) = " << {(S * S * S)} << ". // the approximate value of x" to the command line terminal.
std::cout << "\n\n(S * S * S) = " << (S * S * S) << ". // the approximate absolute value of x";
// Ask the user whether or not to continue inputing values.
std::cout << "\n\nWould you like to continue inputing program values? (Enter 1 if YES. Enter 0 if NO): ";
// Scan the command line terminal for the most recent user input entered via keyboard to store in the variable named input_additional_values.
std::cin >> input_additional_values;
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
}
// Print a closing message to the command line terminal.
std::cout << "\nEnd Of Program";
std::cout << "\n--------------------------------\n\n";
// Print a closing message to the file output stream.
file << "\nEnd Of Program";
file << "\n--------------------------------";
// Close the file output stream.
file.close();
// Exit the program.
return 0;
}</pre>
<hr>
<p><strong>SAMPLE_PROGRAM_OUTPUT</strong></p>
<hr>
<p>The text in the preformatted text box below was generated by one use case of the C++ program featured in this <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_programming" target="_blank" rel="noopener">computer programming</a> tutorial web page.</p>
<p>plain-text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/cube_root_approximation_output.txt</a></p>
<hr>
<pre>--------------------------------
Start Of Program
--------------------------------
The value which was entered for x is 8.
--------------------------------
Computing the approximate cube root of x:
C = 8. // real number to take the cube root of
B = 0. // variable for storing the approximate cube root of x
A = 0. // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i
epsilon = 0. // variable for storing the difference between the input value and B raised to the power of 3
i := 0.
C := 8.
A := 0.
B := (A + C) / 2 = 4.
epsilon = difference(x , B) = 56.
i := 1.
C := 4.
A := 0.
B := (A + C) / 2 = 2.
epsilon = difference(x , B) = 0.
--------------------------------
S = approximate_cube_root(8) = 2.
--------------------------------
The value which was entered for x is 125.
--------------------------------
Computing the approximate cube root of x:
C = 125. // real number to take the cube root of
B = 0. // variable for storing the approximate cube root of x
A = 0. // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i
epsilon = 0. // variable for storing the difference between the input value and B raised to the power of 3
i := 0.
C := 125.
A := 0.
B := (A + C) / 2 = 62.5.
epsilon = difference(x , B) = 244015.625.
i := 1.
C := 62.5.
A := 0.
B := (A + C) / 2 = 31.25.
epsilon = difference(x , B) = 30392.578125.
i := 2.
C := 31.25.
A := 0.
B := (A + C) / 2 = 15.625.
epsilon = difference(x , B) = 3689.697265625.
i := 3.
C := 15.625.
A := 0.
B := (A + C) / 2 = 7.8125.
epsilon = difference(x , B) = 351.837158203125.
i := 4.
C := 7.8125.
A := 0.
B := (A + C) / 2 = 3.90625.
epsilon = difference(x , B) = 65.395355224609375.
i := 5.
C := 7.8125.
A := 3.90625.
B := (A + C) / 2 = 5.859375.
epsilon = difference(x , B) = 76.165676116943359375.
i := 6.
C := 5.859375.
A := 3.90625.
B := (A + C) / 2 = 4.8828125.
epsilon = difference(x , B) = 8.584678173065185546875.
i := 7.
C := 5.859375.
A := 4.8828125.
B := (A + C) / 2 = 5.37109375.
epsilon = difference(x , B) = 29.948793351650238037109375.
i := 8.
C := 5.37109375.
A := 4.8828125.
B := (A + C) / 2 = 5.126953125.
epsilon = difference(x , B) = 9.765286929905414581298828125.
i := 9.
C := 5.126953125.
A := 4.8828125.
B := (A + C) / 2 = 5.0048828125.
epsilon = difference(x , B) = 0.366568681783974170684814453125.
i := 10.
C := 5.0048828125.
A := 4.8828125.
B := (A + C) / 2 = 4.94384765625.
epsilon = difference(x , B) = 4.164306548773311078548431396484375.
i := 11.
C := 5.0048828125.
A := 4.94384765625.
B := (A + C) / 2 = 4.974365234375.
epsilon = difference(x , B) = 1.912767149406136013567447662353515625.
i := 12.
C := 5.0048828125.
A := 4.974365234375.
B := (A + C) / 2 = 4.9896240234375.
epsilon = difference(x , B) = 0.776584445929984212853014469146728515625.
i := 13.
C := 5.0048828125.
A := 4.9896240234375.
B := (A + C) / 2 = 4.99725341796875.
epsilon = difference(x , B) = 0.205880517370360394124872982501983642578125.
i := 14.
C := 5.0048828125.
A := 4.99725341796875.
B := (A + C) / 2 = 5.001068115234375.
epsilon = difference(x , B) = 0.080125756849014351246296428143978118896484375.
i := 15.
C := 5.001068115234375.
A := 4.99725341796875.
B := (A + C) / 2 = 4.9991607666015625.
epsilon = difference(x , B) = 0.062931940783439443976021721027791500091552734375.
i := 16.
C := 5.001068115234375.
A := 4.9991607666015625.
B := (A + C) / 2 = 5.00011444091796875.
epsilon = difference(x , B) = 0.008583265300010634035743350978009402751922607421875.
i := 17.
C := 5.00011444091796875.
A := 4.9991607666015625.
B := (A + C) / 2 = 4.999637603759765625.
epsilon = difference(x , B) = 0.027177748099647958124336355467676185071468353271484375.
i := 18.
C := 5.00011444091796875.
A := 4.999637603759765625.
B := (A + C) / 2 = 4.9998760223388671875.
epsilon = difference(x , B) = 0.009298094029959631801052211130809155292809009552001953125.
i := 19.
C := 5.00011444091796875.
A := 4.9998760223388671875.
B := (A + C) / 2 = 4.99999523162841796875.
epsilon = difference(x , B) = 0.00035762752759194160745437329751439392566680908203125.
i := 20.
C := 5.00011444091796875.
A := 4.99999523162841796875.
B := (A + C) / 2 = 5.000054836273193359375.
epsilon = difference(x , B) = 0.0041127655949197150508922504741349257528781890869140625.
i := 21.
C := 5.000054836273193359375.
A := 4.99999523162841796875.
B := (A + C) / 2 = 5.0000250339508056640625.
epsilon = difference(x , B) = 0.001877555710920887632742193318335921503603458404541015625.
i := 22.
C := 5.0000250339508056640625.
A := 4.99999523162841796875.
B := (A + C) / 2 = 5.00001013278961181640625.
epsilon = difference(x , B) = 0.00075996076098865106285273895991849713027477264404296875.
i := 23.
C := 5.00001013278961181640625.
A := 4.99999523162841796875.
B := (A + C) / 2 = 5.000002682209014892578125.
epsilon = difference(x , B) = 0.000201165784030642169621927450862131081521511077880859375.
i := 24.
C := 5.000002682209014892578125.
A := 4.99999523162841796875.
B := (A + C) / 2 = 4.9999989569187164306640625.
epsilon = difference(x , B) = 7.823107994742173332269885577261447906494140625e-05.
i := 25.
C := 5.000002682209014892578125.
A := 4.9999989569187164306640625.
B := (A + C) / 2 = 5.00000081956386566162109375.
epsilon = difference(x , B) = 6.14672999998955305045456043444573879241943359375e-05.
i := 26.
C := 5.00000081956386566162109375.
A := 4.9999989569187164306640625.
B := (A + C) / 2 = 4.999999888241291046142578125.
epsilon = difference(x , B) = 8.381902984189171235129833803512156009674072265625e-06.
i := 27.
C := 5.00000081956386566162109375.
A := 4.999999888241291046142578125.
B := (A + C) / 2 = 5.0000003539025783538818359375.
epsilon = difference(x , B) = 2.654269525524666217819458324811421334743499755859375e-05.
i := 28.
C := 5.0000003539025783538818359375.
A := 4.999999888241291046142578125.
B := (A + C) / 2 = 5.00000012107193470001220703125.
epsilon = difference(x , B) = 9.080395322380585554356002830900251865386962890625e-06.
i := 29.
C := 5.00000012107193470001220703125.
A := 4.999999888241291046142578125.
B := (A + C) / 2 = 5.000000004656612873077392578125.
epsilon = difference(x , B) = 3.4924596579999356293910750537179410457611083984375e-07.
i := 30.
C := 5.000000004656612873077392578125.
A := 4.999999888241291046142578125.
B := (A + C) / 2 = 4.9999999464489519596099853515625.
epsilon = difference(x , B) = 4.016328560015047788311903786961920559406280517578125e-06.
i := 31.
C := 5.000000004656612873077392578125.
A := 4.9999999464489519596099853515625.
B := (A + C) / 2 = 4.99999997555278241634368896484375.
epsilon = difference(x , B) = 1.833541309802233509884672457701526582241058349609375e-06.
i := 32.
C := 5.000000004656612873077392578125.
A := 4.99999997555278241634368896484375.
B := (A + C) / 2 = 4.999999990104697644710540771484375.
epsilon = difference(x , B) = 7.42147675182602828414246687316335737705230712890625e-07.
i := 33.
C := 5.000000004656612873077392578125.
A := 4.999999990104697644710540771484375.
B := (A + C) / 2 = 4.9999999973806552588939666748046875.
epsilon = difference(x , B) = 1.96450855478869090831040011835284531116485595703125e-07.
i := 34.
C := 5.000000004656612873077392578125.
A := 4.9999999973806552588939666748046875.
B := (A + C) / 2 = 5.00000000101863406598567962646484375.
epsilon = difference(x , B) = 7.6397554969742653696584966382943093776702880859375e-08.
i := 35.
C := 5.00000000101863406598567962646484375.
A := 4.9999999973806552588939666748046875.
B := (A + C) / 2 = 4.999999999199644662439823150634765625.
epsilon = difference(x , B) = 6.0026650310074369798485349747352302074432373046875e-08.
i := 36.
C := 5.00000000101863406598567962646484375.
A := 4.999999999199644662439823150634765625.
B := (A + C) / 2 = 5.0000000001091393642127513885498046875.
epsilon = difference(x , B) = 8.1854523159563541412353515625e-09.
--------------------------------
S = approximate_cube_root(125) = 5.0000000001091393642127513885498046875.
--------------------------------
The value which was entered for x is -8.
--------------------------------
Computing the approximate cube root of x:
C = 8. // real number to take the cube root of
B = 0. // variable for storing the approximate cube root of x
A = 0. // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i
epsilon = 0. // variable for storing the difference between the input value and B raised to the power of 3
i := 0.
C := 8.
A := 0.
B := (A + C) / 2 = 4.
epsilon = difference(x , B) = 56.
i := 1.
C := 4.
A := 0.
B := (A + C) / 2 = 2.
epsilon = difference(x , B) = 0.
--------------------------------
S = approximate_cube_root(-8) = -2.
--------------------------------
The value which was entered for x is 1000.
--------------------------------
Computing the approximate cube root of x:
C = 1000. // real number to take the cube root of
B = 0. // variable for storing the approximate cube root of x
A = 0. // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i
epsilon = 0. // variable for storing the difference between the input value and B raised to the power of 3
i := 0.
C := 1000.
A := 0.
B := (A + C) / 2 = 500.
epsilon = difference(x , B) = 124999000.
i := 1.
C := 500.
A := 0.
B := (A + C) / 2 = 250.
epsilon = difference(x , B) = 15624000.
i := 2.
C := 250.
A := 0.
B := (A + C) / 2 = 125.
epsilon = difference(x , B) = 1952125.
i := 3.
C := 125.
A := 0.
B := (A + C) / 2 = 62.5.
epsilon = difference(x , B) = 243140.625.
i := 4.
C := 62.5.
A := 0.
B := (A + C) / 2 = 31.25.
epsilon = difference(x , B) = 29517.578125.
i := 5.
C := 31.25.
A := 0.
B := (A + C) / 2 = 15.625.
epsilon = difference(x , B) = 2814.697265625.
i := 6.
C := 15.625.
A := 0.
B := (A + C) / 2 = 7.8125.
epsilon = difference(x , B) = 523.162841796875.
i := 7.
C := 15.625.
A := 7.8125.
B := (A + C) / 2 = 11.71875.
epsilon = difference(x , B) = 609.325408935546875.
i := 8.
C := 11.71875.
A := 7.8125.
B := (A + C) / 2 = 9.765625.
epsilon = difference(x , B) = 68.677425384521484375.
i := 9.
C := 11.71875.
A := 9.765625.
B := (A + C) / 2 = 10.7421875.
epsilon = difference(x , B) = 239.590346813201904296875.
i := 10.
C := 10.7421875.
A := 9.765625.
B := (A + C) / 2 = 10.25390625.
epsilon = difference(x , B) = 78.122295439243316650390625.
i := 11.
C := 10.25390625.
A := 9.765625.
B := (A + C) / 2 = 10.009765625.
epsilon = difference(x , B) = 2.932549454271793365478515625.
i := 12.
C := 10.009765625.
A := 9.765625.
B := (A + C) / 2 = 9.8876953125.
epsilon = difference(x , B) = 33.314452390186488628387451171875.
i := 13.
C := 10.009765625.
A := 9.8876953125.
B := (A + C) / 2 = 9.94873046875.
epsilon = difference(x , B) = 15.302137195249088108539581298828125.
i := 14.
C := 10.009765625.
A := 9.94873046875.
B := (A + C) / 2 = 9.979248046875.
epsilon = difference(x , B) = 6.212675567439873702824115753173828125.
i := 15.
C := 10.009765625.
A := 9.979248046875.
B := (A + C) / 2 = 9.9945068359375.
epsilon = difference(x , B) = 1.647044138962883152998983860015869140625.
i := 16.
C := 10.009765625.
A := 9.9945068359375.
B := (A + C) / 2 = 10.00213623046875.
epsilon = difference(x , B) = 0.641006054792114809970371425151824951171875.
i := 17.
C := 10.00213623046875.
A := 9.9945068359375.
B := (A + C) / 2 = 9.998321533203125.
epsilon = difference(x , B) = 0.503455526267515551808173768222332000732421875.
i := 18.
C := 10.00213623046875.
A := 9.998321533203125.
B := (A + C) / 2 = 10.0002288818359375.
epsilon = difference(x , B) = 0.068666122400085072285946807824075222015380859375.
i := 19.
C := 10.0002288818359375.
A := 9.998321533203125.
B := (A + C) / 2 = 9.99927520751953125.
epsilon = difference(x , B) = 0.217421984797183664994690843741409480571746826171875.
i := 20.
C := 10.0002288818359375.
A := 9.99927520751953125.
B := (A + C) / 2 = 9.999752044677734375.
epsilon = difference(x , B) = 0.074384752239677054408417689046473242342472076416015625.
i := 21.
C := 10.0002288818359375.
A := 9.999752044677734375.
B := (A + C) / 2 = 9.9999904632568359375.
epsilon = difference(x , B) = 0.00286102022073553285963498638011515140533447265625.
i := 22.
C := 10.0002288818359375.
A := 9.9999904632568359375.
B := (A + C) / 2 = 10.00010967254638671875.
epsilon = difference(x , B) = 0.0329021247593577204071380037930794060230255126953125.
i := 23.
C := 10.00010967254638671875.
A := 9.9999904632568359375.
B := (A + C) / 2 = 10.000050067901611328125.
epsilon = difference(x , B) = 0.015020445687367101061937546546687372028827667236328125.
i := 24.
C := 10.000050067901611328125.
A := 9.9999904632568359375.
B := (A + C) / 2 = 10.0000202655792236328125.
epsilon = difference(x , B) = 0.00607968608790920850282191167934797704219818115234375.
i := 25.
C := 10.0000202655792236328125.
A := 9.9999904632568359375.
B := (A + C) / 2 = 10.00000536441802978515625.
epsilon = difference(x , B) = 0.001609326272245137356975419606897048652172088623046875.
i := 26.
C := 10.00000536441802978515625.
A := 9.9999904632568359375.
B := (A + C) / 2 = 9.999997913837432861328125.
epsilon = difference(x , B) = 0.00062584863957937386658159084618091583251953125.
i := 27.
C := 10.00000536441802978515625.
A := 9.999997913837432861328125.
B := (A + C) / 2 = 10.0000016391277313232421875.
epsilon = difference(x , B) = 0.0004917383999991642440363648347556591033935546875.
i := 28.
C := 10.0000016391277313232421875.
A := 9.999997913837432861328125.
B := (A + C) / 2 = 9.99999977648258209228515625.
epsilon = difference(x , B) = 6.7055223873513369881038670428097248077392578125e-05.
i := 29.
C := 10.0000016391277313232421875.
A := 9.99999977648258209228515625.
B := (A + C) / 2 = 10.000000707805156707763671875.
epsilon = difference(x , B) = 0.00021234156204197329742555666598491370677947998046875.
i := 30.
C := 10.000000707805156707763671875.
A := 9.99999977648258209228515625.
B := (A + C) / 2 = 10.0000002421438694000244140625.
epsilon = difference(x , B) = 7.2643162579044684434848022647202014923095703125e-05.
i := 31.
C := 10.0000002421438694000244140625.
A := 9.99999977648258209228515625.
B := (A + C) / 2 = 10.00000000931322574615478515625.
epsilon = difference(x , B) = 2.79396772639994850351286004297435283660888671875e-06.
i := 32.
C := 10.00000000931322574615478515625.
A := 9.99999977648258209228515625.
B := (A + C) / 2 = 9.999999892897903919219970703125.
epsilon = difference(x , B) = 3.2130628480120382306495230295695364475250244140625e-05.
i := 33.
C := 10.00000000931322574615478515625.
A := 9.999999892897903919219970703125.
B := (A + C) / 2 = 9.9999999511055648326873779296875.
epsilon = difference(x , B) = 1.4668330478417868079077379661612212657928466796875e-05.
i := 34.
C := 10.00000000931322574615478515625.
A := 9.9999999511055648326873779296875.
B := (A + C) / 2 = 9.99999998020939528942108154296875.
epsilon = difference(x , B) = 5.937181401460822627313973498530685901641845703125e-06.
i := 35.
C := 10.00000000931322574615478515625.
A := 9.99999998020939528942108154296875.
B := (A + C) / 2 = 9.999999994761310517787933349609375.
epsilon = difference(x , B) = 1.571606843830952726648320094682276248931884765625e-06.
i := 36.
C := 10.00000000931322574615478515625.
A := 9.999999994761310517787933349609375.
B := (A + C) / 2 = 10.0000000020372681319713592529296875.
epsilon = difference(x , B) = 6.11180439757941229572679731063544750213623046875e-07.
i := 37.
C := 10.0000000020372681319713592529296875.
A := 9.999999994761310517787933349609375.
B := (A + C) / 2 = 9.99999999839928932487964630126953125.
epsilon = difference(x , B) = 4.80213202480594958387882797978818416595458984375e-07.
i := 38.
C := 10.0000000020372681319713592529296875.
A := 9.99999999839928932487964630126953125.
B := (A + C) / 2 = 10.000000000218278728425502777099609375.
epsilon = difference(x , B) = 6.54836185276508331298828125e-08.
i := 39.
C := 10.000000000218278728425502777099609375.
A := 9.99999999839928932487964630126953125.
B := (A + C) / 2 = 9.9999999993087840266525745391845703125.
epsilon = difference(x , B) = 2.0736479200422763824462890625e-07.
i := 40.
C := 10.000000000218278728425502777099609375.
A := 9.9999999993087840266525745391845703125.
B := (A + C) / 2 = 9.99999999976353137753903865814208984375.
epsilon = difference(x , B) = 7.0940586738288402557373046875e-08.
i := 41.
C := 10.000000000218278728425502777099609375.
A := 9.99999999976353137753903865814208984375.
B := (A + C) / 2 = 9.999999999990905052982270717620849609375.
epsilon = difference(x , B) = 2.7284841053187847137451171875e-09.
--------------------------------
S = approximate_cube_root(1000) = 9.999999999990905052982270717620849609375.
--------------------------------
The value which was entered for x is 3.1400001049041748046875.
--------------------------------
Computing the approximate cube root of x:
C = 3.1400001049041748046875. // real number to take the cube root of
B = 0. // variable for storing the approximate cube root of x
A = 0. // number to add to C before dividing the sum of A and C by 2 for each while loop iteration, i
epsilon = 0. // variable for storing the difference between the input value and B raised to the power of 3
i := 0.
C := 3.1400001049041748046875.
A := 0.
B := (A + C) / 2 = 1.57000005245208740234375.
epsilon = difference(x , B) = 0.72989328296328886773979005564427779972902499139308929443359375.
i := 1.
C := 1.57000005245208740234375.
A := 0.
B := (A + C) / 2 = 0.785000026226043701171875.
epsilon = difference(x , B) = 2.65626343142074184560698368873232766418368555605411529541015625.
i := 2.
C := 1.57000005245208740234375.
A := 0.785000026226043701171875.
B := (A + C) / 2 = 1.1775000393390655517578125.
epsilon = difference(x , B) = 1.5073888318975885679262827210322939208708703517913818359375.
i := 3.
C := 1.57000005245208740234375.
A := 1.1775000393390655517578125.
B := (A + C) / 2 = 1.37375004589557647705078125.
epsilon = difference(x , B) = 0.5474738704539012898626915148980742742423899471759796142578125.
i := 4.
C := 1.57000005245208740234375.
A := 1.37375004589557647705078125.
B := (A + C) / 2 = 1.471875049173831939697265625.
epsilon = difference(x , B) = 0.04869378768681393893254238935952571409870870411396026611328125.
i := 5.
C := 1.471875049173831939697265625.
A := 1.37375004589557647705078125.
B := (A + C) / 2 = 1.4228125475347042083740234375.
epsilon = difference(x , B) = 0.25966472170411463902227333644390228073461912572383880615234375.
i := 6.
C := 1.471875049173831939697265625.
A := 1.4228125475347042083740234375.
B := (A + C) / 2 = 1.44734379835426807403564453125.
epsilon = difference(x , B) = 0.10809842450396796591401138432075867967796511948108673095703125.
i := 7.
C := 1.471875049173831939697265625.
A := 1.44734379835426807403564453125.
B := (A + C) / 2 = 1.459609423764050006866455078125.
epsilon = difference(x , B) = 0.0303610937093032767254696668857150143594481050968170166015625.
i := 8.
C := 1.471875049173831939697265625.
A := 1.459609423764050006866455078125.
B := (A + C) / 2 = 1.4657422364689409732818603515625.
epsilon = difference(x , B) = 0.0090009611727116579406315910460989471175707876682281494140625.
i := 9.
C := 1.4657422364689409732818603515625.
A := 1.459609423764050006866455078125.
B := (A + C) / 2 = 1.46267583011649549007415771484375.
epsilon = difference(x , B) = 0.0107213262234489643993928797982562173274345695972442626953125.
i := 10.
C := 1.4657422364689409732818603515625.
A := 1.46267583011649549007415771484375.
B := (A + C) / 2 = 1.464209033292718231678009033203125.
epsilon = difference(x , B) = 0.0008705083265141623678762261562269486603327095508575439453125.
i := 11.
C := 1.4657422364689409732818603515625.
A := 1.464209033292718231678009033203125.
B := (A + C) / 2 = 1.4649756348808296024799346923828125.
epsilon = difference(x , B) = 0.0040626436212677177230168101829121951595880091190338134765625.
i := 12.
C := 1.4649756348808296024799346923828125.
A := 1.464209033292718231678009033203125.
B := (A + C) / 2 = 1.46459233408677391707897186279296875.
epsilon = difference(x , B) = 0.00159542211586210179972977751816642921767197549343109130859375.
i := 13.
C := 1.46459233408677391707897186279296875.
A := 1.464209033292718231678009033203125.
B := (A + C) / 2 = 1.464400683689746074378490447998046875.
epsilon = difference(x , B) = 0.00036229553291318612739946303236138192005455493927001953125.
i := 14.
C := 1.464400683689746074378490447998046875.
A := 1.464209033292718231678009033203125.
B := (A + C) / 2 = 1.4643048584912321530282497406005859375.
epsilon = difference(x , B) = 0.00025414673460094866323799589480358918081037700176239013671875.
i := 15.
C := 1.464400683689746074378490447998046875.
A := 1.4643048584912321530282497406005859375.
B := (A + C) / 2 = 1.46435277109048911370337009429931640625.
epsilon = difference(x , B) = 5.406431437603685663528807481270632706582546234130859375e-05.
i := 16.
C := 1.46435277109048911370337009429931640625.
A := 1.4643048584912321530282497406005859375.
B := (A + C) / 2 = 1.464328814790860633365809917449951171875.
epsilon = difference(x , B) = 0.00010004373126623069233109841746909296489320695400238037109375.
i := 17.
C := 1.46435277109048911370337009429931640625.
A := 1.464328814790860633365809917449951171875.
B := (A + C) / 2 = 1.4643407929406748735345900058746337890625.
epsilon = difference(x , B) = 2.2990338738696457221433178119696094654500484466552734375e-05.
i := 18.
C := 1.46435277109048911370337009429931640625.
A := 1.4643407929406748735345900058746337890625.
B := (A + C) / 2 = 1.46434678201558199361898005008697509765625.
epsilon = difference(x , B) = 1.55368302446261090377088720515530440025031566619873046875e-05.
i := 19.
C := 1.46434678201558199361898005008697509765625.
A := 1.4643407929406748735345900058746337890625.
B := (A + C) / 2 = 1.464343787478128433576785027980804443359375.
epsilon = difference(x , B) = 3.72679364046553211753387557791938888840377330780029296875e-06.
i := 20.
C := 1.46434678201558199361898005008697509765625.
A := 1.464343787478128433576785027980804443359375.
B := (A + C) / 2 = 1.4643452847468552135978825390338897705078125.
epsilon = difference(x , B) = 5.90500845371239903303095530873179086484014987945556640625e-06.
i := 21.
C := 1.4643452847468552135978825390338897705078125.
A := 1.464343787478128433576785027980804443359375.
B := (A + C) / 2 = 1.46434453611249182358733378350734710693359375.
epsilon = difference(x , B) = 1.08910494453257240821120177542979945428669452667236328125e-06.
i := 22.
C := 1.46434453611249182358733378350734710693359375.
A := 1.464343787478128433576785027980804443359375.
B := (A + C) / 2 = 1.464344161795310128582059405744075775146484375.
epsilon = difference(x , B) = 1.318844963489086696828422873295494355261325836181640625e-06.
i := 23.
C := 1.46434453611249182358733378350734710693359375.
A := 1.464344161795310128582059405744075775146484375.
B := (A + C) / 2 = 1.4643443489539009760846965946257114410400390625.
epsilon = difference(x , B) = 1.1487016335874622452450921628042124211788177490234375e-07.
i := 24.
C := 1.46434453611249182358733378350734710693359375.
A := 1.4643443489539009760846965946257114410400390625.
B := (A + C) / 2 = 1.46434444253319639983601518906652927398681640625.
epsilon = difference(x , B) = 4.8711735211692634706093230079204658977687358856201171875e-07.
i := 25.
C := 1.46434444253319639983601518906652927398681640625.
A := 1.4643443489539009760846965946257114410400390625.
B := (A + C) / 2 = 1.464344395743548687960355891846120357513427734375.
epsilon = difference(x , B) = 1.8612358476167469023554446039270260371267795562744140625e-07.
i := 26.
C := 1.464344395743548687960355891846120357513427734375.
A := 1.4643443489539009760846965946257114410400390625.
B := (A + C) / 2 = 1.4643443723487248320225262432359158992767333984375.
epsilon = difference(x , B) = 3.562670829702907493441443875781260430812835693359375e-08.
i := 27.
C := 1.4643443723487248320225262432359158992767333984375.
A := 1.4643443489539009760846965946257114410400390625.
B := (A + C) / 2 = 1.46434436065131290405361141893081367015838623046875.
epsilon = difference(x , B) = 3.9621728131940259221011046975036151707172393798828125e-08.
i := 28.
C := 1.4643443723487248320225262432359158992767333984375.
A := 1.46434436065131290405361141893081367015838623046875.
B := (A + C) / 2 = 1.464344366500018868038068831083364784717559814453125.
epsilon = difference(x , B) = 1.997510067942853684286319548846222460269927978515625e-09.
--------------------------------