CS 121 Lab 4: Smiley Faces and Madlibs -- Sharpening Your Maple SkillsDr. Frederick W. Chapman(Last Revised on November 13, 2007)We encourage you to work on all the CS 121 labs in groups of two or three students. Although you may work together, you should each submit your own copy of the lab to Blackboard Vista at the end of class. Type your name and the name(s) of your partner(s) in the spaces provided below.Your Name: Partner #1: Partner #2:

Lab 4 is divided into the following sections:5 tutorials5 required problems2 optional problemsYou will need to complete all 5 tutorials and all 5 required problems to prepare for Quiz 4.Note: All students are required to remain in the lab until the end of class. If you finish all of the tutorials and required problems early, you should work on the optional problem(s). Ask a course staff member to give you feedback on your work and recommend a Maple topic which you can explore further. Feel free to offer to help your fellow students, which will also help you learn Maple better. Strive to become a Maple expert -- it will empower you to finish your work in your other classes more quickly, more easily, and with fewer mistakes!Click on the triangles in the left margin to open each of the worksheet sections below. Remember to save your work frequently!
<Text-field style="Heading 1" layout="Heading 1">Introduction</Text-field>Labs 1-3 introduced you to many different features of Maple. The early labs taught you how to use the Maple worksheet interface, acquainted you with the most useful Maple commands, and showed you how to write simple Maple programs to automatically perform otherwise tedious tasks. The primary purpose of Lab 4 is to reinforce the fundamental material from Labs 1-3 rather than to introduce a lot of new material. Lab 4 includes some whimsical and light-hearted problems with a serious underlying purpose: to give you the practice you need to sharpen your Maple skills even further.This lab will review the following key ideas from previous labs:the plot command and the plots packagethe solve commandthe print and printf commandssingle for loops and nested for loopsthe if ... then ... else ... end if conditional statementcreating and using liststhe rand functionThis lab introduce a little new material to help you get even more mileage out of what you already know about Maple:creating one-line functions with the arrow operator (->)creating simple Maple procedures with proc ... end proc.calling your Maple procedures and passing parametersTwo major themes in this lab are plotting and random processes. To reinforce and further expand your Maple plotting skills, we will learn how to create a smiley face and add new features to it. The optional problem even shows you how to animate your smiley face in various ways. Instead of using random processes to performing computational experiments, we will use them to generate random words to fill in the blanks of a madlib. In this lab, you'll not only learn Maple better -- you'll have some fun doing it!
<Text-field style="Heading 1" layout="Heading 1">Tutorial 1: Creating Plots and Solving Equations</Text-field>In this tutorial, we will review Maple's plot command and various commands in the plots package, as well as the Maple solve command for solving equations. We will use these graphical and mathematical tools for a noble scientific purpose -- we will create an adorable smiley face! Along the way, we will learn some useful new options which give us more control over the appearance of our plots and the form of the solutions to our equations.First, load the plots package:with(plots);Recall that a circle with center (a,b) and radius r can be described by the implicit equationLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUklbXN1cEdGJDYlLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEqJnVtaW51czA7RicvRjtRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0ZFLyUpc3RyZXRjaHlHRkUvJSpzeW1tZXRyaWNHRkUvJShsYXJnZW9wR0ZFLyUubW92YWJsZWxpbWl0c0dGRS8lJ2FjY2VudEdGRS8lJ2xzcGFjZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRlQtRjQ2JVEiYUYnRjdGOkZBRkEtRiM2JC1JI21uR0YkNiRRIjJGJ0ZBRkEvJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnLUY+Ni1RIitGJ0ZBRkNGRkZIRkpGTEZORlBGUkZVLUYsNiUtRi82JC1GIzYmLUY0NiVRInlGJ0Y3RjpGPS1GNDYlUSJiRidGN0Y6RkFGQUZaRmpuLUY+Ni1RIj1GJ0ZBRkNGRkZIRkpGTEZORlAvRlNRLDAuMjc3Nzc3OGVtRicvRlZGYHAtRiw2JS1GNDYlUSJyRidGN0Y6RlpGam4tRj42LVEiLkYnRkFGQ0ZGRkhGSkZMRk5GUC9GU1EmMC4wZW1GJy9GVkZbcUZBThe implicitplot command from the plots package can be used to plot such equations. Here is a plot of the circle with center at the origin (0,0) and radius 8:implicitplot(x^2 + y^2 = 8^2, x=-8..8, y=-8..8);Many Maple plotting commands accept various options which are described in the following help page:?plot,optionsFor example, we can use the thickness option with the implicitplot command to make the circle thicker:implicitplot(x^2 + y^2 = 8^2, x=-8..8, y=-8..8, thickness=5);This will be the head of our smiley face. Let's save this plot to a variable so that we can use it later:Head := implicitplot(x^2 + y^2 = 8^2, x=-8..8, y=-8..8, thickness=5);We can use the pointplot command from the plots package to plot individual points (or lists of points). For example, we can put the right eye at the point (3,3):pointplot([3,3]);Let us use some plot options to specify the symbol, the symbolsize, and the color used in this pointplot:pointplot([3,3], symbol=solidcircle, symbolsize=50, color=red);This will be the right eye of our smiley face.RightEye := pointplot([3,3], symbol=solidcircle, symbolsize=50, color=red);Let's put the left eye at the point (-3,3) and save the result to a variable:pointplot([-3,3], symbol=solidcircle, symbolsize=50, color=red);LeftEye := pointplot([-3,3], symbol=solidcircle, symbolsize=50, color=red);For the smile, we will use a circular arc -- not the whole circle. The arc will lie on the circle with center (0,0) and radius 5, which has the implicit equationeqn := x^2 + y^2 = 5^2;We need to solve this equation explicitly for the variable y. We can do this with the Maple solve command:soln := solve(eqn, y);We get two different solutions. Since we want an arc on the lower semicircle to make a smile, we must choose the solution with the negative square root. We can do this by further constraining the problem with the inequality LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIjxGJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIjBGJ0Y5Rjk= on the dependent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and the inequalities LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUkjbW9HRiQ2LVEqJnVtaW51czA7RicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y0LyUpc3RyZXRjaHlHRjQvJSpzeW1tZXRyaWNHRjQvJShsYXJnZW9wR0Y0LyUubW92YWJsZWxpbWl0c0dGNC8lJ2FjY2VudEdGNC8lJ2xzcGFjZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRkMtSSNtbkdGJDYkUSI1RidGLy1GLDYtUSI8RidGL0YyRjVGN0Y5RjtGPUY/L0ZCUSwwLjI3Nzc3NzhlbUYnL0ZFRk4tSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvRjBRJ2l0YWxpY0YnRkpGRkYv on the independent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=. Note the special syntax which is used to accomplish this.soln := solve({eqn, y < 0}, y) assuming -5 < x, x < 5;Maple returns the solution to the constrained problem as a set containing a single equation. We can use the eval command to substitute this equation into the dependent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= to obtain a formula for the lower semicircle in terms of the independent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=:lower := eval(y, soln);Now that we have the appropriate solution, we will plot the values of this solution for x between -4 and 4. We will use the view option to display the smile in a larger region which will ultimately contain the head. We will use the thickness option to make the smile thicker.plot(lower, x=-4..4, view=[-8..8, -8..8], thickness=10);Save the smile to a variable:Smile := plot(lower, x=-4..4, view=[-8..8, -8..8], thickness=10);We can use the display command from the plots package to combine all these plots together to create the smiley face. We will use the axes option to specify that no axes should be displayed.SmileyFace1 := display({Head, RightEye, LeftEye, Smile}, axes=none);SmileyFace1; # Here's looking at you, kid!
<Text-field style="Heading 1" layout="Heading 1">Problem 1: Add Features to Your Smiley Face</Text-field>This problem asks you to add some additional features to the smiley face we created in the previous tutorial. To do this as easily as possible, first identify the relevant Maple commands above, copy and paste them into your worksheet below, and then modify them to solve the given problem.
<Text-field style="Heading 2" layout="Heading 2">Part (a): Add a Nose</Text-field>You can add a nose to the smiley face by plotting a point at the origin (0,0). Use the soliddiamond symbol of size 75 colored red. After you work out the appropriate command to do this, save the resulting plot to a variable called Nose. Add the nose to your smiley face and save the result to a variable called SmileyFace2. To finish this part of the problem, display your magnificent new creation!
<Text-field style="Heading 2" layout="Heading 2">Part (b): Add Eyebrows</Text-field>You can add eyebrows by adapting the technique we used to create the smile. Each eyebrow will be a circular arc which lies on the upper half of a circle.To create the right eyebrow, use a circular arc lying on the circle with center (3,3) and radius 2. First, enter the equation of this circle in implicit form (see Tutorial 1 above for the general form of the equation).Now solve this equation for y. Since we want the upper semicircle, we must select the solution generated by the positive square root. We can do this by constraining the problem with the inequalities LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj5GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIjNGJ0Y5Rjk= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUkjbW5HRiQ2JFEiMUYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNi1RIjxGJ0YvLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y4LyUpc3RyZXRjaHlHRjgvJSpzeW1tZXRyaWNHRjgvJShsYXJnZW9wR0Y4LyUubW92YWJsZWxpbWl0c0dGOC8lJ2FjY2VudEdGOC8lJ2xzcGFjZUdRLDAuMjc3Nzc3OGVtRicvJSdyc3BhY2VHRkctSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvRjBRJ2l0YWxpY0YnRjItRiw2JFEiNUYnRi9GLw==.Next, use the eval command to substitute this equation into the dependent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= to obtain a formula for the upper semicircle in terms of the independent variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=:Plot this solution for x between 2 and 4. Use the same view option we used for the smile. Use a thickness of 5. Save the resulting plot to the variable RightBrow.To create the left eyebrow, follow the same steps as for the right eyebrow, but put the center of the circle at (-3,3). Select the appropriate solution of the new equation by constraining the problem with the inequalities LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj5GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIjNGJ0Y5Rjk= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYqLUkjbW9HRiQ2LVEqJnVtaW51czA7RicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y0LyUpc3RyZXRjaHlHRjQvJSpzeW1tZXRyaWNHRjQvJShsYXJnZW9wR0Y0LyUubW92YWJsZWxpbWl0c0dGNC8lJ2FjY2VudEdGNC8lJ2xzcGFjZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRkMtSSNtbkdGJDYkUSI1RidGLy1GLDYtUSI8RidGL0YyRjVGN0Y5RjtGPUY/L0ZCUSwwLjI3Nzc3NzhlbUYnL0ZFRk4tSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvRjBRJ2l0YWxpY0YnRkpGKy1GRzYkUSIxRidGL0Yv. Plot this solution for x between -4 and -2 and save the resulting plot to the variable LeftBrow.Now add the right and left eyebrows to your smiley face and save the resulting plot to a variable called SmileyFace3. To finish this part of the problem, display your stylish new face. What a looker!
<Text-field style="Heading 1" layout="Heading 1">Tutorial 2: Using Loops to Repeat Tasks</Text-field>In this tutorial and the problem which follows, we will review loops in Maple -- both single loops and nested loops. We will see how Maple's ability to perform a task over and over inside a loop can make short work of an otherwise tedious task.You have been a very naughty student -- your teacher caught you using the Facebook website during class. (By the way, don't ever do that in this class if you want credit for attending the lab!) As punishment, your teacher has asked you to type out the following sentence 50 times:I will not use Facebook in class.Since you know something about Maple, you can see an opportunity to take the sting out of this punishment. You write and execute the following for loop:for i from 1 to 50 do print("I will not use Facebook in class.");end do;You don't like the way the double quotes look, but you remember how to get rid of them by doing formatted printing with the printf command. You use the special \134n newline character to put each sentence on a new line.for i from 1 to 50 do printf("I will not use Facebook in class.\134n");end do;You show this to your teacher and brag about how easy it was to do this using Maple. Your teacher now thinks you're a smart aleck (see "wiseacre") and comes up with a new punishment. Your teacher says, "I want you to do it again, but this time I want you to number each line individually. HA! I bet you can't do that in Maple!" Obviously, your teacher doesn't know anything about programming -- but fortunately, you do. Your formulate this reply using the %d formatting code for integer values:for i from 1 to 50 do printf("%d. I will not use Facebook in class.\134n", i);end do;
<Text-field style="Heading 1" layout="Heading 1">Problem 2: Maple Makes Punishment Fun!</Text-field>This problem continues the theme from the previous tutorial. By this time, your teacher is still very annoyed with you, but is beginning to admire your vast knowledge of computer science. Your teacher thinks for a while and then comes up with the ultimate punishment: "I want you to to do it again, but type it out a different way for each day of the term -- like this!"I will not use Facebook in class on Day 1 of Week 1.I will not use Facebook in class on Day 2 of Week 1.I will not use Facebook in class on Day 3 of Week 1.I will not use Facebook in class on Day 4 of Week 1.I will not use Facebook in class on Day 5 of Week 1....I will not use Facebook in class on Day 1 of Week 11.I will not use Facebook in class on Day 2 of Week 11.I will not use Facebook in class on Day 3 of Week 11.I will not use Facebook in class on Day 4 of Week 11.I will not use Facebook in class on Day 5 of Week 11.You realize that this too can be done easily in Maple. All you have to do is change the single loop to a nested loop -- that is, a loop within a loop.Write a doubly nested loop to generate the output assigned by your teacher as punishment. Pick two different loop variables, like i and j, or better yet, day and week. Use the outer loop variable to number the weeks and the inner loop variable to number the days. Use the %d formatting code twice this time -- once for the number of the day and once for the number of the week.
<Text-field style="Heading 1" layout="Heading 1">Tutorial 3: Using Conditionals to Make Decisions</Text-field>This tutorial and the problem which follows review how the Maple if statement can be used to make decisions in a Maple program. In particular, we can choose between two different courses of action by using the if ... then ... else ... end if form of the if statement.Having tasted the power of Maple in the previous problem and tutorial, your mind races -- you now realize that the possibilities are endless! Overcome with excitement, you throw yourself into a veritable programming frenzy!! You become an unstoppable force of nature!!! Oh, the sheer drama of it all!!!!!!In particular, you realize that you can use Maple to complete your punishment with style and panache. Building on Tutorial 2, you come up with the following clever code, which changes the wording depending on whether the line number is odd or even.for i from 1 to 50 do if type(i, odd) then printf("%d. I will not use Facebook in class.\134n", i); else # i is even printf("%d. I shall not use Facebook in class.\134n", i); end if;end do;
<Text-field style="Heading 1" layout="Heading 1">Problem 3: Maple Makes You Sassy!</Text-field>This follow-up problem to the previous tutorial builds on Problem 2. It occurs to you that Day 1 of Week 3 is a university holiday, which means you won't be in class that day. You decide to rewrite your punishment accordingly.Use an if ... then ... else ... end if statement to modify your solution to Problem 2 so that your Maple code prints the following on Day 1 of Week 3:Day 1 of Week 3 is a holiday and I will do as I please!You can use the = symbol to construct a condition which tests whether a variable equals a given value. You can use Maple's and operator to construct a condition which is true when the number of the day equals 1 and the number of the week equals 3. For example, to determine if m equals 1 and n equals 3, you can test the conditionLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYsLUkjbWlHRiQ2JVEibUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj1GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIjFGJ0Y5LUY2Ni1RIn5GJ0Y5RjtGPkZARkJGREZGRkgvRktRJjAuMGVtRicvRk5GVy1GNjYvUSRhbmRGJy8lJWJvbGRHRjEvRjNRJWJvbGRGJy8lK2ZvbnR3ZWlnaHRHRmluRjtGPkZARkJGREZGRkhGVkZYRlMtRiw2JVEibkYnRi9GMkY1LUZQNiRRIjNGJ0Y5Rjk=.Be sure to modify this condition to use the names of the variables from your loop (not necessarily LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEibUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEibkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=).
<Text-field style="Heading 1" layout="Heading 1">Tutorial 4: Lists, Random Numbers, and the Arrow Operator</Text-field>This tutorial first reviews how to create and use lists and then reviews how to generate random numbers. We will see that lists and random numbers can be used together to generate random text. After we learn how to do this, we will make it more convenient by using the Maple arrow operator (->) to create a simple Maple function which generates random text. The arrow (->) is just a minus sign (-) followed by a greater-than sign (>).First, let's create a list of adjectives:Adjectives := ["happy", "sassy", "stupendous", "enormous", "speedy", "sparkly", "delicious", "spicy", "bubbly", "wreckless", "silly"];Let's count the number of adjectives in the list:A := nops(Adjectives);Here's how to access the individual elements of the list inside a loop:for i from 1 to A do Adjectives[i];end do;Now let's create a random number generate which produces random integers between 1 and A inclusive:RandA := rand(1..A);Let's try it out by generating one random number at a time or a sequence of random numbers:RandA();RandA();RandA();seq(RandA(), i=1..20);Note that this random number generator produces numbers which are valid indices for our list of adjectives. Consequently, we can use this random number generator together with the list of adjectives to generate a sequence of random adjectives! Here's how to generate one random adjective:i := RandA(); # generate random index iAdjectives[i]; # look up i-th adjectiveWe can easily combine this process into a single step by eliminating the index variable LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiaUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=:Adjectives[RandA()];We can make this more convenient by using the Maple arrow operator (->) to create a one-line Maple function which generates a single random adjective:RandAdj := () -> Adjectives[RandA()]; # define functionTo use this function, we must add parentheses after the function name. Each time we call the function, we get another random adjective:RandAdj(); # use functionRandAdj(); # use functionRandAdj(); # use functionFinally, here's how to generate a sequence of random adjectives:seq(RandAdj(), i=1..20);
<Text-field style="Heading 1" layout="Heading 1">Problem 4: Maple Makes You the Life of the Party!</Text-field>In the previous tutorial, we learned how to generate random text. We will now use our new-found ability to write a Maple program which generates madlibs automatically.
<Text-field style="Heading 2" layout="Heading 2">Part (a): Random Nouns</Text-field>Our madlib generator will require some random nouns. We can adapt the very same technique we used above to generate random adjectivesFirst, create your own list of nouns and save the list to the variable Nouns. The madlibs will work best if the nouns are people or animals or machines capable of acting on other things; e.g., "singer", "cat", "robot". Be sure to enclose each noun in double quotes.Now use nops to count the number of nouns in your list Nouns, and save the result to a variable N. Next, create a random number generator which generates random integers from 1 to N inclusive, and save it to the variable RandN.Use your RandN function to generate several random numbers one at a time:Now use the seq command to generate a sequence of 20 random numbers:Create a one-line Maple function called RandNoun which generates random nouns.Use your RandNoun function to generate several random nouns one at a time:Now use the seq command generate a sequence of 20 random nouns:
<Text-field style="Heading 2" layout="Heading 2">Part (b): Random Verbs</Text-field>Our madlib generator will also require some random verbs. In particular, we will need verbs in the past tense, preferably transitive verbs (meaning verbs which take action on some object), like "broke", "sold", and "carried".Copy your solution to Part (a) above, paste it here, and then adapt your Maple code to solve Part (b). Use the variable names Verbs and V and RandV for the intermediate steps. Create a random verb generator called RandVerb. Try out RandVerb a number of times to make sure that it works properly.
<Text-field style="Heading 2" layout="Heading 2">Part (c): Let the Hilarity Ensue!</Text-field>We will now use the RandAdj, RandNoun, and RandVerb functions we created above to generate madlibs based on the children's song, The Itsy Bitsy Spider. Here are the original words:The itsy bitsy spider climbed up the water spout.Down came the rain and washed the spider out.Out came the sun and dried up all the rain,So the itsy bitsy spider climbed up the spout again.First, use the function RandAdj to generate two random adjectives, and save the results in the variables Adj1 and Adj2.Next, use the RandNoun function to generate four random nouns, and save the results in the variables Noun1, Noun2, Noun3, and Noun4.Then use the RandVerb functions to generate three random verbs, and save the results in the variables Verb1, Verb2, and Verb3.For best results, make sure that your random adjectives, nouns, and verbs are all different! You can eliminate duplicates by rerunning a particular command until you get a new word.Finally, run the following code to generate your hilariously entertaining madlib:# given...printf("The %s %s %s %s up the %s.\134n", Adj1, Adj2, Noun1, Verb1, Noun2);printf("Down came the %s and %s the %s out.\134n", Noun3, Verb2, Noun1);printf("Out came the %s and %s up all the %s,\134n", Noun4, Verb3, Noun3);printf("So the %s %s %s %s up the %s again.\134n\134n", Adj1, Adj2, Noun1, Verb1, Noun2);You can run all the Maple code for Part (c) over and over to generate new collections of random adjectives, nouns, and verbs and thus create completely new madlibs. Try it!
<Text-field style="Heading 1" layout="Heading 1">Tutorial 5: Maple Procedures</Text-field>In the previous problem, we developed some Maple code which automatically generates a madlib; however, it can become tedious to rerun so many lines of Maple code every time we want to generate a new madlib. In this tutorial, we will see how we can automate the process and make it more convenient by implementing the madlib generator as a Maple procedure. We'll name the procedure Madlib and define it by executing the following Maple code:Madlib := proc() local Adj1, Adj2, Noun1, Noun2, Noun3, Noun4, Verb1, Verb2, Verb3; Adj1 := RandAdj(); Adj2 := RandAdj(); Noun1 := RandNoun(); Noun2 := RandNoun(); Noun3 := RandNoun(); Noun4 := RandNoun(); Verb1 := RandVerb(); Verb2 := RandVerb(); Verb3 := RandVerb(); printf("The %s %s %s %s up the %s.\134n", Adj1, Adj2, Noun1, Verb1, Noun2); printf("Down came the %s and %s the %s out.\134n", Noun3, Verb2, Noun1); printf("Out came the %s and %s up all the %s,\134n", Noun4, Verb3, Noun3); printf("So the %s %s %s %s up the %s again.\134n\134n", Adj1, Adj2, Noun1, Verb1, Noun2);end proc;Notice how we collected together all the Maple commands we need to generate a new madlib. We put these commands inside of a Maple procedure to make it easier to rerun these commands conveniently as many times as we want. Specifically, we put these commands after proc() and before end proc.We declared all the intermediate variables such as Adj1, Adj2, and Noun1 to be local variables -- this means that the variables are just temporary variables which are needed only inside the procedure Madlib. Local variables do not have any affect on the rest of our Maple session.Now we can generate madlibs easily just by calling the procedure Madlib. We can do this by adding parentheses after the procedure name as follows:Madlib();We can even generate multiple madlibs by calling the procedure Madlib inside a for loop:for i from 1 to 5 do Madlib();end do;Now that we have developed a procedure which makes it easy to generate new madlibs, we will enhance the procedure Madlib in the next problem to make it even more flexible and useful. In particular, we will make the lists of adjectives, nouns, and verbs be parameters to the procedure so that we can easily generate a wider variety of madlibs.To lay the groundwork to achieve this goal, we will now create one new procedure RandWord which will take the place of our three procedures RandAdj, RandNoun, and RandVerb. The new procedure RandWord will accept any list of words as input and then select a word from this list at random to produce the output. Execute the following Maple code to define this procedure:RandWord := proc(Words) # input is a list of words local W, RandW; W := nops(Words); RandW := rand(1..W); Words[RandW()]; # output is one random wordend proc;We will now discuss how the procedure works. How do we give it a name? How does it know what to accept as input and what to produce as output? Once we define the procedure, how do we use (or "call") it?Procedure Name: The name of the procedure is the variable name on the left of the assignment operator (:=). In this case, the procedure is named RandWord.Procedure Input: The input to the procedure is determined by the variable name (or names) enclosed in parentheses after proc. For procedure RandWord, there is one input, namely the list of words, which is denoted by the variable name Words.Procedure Output: The last command executed inside the procedure determines the output of the procedure. For procedure RandWord, the output is the random word generated by the Words[RandW()] command.Procedure Call: We can pass whatever list of words we want as input to the procedure RandWord by enclosing the name of the list in parentheses; e.g., RandWord(Adjectives) and RandWord(Nouns) and RandWord(Verbs) will do the same things that RandAdj() and RandNoun() and RandVerb() did before.The advantage of the new approach is that we can now change the list of words whenever we want without writing a new Maple procedure! For example, let us create a completely new list of adjectives Adjectives and use it to test our new procedure RandWord:Adjectives := ["snowy", "gentle", "dark", "bright", "loud", "soft", "fuzzy", "slippery", "jumpy"];RandWord(Adjectives);RandWord(Adjectives);RandWord(Adjectives);seq(RandWord(Adjectives), i=1..20);With the fundamental building block RandWord, we can now create a much more flexible and useful madlib generator Madlib in the next problem.
<Text-field style="Heading 1" layout="Heading 1">Problem 5: Why Maple Programmers Have More Fun</Text-field>In this problem, we will enhance the procedure Madlib so that the lists of adjectives, nouns, and verbs can be passed as input to Madlib. We will achieve this by using the building block RandWord which we created in the previous tutorial.
<Text-field style="Heading 2" layout="Heading 2">Part (a): Random Nouns and Random Verbs Revisited</Text-field>First, create a completely new list of nouns Nouns and use it to test our new procedure RandWord:Now create a completely new list of past-tense, transitive verbs called Verbs and use it to test our new procedure RandWord:
<Text-field style="Heading 2" layout="Heading 2">Part (b): Hilarity, the Sequel</Text-field>To create the new-and-improved procedure Madlib, copy the original procedure Madlib from the previous tutorial, paste it below, and then make the following changes:1. Modify the procedure Madlib to accept the three lists Adjectives, Nouns, and Verbs as input. You will need to add these variables inside the parentheses after the proc.2. Replace the calls to the three different procedures RandAdj, RandNoun, and RandVerb with calls to procedure RandWord. Remember to provide the appropriate list of words -- Adjectives or Nouns or Verbs -- as input to RandWord when you call this procedure inside your new version of Madlib.Now test your new procedure Madlib by calling it -- for input, use the three lists of Adjectives, Nouns, and Verbs which you defined earlier:Put your procedure call to Madlib inside a for loop to generate 5 different madlibs:Just for kicks, switch your lists of Nouns and Verbs in your call to Madlib:The procedure still works, but the results no longer make any grammatical sense!
<Text-field style="Heading 1" layout="Heading 1">Problem 6 (Optional): Animating Your Smiley Face</Text-field>This three-part problem teaches you how to use Maple to animate your smiley face in a number of different ways. Begin by skimming the following help topics to get a quick overview of Maple's animation capabilities:?animate?plots,animate
<Text-field style="Heading 2" layout="Heading 2">Part (a): Animating the Features of Your Smiley Face</Text-field>Show the values of your variables SmileyFace1, SmileyFace2, and SmileyFace3 from Tutorial 1 and Problem 1 to make sure they are still defined:Now use the display command with the insequence=true option to generate an animation of your three smiley faces in the order you created them.Hint: Enclose the variable names containing your three smiley faces in square brackets [ ] instead of curly brackets { }. Recall that lists (denoted by square brackets) preserve the order of the elements whereas sets (denoted by curly brackets) do not.How to Run the Animation: Go back, left-click on the animation, and then play the animation using the appropriate buttons on the animation context bar at the top of the screen. You will want to lower number of frames per second (FPS) to 1 to slow down the animation so that you can see it. Figure out how to use the animation context bar to play the animation in a continuous cycle.How to Create an Animated GIF File: Right-click on the animation to open a pop-up context menu, and then select the Export > Graphics Interchange Format menu item to save your animation as an animated GIF file on your desktop. Clicking on the icon for the GIF file on the desktop will play your animation outside of Maple! You can even post your animated GIF file on a website so that others can watch your animation from their web browser.
<Text-field style="Heading 2" layout="Heading 2">Part (b): Choosing the Center of Your Smiley Face</Text-field>The following procedure PlotFace creates a simplified version of our first smiley face from Tutorial 1:# given...PlotFace := proc() local x, y, Head, RightEye, LeftEye, Smile; Head := implicitplot(x^2 + y^2 = 8^2, x=-8..8, y=-8..8); RightEye := pointplot([3, 3], symbol=solidcircle, color=red); LeftEye := pointplot([-3, 3], symbol=solidcircle, color=red); Smile := implicitplot(x^2 + y^2 = 5^2, x=-4..4, y=-5..0); display({Head, RightEye, LeftEye, Smile}, axes=none, scaling=constrained);end proc;Now we can create this smiley face simply by calling the procedure PlotFace:PlotFace(); # givenThe resulting smiley face is centered at the origin LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtbkdGJDYkUSIwRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LVEiLEYnRjQvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHUSV0cnVlRicvJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EmMC4wZW1GJy8lJ3JzcGFjZUdRLDAuMzMzMzMzM2VtRidGMEY0RjRGNA==. Create a new version of procedure PlotFace which accepts as input the variables LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and produces as output a smiley face centered at the point LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtaUdGJDYlUSJhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEiLEYnL0Y4USdub3JtYWxGJy8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGNi8lKXN0cmV0Y2h5R0ZCLyUqc3ltbWV0cmljR0ZCLyUobGFyZ2VvcEdGQi8lLm1vdmFibGVsaW1pdHNHRkIvJSdhY2NlbnRHRkIvJSdsc3BhY2VHUSYwLjBlbUYnLyUncnNwYWNlR1EsMC4zMzMzMzMzZW1GJy1GMTYlUSJiRidGNEY3Rj5GPkY+.Hints:1. You will need to modify the equations used to produce the head and smile and change the coordinates of the points used to produce the eyes. Express these in terms of LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=.2. You will need to change the range of LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= values displayed by each implicitplot, expressing them in terms of LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEiYkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= as well.Test your new procedure PlotFace by plotting the smiley faces centered at LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtbkdGJDYkUSIwRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LVEiLEYnRjQvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHUSV0cnVlRicvJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EmMC4wZW1GJy8lJ3JzcGFjZUdRLDAuMzMzMzMzM2VtRidGMEY0RjRGNA== and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtbkdGJDYkUSMxMEYnLyUsbWF0aHZhcmlhbnRHUSdub3JtYWxGJy1JI21vR0YkNi1RIixGJ0Y0LyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR1EldHJ1ZUYnLyUpc3RyZXRjaHlHRj0vJSpzeW1tZXRyaWNHRj0vJShsYXJnZW9wR0Y9LyUubW92YWJsZWxpbWl0c0dGPS8lJ2FjY2VudEdGPS8lJ2xzcGFjZUdRJjAuMGVtRicvJSdyc3BhY2VHUSwwLjMzMzMzMzNlbUYnLUYxNiRRIzIwRidGNEY0RjRGNA==. First plot them separately, and then plot them together using display.
<Text-field style="Heading 2" layout="Heading 2">Part (c): Moving Your Smiley Face Along a Curve</Text-field>The following function PlotXY plots a small solid red circle at the specified point LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEiLEYnL0Y4USdub3JtYWxGJy8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGNi8lKXN0cmV0Y2h5R0ZCLyUqc3ltbWV0cmljR0ZCLyUobGFyZ2VvcEdGQi8lLm1vdmFibGVsaW1pdHNHRkIvJSdhY2NlbnRHRkIvJSdsc3BhY2VHUSYwLjBlbUYnLyUncnNwYWNlR1EsMC4zMzMzMzMzZW1GJy1GMTYlUSJ5RidGNEY3Rj5GPkY+:PlotXY := (x,y) -> pointplot([x,y], symbol=solidcircle, color=red, axes=none); # givenFor example, we can use PlotXY to create a plot of the points LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtbkdGJDYkUSIxRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LVEiLEYnRjQvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBh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USwwLjIyMjIyMjJlbUYnL0ZORl9vRk9GOUY5Rjk= as LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= goes from 0 to 1. We can do this with the following animate command:animate(PlotXY, [t, t*(1-t)], t=0..1); # givenNote: Be sure to go back and run the animation after you create it!Use the animate command and your PlotFace procedure from Part (b) to create an animation which shows the smiley face centered at LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEiLEYnL0Y4USdub3JtYWxGJy8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGNi8lKXN0cmV0Y2h5R0ZCLyUqc3ltbWV0cmljR0ZCLyUobGFyZ2VvcEdGQi8lLm1vdmFibGVsaW1pdHNHRkIvJSdhY2NlbnRHRkIvJSdsc3BhY2VHUSYwLjBlbUYnLyUncnNwYWNlR1EsMC4zMzMzMzMzZW1GJy1GMTYlUSJ5RidGNEY3Rj5GPkY+ moving along the curve defined parametrically by the equations LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj1GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIjBGJ0Y5Rjk= and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYqLUkjbWlHRiQ2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj1GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRJDEwMEYnRjktRjY2LVEqJnVtaW51czA7RidGOUY7Rj5GQEZCRkRGRkZIL0ZLUSwwLjIyMjIyMjJlbUYnL0ZORlctRjY2LVEifkYnRjlGO0Y+RkBGQkZERkZGSC9GS1EmMC4wZW1GJy9GTkZnbi1JJW1zdXBHRiQ2JS1GLDYlUSJ0RidGL0YyLUYjNiQtRlA2JFEiMkYnRjlGOS8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRictRiw2I1EhRidGOQ== as LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= goes from -10 to 10.Now go back and run the animation in a continuous loop! This animation simulates a bouncing ball which is perfectly elastic and encounters no resistance due to friction.Next, create an animation which sh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2JVEieUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RIj1GJy9GM1Enbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIzUwRidGOS1GNjYtUScmc2RvdDtGJ0Y5RjtGPkZARkJGREZGRkgvRktRJjAuMGVtRicvRk5GVy1GLDYlUSRhYnNGJy9GMEY9RjktSShtZmVuY2VkR0YkNiQtRiM2JS1GLDYlUSRzaW5GJ0ZmbkY5LUZobjYkLUYjNiYtRiw2JVEnJiM5NjA7RidGZm5GOUZTLUYsNiVRInRGJ0YvRjJGOUY5RjlGOUY5 as LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= goes from 0 to 5. Use the frames option of animate to generate an animation with 31 frames.Go back and run the animation, which approximates the motion of a bouncing ball moving horizontally.Finally, create an animation which shows the smiley face centered at LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkobWZlbmNlZEdGJDYkLUYjNiYtSSNtaUdGJDYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEiLEYnL0Y4USdub3JtYWxGJy8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckd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0vJSlzdHJldGNoeUdGPS8lKnN5bW1ldHJpY0dGPS8lKGxhcmdlb3BHRj0vJS5tb3ZhYmxlbGltaXRzR0Y9LyUnYWNjZW50R0Y9LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTC1JI21uR0YkNiRRIzUwRidGOS1GNjYtUScmc2RvdDtGJ0Y5RjtGPkZARkJGREZGRkgvRktRJjAuMGVtRicvRk5GVy1GLDYlUSRzaW5GJy9GMEY9RjktSShtZmVuY2VkR0YkNiQtRiM2KC1GUDYkUSI0RidGOUZTLUYsNiVRJyYjOTYwO0YnRmZuRjlGUy1GLDYlUSJ0RidGL0YyRjlGOS1GLDYjUSFGJ0Y5 as LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= goes from 0 to 1.Go back and run the animation in a continuous loop to see the smiley face moving in an infinite figure-eight pattern. It looks downright happy to see you, doesn't it?! :-)
<Text-field style="Heading 1" layout="Heading 1">Problem 7 (Optional): Eliminating Duplicate Random Words</Text-field>There is one small problem with the Madlib procedure which you created in Problem 5(b): It sometimes generates the same random word twice. When this happens, the resulting madlib is less interesting than it would be if all the random words were unique.This optional problem shows you how to eliminate the duplicates from your random words to generate higher quality madlibs. The key is to convert your original list of words into a set of words and then remove the randomly chosen words from the set so that only unused words remain. If we select the next random word from words which have not yet been used, we will never select the same word twice!The following example illustrates the technique. First, let us create a list of words:Words := ["here", "are", "some", "words"]; # givenNow convert the list of words into set of words:WordSet := {op(Words)}; # givenUse the WordSet instead of the original Words list to generate the first random word:Word1 := RandWord(WordSet); # givenThe key step is to remove Word1 from the WordSet before we generate the next random word:WordSet := WordSet minus {Word1}; # givenIf we use the updated WordSet to generate the next random word, the result is guaranteed to be different than the first random word:Word2 := RandWord(WordSet); # givenCopy your Madlib procedure from Problem 5(b) and paste it below. Modify Madlib so that it uses the technique demonstrated above to guarantee that all of the randomly generated adjectives, nouns, and verbs are unique. To accomplish this, you will need to make the following changes to Madlib:1. Add the variables AdjectiveSet, NounSet, and VerbSet to the local variables in Madlib.2. In the body of procedure Madlib, convert the lists of Adjectives, Nouns, and Verbs into the corresponding sets AdjectiveSet, NounSet, and VerbSet.3. After you generate each random adjective, noun, or verb, remove it from the corresponding set of words before you generate the next random word of the same type.4. Remember to pass the updated set of words rather than the original list of words as input to procedure RandWord.Now test your new-and-improved procedure Madlib by calling it -- for input, use the three lists of Adjectives, Nouns, and Verbs which you defined earlier:Finally, put your procedure call to Madlib inside a for loop to generate 5 different madlibs:If you have solved this problem correctly, none of your madlibs will contain any duplicate random words.