restart;To begin, use the !!! button in the toolbar to execute all the statements. Read the introduction carefully, then do the exercise in the second section.IntroductionIn grade school you learn about rational numbers, which are expressed as the ratio of two integers (whole numbers). Most numbers, like LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEnJiM5NjA7RicvJSdpdGFsaWNHUSZmYWxzZUYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJw==, are irrational. Every irrational number has infinite, non-repeating decimal expansion. Maple can give you many digits of this expansion, as inevalf(Pi,200);But of course, 200 or 200 trillion digits are as nothing compared to infinity. You also learn in grade school that LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEnJiM5NjA7RicvJSdpdGFsaWNHUSZmYWxzZUYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNjBRKSZhcHByb3g7RidGMi8lJmZlbmNlR0YxLyUqc2VwYXJhdG9yR0YxLyUpc3RyZXRjaHlHRjEvJSpzeW1tZXRyaWNHRjEvJShsYXJnZW9wR0YxLyUubW92YWJsZWxpbWl0c0dGMS8lJ2FjY2VudEdGMS8lJWZvcm1HUSZpbmZpeEYnLyUnbHNwYWNlR1EvdGhpY2ttYXRoc3BhY2VGJy8lJ3JzcGFjZUdGTC8lKG1pbnNpemVHUSIxRicvJShtYXhzaXplR1EpaW5maW5pdHlGJy1JJm1mcmFjR0YkNigtSSNtbkdGJDYkUSMyMkYnRjItRiM2Iy1GWTYkUSI3RidGMi8lLmxpbmV0aGlja25lc3NHUSIxRicvJStkZW5vbWFsaWduR1EnY2VudGVyRicvJSludW1hbGlnbkdGYG8vJSliZXZlbGxlZEdGMS1GLDYlUSFGJy9GMFEldHJ1ZUYnL0YzUSdpdGFsaWNGJw==. As point of fact,evalf(Pi-22/7);This approximation gives about 3 accurate digits, and it can be convenient at times to have the simpler rational form. But where did 22/7 come from, anyway? Is it just a coincidence? Can it be improved?The key to answering this question is an old idea called continued fractions. It's easiest to start these with a rational number to get the idea. I'll pick one based on my phone number. (Note that I can put more than one command on a line, as long as each ends with a semicolon.)x:= 3383/831; evalf(x);It's pretty obvious that I can write x as the sum of an integer (whole number) and a rational remainder less than one. The floor function is handy for rounding down to the nearest integer. (The square brackets below give subscripts on the variable names.)m[1]:= floor(x); remainder:= x - m[1];Since the remainder is less than one, its reciprocal is greater than one. y:= 1/remainder; evalf(y);So we can write y too as the sum of an integer part and remainder:m[2]:= floor(y); remainder:= y - m[2];Let's keep cranking these out. (I do this by copy/paste, rather than typing the same stuff over and over.)m[3]:= floor(1/remainder); remainder:= 1/remainder - m[3];m[4]:= floor(1/remainder); remainder:= 1/remainder - m[4];Aha! Since the reciprocal of this remainder is exactly the integer 4, we have reached the end of the line--no more remainders. m[5]:= floor(1/remainder); remainder:= 1/remainder - m[5];Obviously the sequence of numbers LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYnLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEibUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYjLUkjbW5HRiQ2JFEiMUYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R1EiMEYnLUkjbW9HRiQ2MFEiLEYnRj4vJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRjQvJSlzdHJldGNoeUdGSS8lKnN5bW1ldHJpY0dGSS8lKGxhcmdlb3BHRkkvJS5tb3ZhYmxlbGltaXRzR0ZJLyUnYWNjZW50R0ZJLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUSQwZW1GJy8lJ3JzcGFjZUdRM3Zlcnl0aGlja21hdGhzcGFjZUYnLyUobWluc2l6ZUdGPS8lKG1heHNpemVHUSlpbmZpbml0eUYnLUZENjBRIy4uRidGPkZHL0ZLRklGTEZORlBGUkZUL0ZXUShwb3N0Zml4RicvRlpRMG1lZGl1bW1hdGhzcGFjZUYnL0ZnbkZlbkZpbkZbby1GRDYwUSIuRidGPkZHRmFvRkxGTkZQRlJGVEZWRllGZm9GaW5GW28tRiw2JUYuLUYjNiMtRjs2JFEiNUYnRj5GQA== tells us something about x, but what? Let's go back and do things symbolically. First, we write x as the sum of an integer plus a remainder, which we give its own name.unassign('x');
x= m[1] + r[1];Next, we did the same trick again, representing 1/LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEickYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYjLUkjbW5HRiQ2JFEiMUYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R1EiMEYn as the sum LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEibUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYjLUkjbW5HRiQ2JFEiMkYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R1EiMEYnLUkjbW9HRiQ2MFEiK0YnRj4vJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRkkvJSlzdHJldGNoeUdGSS8lKnN5bW1ldHJpY0dGSS8lKGxhcmdlb3BHRkkvJS5tb3ZhYmxlbGltaXRzR0ZJLyUnYWNjZW50R0ZJLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUTBtZWRpdW1tYXRoc3BhY2VGJy8lJ3JzcGFjZUdGZW4vJShtaW5zaXplR1EiMUYnLyUobWF4c2l6ZUdRKWluZmluaXR5RictRiw2JS1GLzYlUSJyRidGMkY1RjhGQC1GRDYwUSIuRidGPkZHRkpGTEZORlBGUkZURlYvRlpRJDBlbUYnL0ZnbkZnb0ZobkZbby1GRDYwUSJ+RidGPkZHRkpGTEZORlBGUkZUL0ZXUSFGJ0Zmb0Zob0ZobkZbb0Zpbw==In other words,r[1]=1/(m[2]+r[2]);Putting this into the previous result (note that %% goes back to the next to last result),subs( %, %% ); And so on:subs( r[2]=1/(m[3]+r[3]), % );subs( r[3]=1/(m[4]+r[4]), % );subs( r[4]=1/m[5], % );The trail ends here because there are no more remainders, and Maple simplifies the result automatically. Equation (with LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEickYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYjLUkjbW5HRiQ2JFEiNEYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R1EiMEYnLUkjbW9HRiQ2MFEiPUYnRj4vJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRkkvJSlzdHJldGNoeUdGSS8lKnN5bW1ldHJpY0dGSS8lKGxhcmdlb3BHRkkvJS5tb3ZhYmxlbGltaXRzR0ZJLyUnYWNjZW50R0ZJLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUS90aGlja21hdGhzcGFjZUYnLyUncnNwYWNlR0Zlbi8lKG1pbnNpemVHUSIxRicvJShtYXhzaXplR1EpaW5maW5pdHlGJy1GIzYjLUkmbWZyYWNHRiQ2KC1GOzYkRmpuRj5GOC8lLmxpbmV0aGlja25lc3NHUSIxRicvJStkZW5vbWFsaWduR1EnY2VudGVyRicvJSludW1hbGlnbkdGam8vJSliZXZlbGxlZEdGSS1GLzYlUSFGJ0YyRjU=) is called the continued fraction form of the original x. The continued fraction method also works on irrational numbers, like LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEnJiM5NjA7RicvJSdpdGFsaWNHUSZmYWxzZUYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNjBRIi5GJ0YyLyUmZmVuY2VHRjEvJSpzZXBhcmF0b3JHRjEvJSlzdHJldGNoeUdGMS8lKnN5bW1ldHJpY0dGMS8lKGxhcmdlb3BHRjEvJS5tb3ZhYmxlbGltaXRzR0YxLyUnYWNjZW50R0YxLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUSQwZW1GJy8lJ3JzcGFjZUdGTC8lKG1pbnNpemVHUSIxRicvJShtYXhzaXplR1EpaW5maW5pdHlGJw==x:= Pi;m[1]:= floor(x); remainder:= x - m[1];Even though the remainder is not rational, it is still clearly less than one. evalf(remainder);m[2]:= floor(1/remainder); remainder:= 1/remainder - m[2];m[3]:= floor(1/remainder); remainder:= 1/remainder - m[3];m[4]:= floor(1/remainder); remainder:= 1/remainder - m[4];and so on. You can see the continued fraction form emerging in the remainder.The difference this time is that the process can never stop. If we ever got a zero remainder, then we would be able to write \317\200 as a rational number exactly by simplifying the continued fraction. However, by terminating the process prematurely (tossing out the remainder as if it were zero) we do get rational approximations to LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEnJiM5NjA7RicvJSdpdGFsaWNHUSZmYWxzZUYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNjBRIi5GJ0YyLyUmZmVuY2VHRjEvJSpzZXBhcmF0b3JHRjEvJSlzdHJldGNoeUdGMS8lKnN5bW1ldHJpY0dGMS8lKGxhcmdlb3BHRjEvJS5tb3ZhYmxlbGltaXRzR0YxLyUnYWNjZW50R0YxLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUSQwZW1GJy8lJ3JzcGFjZUdGTC8lKG1pbnNpemVHUSIxRicvJShtYXhzaXplR1EpaW5maW5pdHlGJw==x[1]:= m[1]+r[1]; subs(r[1]=0,x[1]);x[2]:= subs( r[1]=1/(m[2]+r[2]), x[1] ); subs(r[2]=0,x[2]);x[3]:= subs( r[2]=1/(m[3]+r[3]), x[2] ); subs(r[3]=0,x[3]);x[4]:= subs( r[3]=1/(m[4]+r[4]), x[3] ); subs(r[4]=0,x[4]);evalf( [3,22/7,333/106,355/113,Pi] );As you can see, the last approximation gets seven correct significant digits. Laboratory exercises1.Use the commands above to find the terminating continued fraction form of a rational number with three digits in the denominator (a phone number usually works well). 2.Find the continued fraction forms of LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkmbXNxcnRHRiQ2Iy1GIzYjLUkjbW5HRiQ2JFEiMkYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNjBRIn5GJ0Y0LyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y9LyUpc3RyZXRjaHlHRj0vJSpzeW1tZXRyaWNHRj0vJShsYXJnZW9wR0Y9LyUubW92YWJsZWxpbWl0c0dGPS8lJ2FjY2VudEdGPS8lJWZvcm1HUSFGJy8lJ2xzcGFjZUdRJDBlbUYnLyUncnNwYWNlR0ZPLyUobWluc2l6ZUdRIjFGJy8lKG1heHNpemVHUSlpbmZpbml0eUYnLUY4NjBRJGFuZEYnRjRGO0Y+RkBGQkZERkZGSEZKRk1GUEZSRlVGNw==the number LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2MFEvJkV4cG9uZW50aWFsRTtGJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJnVuc2V0RicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUlZm9ybUdGLi8lJ2xzcGFjZUdGLi8lJ3JzcGFjZUdGLi8lKG1pbnNpemVHRi4vJShtYXhzaXplR0Yu or exp(1) in Maple:evalf(exp(1),16);In each case you should find that the integers in the continued fraction follow a clear pattern. Find the error in the rational approximation defined by LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEibUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYjLUkjbW5HRiQ2JFEiMUYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R1EiMEYnLUkjbW9HRiQ2MFEiLEYnRj4vJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRjQvJSlzdHJldGNoeUdGSS8lKnN5bW1ldHJpY0dGSS8lKGxhcmdlb3BHRkkvJS5tb3ZhYmxlbGltaXRzR0ZJLyUnYWNjZW50R0ZJLyUlZm9ybUdRJmluZml4RicvJSdsc3BhY2VHUSQwZW1GJy8lJ3JzcGFjZUdRM3Zlcnl0aGlja21hdGhzcGFjZUYnLyUobWluc2l6ZUdGPS8lKG1heHNpemVHUSlpbmZpbml0eUYnLUZENjBRIy4uRidGPkZHL0ZLRklGTEZORlBGUkZUL0ZXUShwb3N0Zml4RicvRlpRMG1lZGl1bW1hdGhzcGFjZUYnL0ZnbkZlbkZpbkZbby1GRDYwUSIuRidGPkZHRmFvRkxGTkZQRlJGVEZWRllGZm9GaW5GW28tRiw2JUYuLUYjNiMtRjs2JFEiNEYnRj5GQEZnbw==LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn