<Text-field style="Heading 1" layout="Heading 1">Title: An Introduction to Applying Mathematics with Maple</Text-field>
<Text-field style="Heading 2" layout="Heading 2">Author</Text-field>Professor Kenneth ShiskowskiDepartment of MathematicsEastern Michigan UniversityYpsilanti, Mi. 48198
<Text-field style="Heading 1" layout="Heading 1">Introduction</Text-field>This notebook will give an introduction to the programming of mathematics with Maple to the novice user of the mathematical software Maple. The basic features of Maple will be covered. These features include algebra operations on polynomials and rational functions, defining expressions versus functions and their uses, plots of all kinds, creating and manipulating lists, sets, strings, and matrices as well as solving equations and systems of equations. Some interesting applications to financial applications involving savings accounts and loans are also discussed along with an introduction to basic statistics.Also, we will look at all types of graphing (plotting) along with basic Calculus topics such as differentiation, integration, Taylor polynomials, and differential equations. The last topic of our discussion will be recursion for generating sequences such as in Newton's method for approximately solving an equation, and the use of procedures for defining functions of several variables as a Maple program.
<Text-field style="Heading 1" layout="Heading 1">Basic Information</Text-field>Maple is a very sophisticated mathematical software package which allows you to combine text and color graphics with mathematical calculations which are either symbolic or computational.You have already seen a major feature of Maple in the cell (or execution group) structure it has as indicated by the vertical brackets on the left of your screen. Each cell style is essentially of one of three basic types: Input, Output, or Text although a full list of the possibilities can be found by looking under the menu headed P Normal at the top left of your screen. P Normal is the cell style you are reading now. The default styles of each style of cell can be set by using Styles under the menu Format at the top of your screen.An Input cell is one in which all Maple commands are to be placed for Maple to carry out. All the commands placed in a single Input cell will be carried out in the order they are given when the cell is activated. An Input cell is activated by placing the cursor anywhere in the cell and then hitting ENTER. Each command in an Input cell must be preceeded by the prompt > which can be gotten when a new Input cell is created or by using Maple Input under the Insert menu (or Ctrl m).The creation of a new Input cell can be done by placing the cursor at the end of the last line of a cell and then clicking with the mouse on the button [> at the top of your screen below and between the menus Format and Options. This produces an Input cell immediately after the cell in which your cursor was placed. An Input cell can also be placed using the Execution Group commands under the Insert menu.An Output cell is created when an Input cell's commands are carried out if you wish the result of this command displayed apart from its Input cell - otherwise the displayed output is part of your Input cell.If you wish to create an Input cell, then hit the button [> in the top menu of the screen. The button T will create a Text cell. In order to delete any Maple cell or Element, go to Edit above and use Delete Element or equivalently use Ctrl+Delete. Under Insert above you have the commands for creating new sections and subsections which are indicated by triangles as well as for placing new Execution Groups or Paragraphs in cells before or after the cursor. Each command in an Input cell must end in a colon : or semi-colon ;. The colon ending indicates that the output of the command is to be suppressed and not displayed while the semi-colon indicates it is to be displayed. You will have to decide through use when you prefer to use these two types of command endings. I suggest in the beginning to use the semi-colon for all your endings until you have some experience. When you have the cursor on a particular command line, then it will also appear at the top of your screen for your convenience.I have set in Style the color of an Input command as red and Output text as blue while you should have noticed that my section titles are P Bullet Item in the color green. You can set your own color scheme through Style if you prefer a different system. I suggest that you experiment with all of these possibilities to gain facility controlling them as well as seeing what you like best.In order to copy all or part of a cell darken the region desired with the mouse and type Ctrl c while to paste it in somewhere type Ctrl v. In order to delete all or part of a cell darken the region desired and type Ctrl x or hit the Backspace key. The usual word processing commands apply as indicated by these examples - a new paragraph can be created using the Paragraph under the Insert menu or by hitting the Enter key.
The percent symbol % can be used to indicate the previous output of a command and %% is the output of two commands back while the asterisk * indicates multiplication and must always be used. Multiplication in Maple must be explicitly stated since it will not be assumed through context or a space.
If a command is too long to fit on a single line, then Maple will move to a new line to finish it. You can not break a line in the middle of a command structure head (or title) such as the name of a command. As an example, you should not break a line in the middle of the command name spacecurve(...) which gives a 3d curve plot except after spacecurve(.
It is advisable to save your work frequently as you go since Maple can freeze up occasionally causing potential lose of your work. If you wish to terminate a command while Maple is working, then hit the STOP button at the top of the screen which should be in red when a computation is running.The restart command is very useful if you wish to start over in a notebook file since it deletes all previous work from memory while leaving all of the previous inputs and outputs in place on the screen and your file.
<Text-field style="Heading 1" layout="Heading 1">Algebraic and Arithmetic Operations</Text-field>In this section we are interested in working with the algebra of rational functions (quotients of polynomials) and polynomials with real or complex coefficients. We will review the algebra of polynomials such as multiplication, division, expanding, and factoring.
We also can find the greatest common divisor gcd and least common multiple lcm of two polynomials which can be factored over the integers. The lcm is the product of the polynomials divided by their gcd.
The arithmetic operations this section will discuss are sum and product for a list of numbers or polynomials as well as how to approximate such sums and products.
The command to multiply a product of any number of polynomials is expand(product of polynomials). The command to factor a polynomial is factor(polynomial). Factor will only factor an integer coefficient polynomial if it will factor into a product of other integer coefficient polynomials.A polynomial p is defined below as an expression (not a function) in the variable x. The := is the assignment command and it is global so that in your Maple session p will always be this polynomial. If you want to change p, then do so to it directly and hit ENTER to have p changed to your new polynomial.p := (x-5)^3*(x-4)^2;subs(x = Pi, p);evalf(%);expand(p);factor(%);factor(x^2 - 5*x - 7);q := (5*x + 3*y - 2*z)^4:expand(q);factor(%);gcd((x+3)^2*(x-5)^4*(x+2)^7, (x+1)*(x-5)^8*(x+2)^5);lcm((x+3)^2*(x-5)^4*(x+2)^7, (x+1)*(x-5)^8*(x+2)^5);The command quo(numerator, denominator, x, 'r') will carry out the division giving the quotient while storing the remainder of the division as r. Also, rem(numerator, denominator, x, 'q') will carry out the division giving the remainder while storing the quotient of the division as q.
The command simplify(quotient of two polynomials) will divide the denominator into the numerator when the numerator is a multiple of the denominator (the remainder of the division is 0.)simplify((x^3 - 27)/(x - 3));simplify((x^3 - 15)/(x - 3));q := quo(x^3 - 15, x - 3, x, 'r');r;simplify((x - 3)*q + r);rem(x^3 - 15, x - 3, x, 'q');q;JSFHFind the quotient and remainder of dividing LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYxLUkjbW5HRiQ2JVEiNkYnLyUsbWF0aHZhcmlhbnRHUSVib2xkRicvJStmb250d2VpZ2h0R0YxLUkjbW9HRiQ2LlEifkYnRi9GMi8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGOi8lKXN0cmV0Y2h5R0Y6LyUqc3ltbWV0cmljR0Y6LyUobGFyZ2VvcEdGOi8lLm1vdmFibGVsaW1pdHNHRjovJSdhY2NlbnRHRjovJSdsc3BhY2VHUSYwLjBlbUYnLyU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ZnRHUSIwRictRiw2LlEiK0YnRi9GMkY0RjdGOUY7Rj1GP0ZBRkNGRi1GSTYlUSIzRidGL0YyRkxGVS1GLDYuUSgmbWludXM7RidGL0YyRjRGN0Y5RjtGPUY/RkFGQ0ZGLUZJNiVRIjFGJ0YvRjJGXW9GX28=.The command simplify(Sums of quotients of polynomials) will combine such a sum into a single quotient as will the command combine. The command combine(Any algebraic and/or trignometric expression, option) will try to rewrite the quantity in as simple a form as its simplification rules can find using the option list of rules. The option trig is a list of trignometric identities.simplify((x^2 - 9)/(x-3) + (x^2 - 4)/x);simplify((x^2 - 9)/(x-3));simplify((x^2 - 4)/x);combine(sin(2*x)^3, trig);In order to find a sum or product of a list or string of numbers or polynomials, you first must "create" the list or string and then use the commands sum or product to do the rest. The sum and product commands will simultaneously create and add or multiply the results while the command seq will only create a string of numerical values or expressions. Also, look into the commands add and multiply which are similar to the commands sum and product but are used to merely carry out these two operations in non-abstract situations.
In order to get an approximate value for a quantity, use the command evalf(Quantity, # of digits of accuracy). If the quantity is a list or string, then this command approximates each element of the list or string. The default number of digits of accuracy to be displayed and used by Maple is 10 which you can reset using the Digits := # command.
seq(x^j/2^j, j = 0..3);evalf(%,4);evalf(seq(Pi^i, i = -1..2), 5);add(k^2, k = 1..6);sum(k^2, k = 1..N);sum(1/3^k, k = 0..N);add((2^k/k!)*x^k, k = 2..7);evalf(%);product(2^j/j!, j = 4..9);evalf(%); Now let's look at some examples involving the arithmetic of complex numbers.
u:= 7-3*I:w:= -2+8*I:u*w;u/w;comjugate(u);Re(u);Im(u);abs(u);evalf(ln(w));exp(%);polar(u);argument(u);evalf(%);abs(u)*exp(argument(u)*I);JSFH
<Text-field style="Heading 1" layout="Heading 1">Expressions versus Functions</Text-field>This section will indicate how functions f(x) versus expressions f can be defined and their graphs plotted. We will also see how you can plot several functions or expressions simultaneously each of which is in a different color. You also can change the plot's range if you wish or have it determined by Maple.A plot can be made larger or smaller on the screen by clicking the mouse when the cursor is over the square in the lower righthand corner of the plot window and dragging the cursor with the mouse. The coordinates of a point in the plot window can be found approximately by clicking the mouse when the cursor is over the point. The point's coordinates will appear at the top of the plot window.An expression f in a variable x is merely a string of symbols where the only undefined variable or symbol is x. A function f is a rule f(x) in the variable x where x can be given values to evaluate the rule. The idea of expression versus function is not interchangeable although one can be converted into the other. Each has its uses as we shall see which determine when one is preferred over the other.In defining a function called f with variable x you must say that the rule of f is given by the command
f := x -> its rule
where this rule can be any expression involving the variable x and the x -> is used to tell Maple that x is f's variable which can be replaced by any quantity.In order to evaluate the function f(x) at x = a give the command f(a) while to evaluate the expression g having the variable x give the command subs(x=a, g). You can also use the subs command to change an expression into a function as the example of v(w) below illustrates or you can use the unapply command. (Note that the exponential function base e is abbreviated in Maple by exp.)u := x*sin(x):subs(x = Pi/3, u);evalf(%);v:= w -> evalf(subs(x=w,u)):v(Pi/3);z:= exp(cos(x)):h:= unapply(z, x):h(Pi);f := x -> 4*cos(x);g := x -> sin(x);g(Pi/4);plot({f(x), g(x), u}, x = 0..2*Pi);plot([f(x), v(x)], x = 0..2*Pi, y = -.5...8);Now try plotting the functions cos(2*x) and sin(3*x) with the expression cos(x/2) on the interval [0, 2*Pi]. Also, insert in this plot the title "3 Trig Funcs" by looking up in Help the plot option you need.Note that in the first plot command above the parentheses { } enclose a set while the brackets [ ] enclose a list. Maple will plot lists and sets of functions and/or expressions simultaneously.
<Text-field style="Heading 1" layout="Heading 1">Financial Applications</Text-field>This section of the introduction to Maple is for business and/or economics students who might wish to use Maple to solve financial problems involving savings accounts, loans, effective interest rates, and related topics. You should also see Maple's Finance package after reading this section for further features of Maple related to our topics. The types of basic financial problems we will solve all involve the need to solve algebraic equations which we could do by hand or as in our case have Maple do for us. Let's start with savings accounts. We will assume for simplicity that an account is opened with a principal P and we will make no further deposits or withdrawals into the account. We want a formula for the balance B in the account at the end of T years if it has a yearly interest rate of R%. In the following balance formulas, R is not a percent but the decimal equivalent, that is, 5% becomes .05. The three types of accounts which we will examine are simple, compound, and continuous interest accounts. A simple interest account is one in which interest is added to the principal at the end of each year (or proportionally if not an integer number of years), but no interest accrues on interest. The balance formula in this case is B = P*(1 + R*T).In a compound interest account, interest accrues on interest N times per year evenly spaced throughout the year at an interest rate of LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYlLUkmbWZyYWNHRiQ2KC1JI21pR0YkNiZRIlJGJy8lJ2l0YWxpY0dRJXRydWVGJy8lLG1hdGh2YXJpYW50R1EsYm9sZC1pdGFsaWNGJy8lK2ZvbnR3ZWlnaHRHUSVib2xkRictRiM2JS1GLzYmUSJORidGMkY1RjgvJSVib2xkR1EmZmFsc2VGJy9GNlEnbm9ybWFsRicvJS5saW5ldGhpY2tuZXNzR1EiMUYnLyUrZGVub21hbGlnbkdRJ2NlbnRlckYnLyUpbnVtYWxpZ25HRkovJSliZXZlbGxlZEdGQkZARkM= % each compounding period. The balance formula in this case isLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUkjbWlHRiQ2JlEiQkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JI21vR0YkNi5RIj1GJy9GM0Y3RjUvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj8vJSlzdHJldGNoeUdGPy8lKnN5bW1ldHJpY0dGPy8lKGxhcmdlb3BHRj8vJS5tb3ZhYmxlbGltaXRzR0Y/LyUnYWNjZW50R0Y/LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTi1GLDYmUSJQRidGL0YyRjUtRjk2LlEnJnNkb3Q7RidGPEY1Rj1GQEZCRkRGRkZIRkovRk1RJjAuMGVtRicvRlBGWC1JJW1zdXBHRiQ2JS1JKG1mZW5jZWRHRiQ2JS1GIzYnLUkjbW5HRiQ2JVEiMUYnRjxGNS1GOTYuUSIrRidGPEY1Rj1GQEZCRkRGRkZIRkovRk1RLDAuMjIyMjIyMmVtRicvRlBGZG8tSSZtZnJhY0dGJDYoLUYsNiZRIlJGJ0YvRjJGNS1GIzYlLUYsNiZRIk5GJ0YvRjJGNS8lJWJvbGRHRj8vRjNRJ25vcm1hbEYnLyUubGluZXRoaWNrbmVzc0dGX28vJStkZW5vbWFsaWduR1EnY2VudGVyRicvJSludW1hbGlnbkdGaXAvJSliZXZlbGxlZEdGP0ZhcEZjcEY8RjUtRiM2JS1GaG42JS1GIzYnRl5wRlQtRiw2JlEiVEYnRi9GMkY1RmFwRmNwRjxGNUZhcEZjcC8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRidGYXBGY3A=.In a continuous interest account, interest accrues on interest at each moment the account is open. The balance formula in this case isLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUkjbWlHRiQ2JlEiQkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JI21vR0YkNi5RIj1GJy9GM0Y3RjUvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj8vJSlzdHJldGNoeUdGPy8lKnN5bW1ldHJpY0dGPy8lKGxhcmdlb3BHRj8vJS5tb3ZhYmxlbGltaXRzR0Y/LyUnYWNjZW50R0Y/LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTi1GLDYmUSJQRidGL0YyRjUtRjk2LlEnJnNkb3Q7RidGPEY1Rj1GQEZCRkRGRkZIRkovRk1RJjAuMGVtRicvRlBGWC1JJW1zdXBHRiQ2JS1GLDYmUSJlRidGL0YyRjUtRiM2JS1JKG1mZW5jZWRHRiQ2JS1GIzYnLUYsNiZRIlJGJ0YvRjJGNUZULUYsNiZRIlRGJ0YvRjJGNS8lJWJvbGRHRj8vRjNRJ25vcm1hbEYnRjxGNUZnb0Zpby8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRidGZ29GaW8=.In this formula, e is the usual constant with value approximately 2.718.Let's now see Maple in action solving some problems.As a first example, let's find how long it will take for a compound interest account opened with $2,000 to increase by 70% in value if it is compounded monthly at 4.61% annual interest. The answer that the following computation gives is a time T = 11.53 years. compeqn:= B = P*(1+R/N)^(N*T):P:= 2000:R:= .0461:N:= 12:B:= 1.7*2000:compeqn;fsolve(compeqn, T);This problem was easy for Maple to solve while by hand it would have taken algebra involving logarithms.As another problem, say that we have $15,000 to invest in a certificate of deposit. We want to know what yearly interest rate would be needed compounded quarterly for this amount to double in 10 years. The command R:= 'R' below resets the symbol R to a variable instead of the value of .0461 we previously assigned it. The answer Maple gives is essentially 7% where fsolve searches for the value of R between 0 and 0.2 or 20%. P:= 15000:T:= 10:N:= 4.:B:= 30000:R:= 'R':compeqn;fsolve(compeqn, R, 0..0.2);These last examples have involved compound interest situations. Now let's look at one with a continuous interest account. A plot of land is purchased for $25,000. It's value is depreciating as a continuous interest account. How long will it take for its value to reach $22,000 at a yearly depreciation rate of 5.35%? The notation exp is for the exponential function base e. (We will a negative interest rate to indicate depreciation while positive interest rates indicate appreciation.) Maple says it will take T = 2.39 years for this to happen.R:= -.0535:T:= 'T':P:= 25000:B:= 22000:conteqn:= B = P*exp(R*T):conteqn;fsolve(conteqn, T);Now we switch to a new topic - effective yearly interest rates. The effective yearly interest rate E for an account is the simple interest rate needed to make your account equivalent to a simple interest account for the first year your account is open. Effective interest rates are what banks and mortgage companies use to compare different accounts. The account with the highest effective interest rate is the best one in the comparison.Let's have Maple find the formulas for the effective yearly interest rates E compound and continuous accounts. The time T used for this computation is one year. P:= 'P':N:= 'N':R:= 'R':E:= solve(P*(1+E) = P*(1+R/N)^N, E);This says that the effective interest rate E for a compound interest account isLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUkjbWlHRiQ2JlEiRUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JI21vR0YkNi5RIj1GJy9GM0Y3RjUvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj8vJSlzdHJldGNoeUdGPy8lKnN5bW1ldHJpY0dGPy8lKGxhcmdlb3BHRj8vJS5tb3ZhYmxlbGltaXRzR0Y/LyUnYWNjZW50R0Y/LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTi1JJW1zdXBHRiQ2JS1JKG1mZW5jZWRHRiQ2JS1GIzYnLUkjbW5HRiQ2JVEiMUYnRjxGNS1GOTYuUSIrRidGPEY1Rj1GQEZCRkRGRkZIRkovRk1RLDAuMjIyMjIyMmVtRicvRlBGW28tSSZtZnJhY0dGJDYoLUYsNiZRIlJGJ0YvRjJGNS1GIzYlLUYsNiZRIk5GJ0YvRjJGNS8lJWJvbGRHRj8vRjNRJ25vcm1hbEYnLyUubGluZXRoaWNrbmVzc0dGZm4vJStkZW5vbWFsaWduR1EnY2VudGVyRicvJSludW1hbGlnbkdGYHAvJSliZXZlbGxlZEdGP0Zob0Zqb0Y8RjVGY28vJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnLUY5Ni5RKCZtaW51cztGJ0Y8RjVGPUZARkJGREZGRkhGSkZqbkZcb0ZZRmhvRmpv.We now want it for a continuous account. E:= 'E':E:= solve(P*(1+E) = P*exp(R), E);This says that the effective interest rate R for a continuous interest account isLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUkjbWlHRiQ2JlEiRUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JI21vR0YkNi5RIj1GJy9GM0Y3RjUvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj8vJSlzdHJldGNoeUdGPy8lKnN5bW1ldHJpY0dGPy8lKGxhcmdlb3BHRj8vJS5tb3ZhYmxlbGltaXRzR0Y/LyUnYWNjZW50R0Y/LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTi1JJW1zdXBHRiQ2JS1GLDYmUSJlRidGL0YyRjUtRiM2JS1GLDYmUSJSRidGL0YyRjUvJSVib2xkR0Y/L0YzUSdub3JtYWxGJy8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRictRjk2LlEoJm1pbnVzO0YnRjxGNUY9RkBGQkZERkZGSEZKL0ZNUSwwLjIyMjIyMjJlbUYnL0ZQRmFvLUkjbW5HRiQ2JVEiMUYnRjxGNUZmbkZobg==.We now want to use these formulas to compare two different accounts. Which account is better - a compound interest account compounded semiannually at yearly interest of 7.82% or a continuous account at yearly interest of 7.79%? Econt:= exp(.0779) - 1;Ecomp:= (1 + .0782/2)^2 - 1;The better account is accordingly the continuous account by an appreciable amount since their effective interest rates are .13% apart versus .03% apart in the actual accounts.It should be clear that the effective interest rate is a needed measure to compare accounts mainly when they are of distinctly different types as above or when a large amount of money is involved so that even small differences really matter.Our last topic of this section is that of loans based on compound interest accounts. We will assume that a loan with a principal of P is to be taken out for a fixed period of T years at a yearly interest rate of R% compounded N times per year. Now a formula giving the monthly loan payment amount L is needed. The details of how this formula is found will not be given here, only the formula itself. This formula isLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzZqby1JI21vR0YkNj9RIn5GJy8lJ2ZhbWlseUdRMFRpbWVzfk5ld35Sb21hbkYnLyUlc2l6ZUdRIzEyRicvJSVib2xkR1EmZmFsc2VGJy8lJ2l0YWxpY0dGNy8lK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xGTkZQRlJGVEZWRllGX3EtRmlxNjYtRiM2OEZlcS1GLDY/USgmbWludXM7RidGL0YyRjVGOEY6RjxGPkZARkNGRkZIRkpGTEZORlBGUkZURlZGWUZmbkZobkZqbkZcb0Zeb0Zgb0Zib0ZkckZmckZdckYvRjJGNUY4RjpGPEY+RkBGQ0ZGRkhGSkZMRk5GUEZSRlRGVkZZRi9GMkY1RjhGOkY8Rj5GQEZDRkZGSEZKRkxGTkZQRlJGVEZWRllGL0YyRjVGOEY6RjxGPkZARkNGRkZIRkpGTEZORlBGUkZURlZGWUZjdEYvRjJGNUY4RjpGPEY+RkBGQ0ZGRkhGSkZMRk5GUEZSRlRGVkZZRmBzRmJzRmVzRmdzRkBGQ0YvRjJGNUY4RjpGPEY+RkBGQ0ZGRkhGSkZMRk5GUEZSRlRGVkZZ .As an example of using this formula, let us now find the yearly interest rate R needed to pay on a home loan of $109,000 in equal monthly payments of $750 compounded monthly over 30 years. The value we will find is R = 7.34%. R:='R':L:= 750:P:= 109000:T:= 30:N:= 12:loaneqn := (12.*((1+R/N)^(N*T)-1))*L = P*R*(1+R/N)^(N*T):loaneqn;fsolve(loaneqn, R, 0.01 ..0.2);eval(subs(R = .0734, loaneqn));In this case, Maple is unable to use solve or fsolve to find the solution value of R if we leave the loan equation as it is originally written. Instead, we could graph the two functions which are the two sides of this original loan equation and find that their intersection point is at approximately R = .07. Then by plugging values of R near this into the loaneqn using the command subs we get R accurate to 4 decimal places.plot({12.*L, P*R*(1 + R/N)^(N*T)/((1 + R/N)^(N*T) - 1)}, R = .01..0.10);
<Text-field style="Heading 1" layout="Heading 1">More Examples of Plotting Types</Text-field>In this section we will look at plotting more advanced situations than the expressions and functions of the last section. Now we will plot implicitly defined curves and surfaces as well as parametric curves and surfaces. Let's start with implicit curve plotting which will plot curves in the xy-plane which are the sets of points (x, y) satisfying an equation in the variables x and y followed by implicit surface plotting which plots surfaces in space which are the sets of points (x, y, z) satisfying an equation in the three variables.. In order to use the commands implicitplot or implicitplot3d you will need to first load the plots library using the command with(plots). with(plots):p:= (x-3)^2/36 + (y+5)^2/100 = 1:implicitplot(p, x=-3..9, y=-15..5, scaling = constrained, color = blue);implicitplot({x^2 + y^2 = 100, p}, x=-10..10, y=-15..10, scaling = constrained);implicitplot3d(x^2 + y^2 + z^2 = 25, x=-5..5, y=-5..5, z=-5..5, axes = boxed);JSFHThe option scaling = constrained is used so that the graphs are drawn to scale so that ellipses will look elliptical instead of circular. The option color = blue is given since otherwise the default color is red.Now implicit plot the equation LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYtLUklbXN1cEdGJDYlLUkobWZlbmNlZEdGJDYlLUYjNictSSNtaUdGJDYmUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRLGJvbGQtaXRhbGljRicvJStmb250d2VpZ2h0R1ElYm9sZEYnLUkjbW9HRiQ2LlEiK0YnL0Y7Rj9GPS8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGRy8lKXN0cmV0Y2h5R0ZHLyUqc3ltbWV0cmljR0ZHLyUobGFyZ2VvcEdGRy8lLm1vdmFibGVsaW1pdHNHRkcvJSdhY2NlbnRHRkcvJSdsc3BhY2VHUSwwLjIyMjIyMjJlbUYnLyUncnNwYWNlR0ZWLUkjbW5HRiQ2JVEiNEYnRkRGPS8lJWJvbGRHRkcvRjtRJ25vcm1hbEYnRkRGPS1GIzYlLUZaNiVRIjJGJ0ZERj1GZ25GaW4vJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnRkAtRiw2JS1GLzYlLUYjNictRjQ2JlEieUYnRjdGOkY9LUZBNi5RKCZtaW51cztGJ0ZERj1GRUZIRkpGTEZORlBGUkZURlctRlo2JVEiMUYnRkRGPUZnbkZpbkZERj1GW29GYG8tRkE2LlEiPUYnRkRGPUZFRkhGSkZMRk5GUEZSL0ZVUSwwLjI3Nzc3NzhlbUYnL0ZYRmZwLUZaNiVRIjVGJ0ZERj0tRkE2LlEnJnNkb3Q7RidGREY9RkVGSEZKRkxGTkZQRlIvRlVRJjAuMGVtRicvRlhGX3FGM0ZbcUZpb0ZnbkZpbg== in color green to scale followed by the surface LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYpLUklbXN1cEdGJDYlLUkobWZlbmNlZEdGJDYlLUYjNictSSNtaUdGJDYmUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRLGJvbGQtaXRhbGljRicvJStmb250d2VpZ2h0R1ElYm9sZEYnLUkjbW9HRiQ2LlEoJm1pbnVzO0YnL0Y7Rj9GPS8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGRy8lKXN0cmV0Y2h5R0ZHLyUqc3ltbWV0cmljR0ZHLyUobGFyZ2VvcEdGRy8lLm1vdmFibGVsaW1pdHNHRkcvJSdhY2NlbnRHRkcvJSdsc3BhY2VHUSwwLjIyMjIyMjJlbUYnLyUncnNwYWNlR0ZWLUkjbW5HRiQ2JVEiM0YnRkRGPS8lJWJvbGRHRkcvRjtRJ25vcm1hbEYnRkRGPS1GIzYlLUZaNiVRIjJGJ0ZERj1GZ25GaW4vJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnLUZBNi5RIitGJ0ZERj1GRUZIRkpGTEZORlBGUkZURlctRiw2JS1GLzYlLUYjNictRjQ2JlEiekYnRjdGOkY9RmNvLUZaNiVRIjVGJ0ZERj1GZ25GaW5GREY9RltvRmBvLUZBNi5RIj1GJ0ZERj1GRUZIRkpGTEZORlBGUi9GVVEsMC4yNzc3Nzc4ZW1GJy9GWEZmcC1GWjYlUSMxNkYnRkRGPUZnbkZpbg==. Also try an example of plotting two surfaces together.Now let's move on to parametric curve and surface plotting. A parametric curve in the xy-plane is given by two functions x = f(t) and y = g(t) of a parameter(variable) t which determine the x,y location of points on the curve as t (thought of as time) changes. You must also give an interval [a,b] for the time t to progress over with t = a the starting time and t = b the stopping time.plot([5 + 2*cos(t), -3 + 2*sin(t), t=0..2*Pi], x=3..7, y=-5..-1);p1:= plot([5 + 2*cos(t), -3 + 2*sin(t),t=0..2*Pi], x=-10..10, y=-10..10, color = blue):p2:= plot([-1 + 5*sin(t), 1 + 8*cos(t), t=0..2*Pi], x=-10..10, y=-10..10, color = green):display({p1,p2}, scaling = constrained);JSFHYou now can try plotting parametrically simultaneously the two circles with centers at (4,-9) and (-1,-3) with respective radii of 8 and 5 in two different colors.Now we can move to plotting parametric curves in space using the spacecurve command from the plots library. The numpoints option allows you to set the number of points plotted. This should be set relatively high for a complicated curve in space or even the plane.spacecurve([3*cos(2*t) - sin(t), 5*sin(t) + 12*cos(t), 2*cos(t) - 10*sin(3*t)], t=0..2*Pi, numpoints = 150, axes = boxed);c1:= spacecurve([3*cos(t), 3*sin(t), t], t=0..4*Pi, color = red):c2:= spacecurve([t, 2*sin(t), 5*cos(t)], t=0..8*Pi, color = blue):display({c1,c2}, axes = boxed);spacecurve([4*cos(t), 7*sin(t), cos(t)^2], t=0..8*Pi, color = blue, axes = boxed, numpoints = 300);JSFHOur last topic of this section is plotting parametric surfaces. The best format for giving and manipulating a surface is the parametric format. plot3d([3*cos(u)*cos(v), 3*sin(u)*cos(v), 3*sin(v)], u=0..2*Pi, v=0..2*Pi, axes = boxed);s1:= plot3d([3*cos(u)*cos(v), 3*sin(u)*cos(v), 3*sin(v)], u=0..2*Pi, v=0..2*Pi):s2:= plot3d([2*cos(u), v, 2*sin(u)], u=0..2*Pi, v=-6..6):display3d({s1,s2}, axes = boxed);JSFHThese examples of plotting curves and surfaces should illustrate some of the capabilities of the plot structures in Maple. You should now try to do some 2D and 3D animations by looking at some examples from the HELP menu.
<Text-field style="Heading 1" layout="Heading 1">Array Types:Lists through Matrices</Text-field>This part of our notebook will show you how to create and manipulate lists, sets, strings, arrays, vectors, and matrices. A list is an ordered collection of objects enclosed in square brackets [ ] with commas separating its elements where the elements may repeat. A set is an unordered collection of objects enclosed in parentheses { } with commas separating its elements where no two elements may be the same. A sequence is a string of objects without the enclosing brackets. The seq command is a common way to create sequences (or strings) which can then be changed into lists or sets by enclosing the string in the appropriate brackets [ ] or { }. The elements of our lists, sets, or sequences will usually be expressions, real or complex numbers, or points in the xy-plane or space.
If you want the quantity in the Kth place in the list or set named pts, then use the command pts[K]. In order to change a sequence called points into a list or set, you merely need to enclose its name points in brackets to get a list or parentheses for a set. The op command will convert a list or set into a sequence while the nops command gives the number of elements in a set or list. I suggest that if you are dealing with a large sequence that it is best to make it into a list instead of a set if you need to since when a set is created Maple will check it for duplicate elements which is time and memory consuming as well as usually not needed for the job you have in mind. pol1:= seq(j^2*x^j, j=-3..2);pol2:= seq(j*x^j, j=0..5);listpol:= [pol1];listpol[2];op(listpol);setpol:= {pol2};nops(setpol);[op(setpol),op(listpol)];setpol union {op(listpol)};JSFHAn array is a table of objects of a positive number of dimensions. Then a 1-dimensional array is a vector while a 2-dimensional array is a matrix. Higher dimensional arrays might be called tensors for those of you who have heard of them. Essentially, an array is a version of a list for a 1-dimensional array or list of lists for a 2-dimensional array.If you want the quantity in the Rth row and Cth column in the matrix named mat, then use the command mat[R, C] while you can use mat[R] for the Rth row of the matrix mat. If you have a vector V, then its ith component is V[i].The multiplication of the matrices mat1 times mat2 in this order can be performed by the command evalm(mat1 &* mat2) where the command evalm will tell Maple to evaluate a matrix operation. The commands det and inverse as ^(-1) are hopefully obvious and apply only to square matrices. The command with(linalg): will load the linear algebra package which contains the commands matrix, det, and many others. Maple also has a second linear algebra library of commands called LinearAlgebra.with(linalg):vec := array(1..3, [-7,4,-5]);vec1 := array(1..1,1..3,[[-7,4,-5]]);vec2 := matrix(1,3,[[-7,4,-5]]);vec3 := matrix(3,1,[[-7],[4],[-5]]);evalm(vec2 &* vec3);evalm(vec3 &* vec2);det(%);mat := [seq([seq(cos(r)/c!, c = 1..3)], r = 1..3)];mat1 := evalf(matrix(3, 3, mat));evalm(mat1^(-1));det(%);JSFHIn the above commands, vec is a vector or 1-dimensional array of length 3 while vec1 is a row matrix, vec2 is the same, and vec3 is a column matrix.The list of lists called mat is not a matrix until we use the command matrix on it calling the result the 3 x 3 matrix mat1. An easier way to create the matrix mat1 is given next as the matrix mat2.
mat2 := matrix(3, 3, (r, c) -> cos(r)/c!);mat[2];mat[2][3];mat2[3, 3];mat3 := matrix(3, 3, (r, c) -> r/2^c);evalm(mat2 &* mat3 + diag(1, 1, 1));evalm(evalf(%)^(-1));mat4 := array([[a, b], [c, d]]);det(%);JSFHAs an example, find the 3rd row of the inverse of the product of the two matrices mat1(r, c) = c/r! which is 3 by 4 times mat2(r, c) = r/c^2 which is 4 by 3.
<Text-field style="Heading 1" layout="Heading 1">Basic Probability, Statistics and Regression</Text-field>This section will introduce some basic concepts in statistics such as mean, standard deviation, histograms and scatter plots, linear regression or fit, random numbers, and the normal distribution. These are only a few of the most common and useful elementary topics in statistics, but they will give us a good intoduction to statistics and the stats package in Maple.All of these topics appear in the stats package of Maple and within one of its subpackages - describe, fit, random, and statplots. The describe subpackage contains the mean, standard deviation, and normal distribution. Histograms and scatter plots are in the statplots subpackage while fit contains linear regression and random produces random numbers of different characteristics. The normal distribution will be discussed by the use of its defining function instead of through a Maple package. We will begin with finding the arithmetic mean or average M and (sample versus population) standard deviation S (or sigma) for a frequency (or weighted) distribution (or table or list) for a set of collected data (called a sample). Let's illustrate what we have in mind with an example. A state administers drivers' tests each weekday. We assume that a test contains 15 multiple choice questions which on a particular day was given to 1388 people. The scores on this test range from 0 to 15 indicating the number of correct answers. We are told that 18 people got score 0, 35 people got score 1, 51 people got score 2, 74 people got score 3, 85 people got score 4, 102 people got score 5, 136 people got score 6, 150 people got score 7, 173 people got score 8, 194 people got score 9, 126 people got score 10, 87 people got score 11, 60 people got score 12, 49 people got score 13, 32 people got score 14, and 16 people got score 15. The number of people who received a particular score is the score's frequency or weight. The size of this day's sample of data is 1388 which is the sum of our frequencies. The following sum will check that the sample size is correct at 1388. 18+35+51+74+85+102+136+150+173+194+126+87+60+49+32+16;We now store this sample data to the following list called scores.scor:= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]:freq:= [18,35,51,74,85,102,136,150,173,194,126,87,60,49,32,16]:add(i, i = freq);with(stats, describe):scores:= [seq(Weight(scor[j],freq[j]), j=1..16)];M:= describe[mean](scores);evalf(%);As a check that this is the correct average or mean, let's do it directly. This means we add up all 1388 scores and divide by the number of them, 1388.(18*0+35*1+51*2+74*3+85*4+102*5+136*6+150*7+173*8+194*9+126*10+87*11+60*12+49*13+32*14+16*15)/1388;add(scor[j]*freq[j], j=1..16)/1388;Now we want to compute the two standard deviations for this data - sample and population. The population standard deviation SP is defined to be the square root of the mean of the square of the deviations from the mean. This means that the population standard deviation SP is approximately the average dispersion of the data about the mean M.The sample standard deviation SS is defined to be the square root of the "mean" of the square of the deviations from the mean. By "mean", it is meant that in this average we divide by the sample size minus one, 1387, instead of the sample size of 1388. This is done to try to make the sample standard deviation SS more closely approximate the population standard deviation SP for small sample size. SP:= describe[standarddeviation[0]](scores);evalf(%);SS:= describe[standarddeviation[1]](scores);evalf(%);Note that in our case both standard deviations are quite close since the sample size of 1388 is not small. Let's check these directly with SP first.sqrt(add(freq[j]*(M-scor[j])^2, j=1..16)/1388);evalf(%);sqrt((18*(M-0)^2+35*(M-1)^2+51*(M-2)^2+74*(M-3)^2+85*(M-4)^2+102*(M-5)^2+136*(M-6)^2+150*(M-7)^2+173*(M-8)^2+194*(M-9)^2+126*(M-10)^2+87*(M-11)^2+60*(M-12)^2+49*(M-13)^2+32*(M-14)^2+16*(M-15)^2)/1388);sqrt((18*(M-0)^2+35*(M-1)^2+51*(M-2)^2+74*(M-3)^2+85*(M-4)^2+102*(M-5)^2+136*(M-6)^2+150*(M-7)^2+173*(M-8)^2+194*(M-9)^2+126*(M-10)^2+87*(M-11)^2+60*(M-12)^2+49*(M-13)^2+32*(M-14)^2+16*(M-15)^2)/1387);Both of our checks agree with the Maple computed values.Before we continue, let me now mention how to use a table or array to display and store the sample data in scores list.with(linalg):scoretable:= array(1..17,1..2,[[test_scores,frequency], seq([scor[j],freq[j]], j=1..16)]);This array or table format allows you to both store and display your data in a convenient way to scan it for errors.The type of data examined so far is called ungrouped or non-interval data since each individual outcome of the test is accounted for. The data type is called grouped or interval data if in place of individual outcomes we have intervals of outcomes.Let's do an example of grouped or interval data. A survey of 1140 (random) households has been done asking for an estimate of the household's annual income. Grouped into intervals of length $10,000 the results are in the interval $0 to $10,000 are 58 households, $10,000 to $20,000 are 147 households, $20,000 to $30,000 are 193 households, $30,000 to $40,000 are 286 households, $40,000 to $50,000 are 205 households, $50,000 to $60,000 are 130 households, $60,000 to $70,000 are 79 households, and $70,000 to $80,000 are 42 households.The table incometable below will have a third column consisting of the probabilities or relative frequencies of these income intervals. These probabilities are the percentages of the sample data which are in each interval. This table is called a frequency/probability distribution.income_terminators:= [0,10000,20000,30000,40000,50000,60000,70000,80000]:freqs:= [58,147,193,286,205,130,79,42]:sample_size:= add(i, i = freqs);incometable:= array(1..9,1..3,[[income,frequency,probability], seq([income_terminators[j]..income_terminators[j+1],freqs[j],evalf(freqs[j]/sample_size)], j = 1..8)]);For the purposes of computing the mean and standard deviations for grouped data, the interval of outcomes is replaced by its midpoint which in this case are 5,000 to 75,000.incomes:= [seq(Weight(income_terminators[j]..income_terminators[j+1],freqs[j]), j = 1..8)];M:= describe[mean](incomes);evalf(%);SP:= describe[standarddeviation[0]](incomes);evalf(%);SS:= describe[standarddeviation[1]](incomes);evalf(%);You can combine the two types of data in Maple although in practice this is rarely encountered. Also, Maple allows you to have missing data in a data list indicated by the word missing - this is virtually never used in a real situation. You can compute use in place of the frequencies the relative frequencies in order to compute the mean or population standard deviation. This gives the same results as if you had used the actual frequencies.probincomes:= [seq(Weight(income_terminators[j]..income_terminators[j+1],freqs[j]/sample_size), j = 1..8)];probM:= evalf(describe[mean](probincomes));probSP:= evalf(describe[standarddeviation[0]] (probincomes));Now we move on to histograms and scatter plots. These are two kinds of statistical plots contained in the statplots subpackage of stats. A histogram is a vertical bar representation of grouped data where the height of the vertical bar for a particular interval is the frequency assigned to the interval divided by the length of the interval. evalf(58/10000);with(stats,statplots):statplots[histogram](incomes, colour=red);statplots[histogram](probincomes, colour=blue);JSFHLet's now give the histograms for test scores 0 through 15 where the scores are converted to grouped data by making each interval of length 1 with midpoint a particular score.groupscores:= [Weight(-.5..(.5),18), Weight(.5..1.5,35), Weight(1.5..2.5,51), Weight(2.5..3.5,74), Weight(3.5..4.5,85), Weight(4.5..5.5,102), Weight(5.5..6.5,136), Weight(6.5..7.5,150), Weight(7.5..8.5,173), Weight(8.5..9.5,194), Weight(9.5..10.5,126), Weight(10.5..11.5,87), Weight(11.5..12.5,60), Weight(12.5..13.5,49), Weight(13.5..14.5,32), Weight(14.5..15.5,16)]:statplots[histogram](groupscores, colour=green);Now we can move on to scatter (or point) plots of two dimensional sets of data where each datapoint is considered a point in the plane. We are interested in doing this to see if there is a relationship between the values in the first coordinate relative to their second coordinates. Let's look at the following example for clarification. A company manufactures screw drivers and each week it posts the selling price p of its type A screw driver for the following week, and it's sales department notes the number q of screw drivers it sold that week at price p. It notes that for 5 consecutive weeks it has the following sales - q = 11,235 screw drivers when p = $5.47, q = 11,542 screw drivers when p = $5.27, q = 11,430 screw drivers when p = $5.33, q = 11,063 screw drivers when p = $5.58, and q = 10,891 screw drivers when p = $5.65. We can think of these pairs as the points in the plane with coordinates [q,p] or [p,q]. Let's plot them as [q,p] as a scatter plot and then as a point plot. quant:= [11235, 11542, 11430, 11063, 10891]:price:= [5.47, 5.27, 5.33, 5.58, 5.65]:statplots[scatterplot](quant,price, color=red, symbolsize=20);qp:= [seq([quant[j],price[j]], j=1..5)];with(plots):plotqp:= pointplot(qp, symbol=BOX, color=red, labels=[Quantity,Price]): display(plotqp, symbolsize=15);Our next topic will continue the previous one since it is clear from these plots that the quantity q and corresponding price p are almost linearly related since it appears that a line will pass almost through these points. In order to find this line of best fit we use (linear) regression or least squares fits which is in the fit subpackage of the stats package. with(stats,fit):fit[leastsquare[[q,p]]]([quant,price]);fitplot:= plot(12.26295214-.0006056651537*x, x=10800..11600): display({plotqp, fitplot}, symbolsize=15);This line passes close to all 5 points although it probably passes exactly through none of them. The value of this line is that it allows you to predict fairly accurately what the weekly sales q will be once you know the selling price p or vice versa. The following command switches the roles of q and p allowing us to quickly get q in terms of p - you could get the same result by solving p = 12.26295214 - .6056651537*10^(-3)*q for q.fit[leastsquare[[p,q]]]([price,quant]);Our next topic of discussion is random numbers. Random numbers are defined by Maple as positive 12 digit integers using the command rand() from the random subpackage. (An example below will show you how to use the trunc command to change your random numbers to fewer than 12 digits.) You can get random numbers from the positive integer N to the positive integer M using the command rand(N..M) which gives a Maple procedure you can name and use to generate your random values. The method Maple uses for generating random numbers uses a seed value which must be a positive integer. The seed value can be set by you using the global variable seed, and then you and someone else using this seed will generate the same random numbers in the same order.Random numbers are useful for doing simulations and for allowing you to pick random telepone or social security numbers for doing surveys. For a survey of people to accurately reflect the entire population, it must be both sufficiently large as well as random. Then the sample mean and standard deviation from the survey should accurately reflect the entire population within a certain margin of error which is usually 5%.with(stats,random):seed:= 1596:randlist:= [seq(rand(), j=1..10)];seq(trunc(randlist[j]/100), j=1..10);seed:= 8145:scor:= rand(1..50):seq(scor(), j=1..10);You also can use random numbers to run simulations of such things as throwing dice, tossing coins, picking cards, or other games which involve numbers or can be converted to numbers. As an example, we will run a simulation of throwing a "fair" 6-sided die to see if we get the conclusion that each face is equally likely to come up. We will use the last seed value of 8145. In order to carry out this simulation, we will pick 150 random numbers from 1 to 6 which will be sorted and tallied using these features in the transform subpackage of stats. If we are correct in our assumption that random numbers can simulate a fair die, then our tally of these 150 imaginary rolls of the die should give weights of approximately 25 to each of the face values 1 through 6. die:= rand(1..6):rolls:= [seq(die(), j=1..150)]:with(stats,transform):sortrolls:= transform[statsort](rolls):tallyrolls:= transform[tally](sortrolls);What we see above seems to be evidence that random numbers may not always simulate a fair or equally likely situation since they may not always give equally weighted values. In this case, our imaginary coin seems to be biased. This may be due to the method used to generate our random numbers or it may simply be a consequence of our choosing too small of a sample in the 150 rolls. Let's redo this simulation with a new seed value and many more rolls to see what happens. seed:= 7254:die:= rand(1..6):rolls:= [seq(die(), j=1..3000)]:sortrolls:= transform[statsort](rolls):tallyrolls:= transform[tally](sortrolls);The relative frequencies or probabilities in these 3000 rolls are much closer to the predicted equally likely value of 1/6 th than their counterparts in the previous simulation. Perhaps our random number generator does mimic a fair die after all if we look at relative frequencies instead of frequencies and our sample size is large enough. Our last topic for statistics will be the normal probability distribution. Before we can discuss this concept, we must first do some preliminary work. Data can be collected as we have seen in two different ways - grouped or ungrouped.Data (or the procedure producing the data) is also of two different fundamental types - discrete or continuous. Data is called continuous if an outcome or value in the data can be any real number within a set range of values. Examples of continuous data are ages, weights, lengths, and incomes since they can take on any positive real value. (Note that continuous data can take on an infinite number of different values.) Data is called discrete if an outcome in the data can only be chosen from a finite range of values. Examples of discrete data are die rolls with outcomes in the range 1 to 6, test scores in the range 0 to 100, and numbers of defective parts coming off a machine in the range of 0 to 20. The main difference between these two types of data is clearly that discrete data involves a finite number of possible outcomes while continuous data involves an infinite number of them with any value between two outcomes also being an outcome. The normal distribution was designed to work with continuous data (or to approximate discrete data as seen in histograms) which has certain very specific properties which are often encountered in practice. Continuous data is said to be normally distributed if all of the following properties are true. 1) All statistical information about the data is completely determined by the data's mean M and standard deviation S.2) The data is symmetrically distributed about the mean M. This means that any histogram for this data would have its highest vertical bar at the interval containing the mean M and the heights of the bars to either side of the highest would be symmetrically tapering off towards 0 in height as you move away from the mean. A histogram is said to be bell-shaped if it is symmetric about its mean and tapering towards 0 to either side of the mean. (This symmetry is in fact only truly seen in the histogram if the center of the highest vertical bar is the mean - otherwise the symmetry is somewhat broken although the normal distribution still applies.)3) The probability of getting an outcome in the data between x = a to x = b is the area between the x-axis and the graph of the function LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0a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0YnRi9GMkY1RjdGOUY7Rj1GP0ZBRlxyRl5yLUZJNiZRIk1GJ0YvRkxGT0YvRjJGL0YyLUYjNiVGam9GL0YyLyUxc3VwZXJzY3JpcHRzaGlmdEdRIjBGJ0YvRjItRiM2J0Zqb0Ziby1GXnE2JUZfb0Zic0Zkc0YvRjJGZHBGZnBGaXBGW3FGL0YyRi9GMkYvRjJGZHNGL0Yyfrom x = a to x = b. Here exp means the exponential function base e. The total area between the x-axis and this curve is exactly 1 with half of it before x = M and half after x = M. The symmetry of condition 2 and the fact that the total area is to be 1 are the main reasons for the choice of this function. The graph of this function is called a bell-shaped curve since it displays the intent of condition 2 above.The normal distribution and this function were originally investigated by the great German mathematician Carl F. Gauss in the 1800's.A consequence of condition 3 above is that all of the following are true -a) Approximately 68.27% of all the data is in the outcomes from M - S to M + S. The outcomes from M - S to M + S are said to be within one standard deviation amount from the mean. b) Approximately 95.45% of all the data is in the outcomes from M - 2S to M + 2S. The outcomes from M - 2S to M + 2S are said to be within two standard deviation amounts from the mean.c) Approximately 99.73% of all the data is in the outcomes from M - 3S to M + 3S. The outcomes from M - 3S to M + 3S are said to be within three standard deviation amounts from the mean.Let's look at an example of a continuous data situation where a normal distribution might apply. A food company makes a product which it markets at a mean weight of 18.2 ounces with a standard deviation of .13 ounces. It assumes from industry experience that a normal distribution applies. What percentage (probability) should a government food inspector testing random samples of this product find between 18.1 and 18.3 ounces if a normal distribution applies? We can use property 6 to decide the answer. The area between the x-axis and a curve can be found using the integration command int, and we will use the middlebox command in the student package to shade the region between the x-axis and our normal curve from x = 18.1 to x = 18.3. M:= 18.2:S:= .13:f:= exp(-.5*(x-M)^2/S^2)/(S*sqrt(2*Pi)):with(plots):nrml:= plot(f, x=M-3*S..M+3*S, y=0..1/(S*sqrt(2*Pi))):display(nrml);with(student,middlebox):shade:= middlebox(f, x=18.1..18.3, 25):display({nrml, shade});prob:= evalf(int(f, x=18.1..18.3));The area of this shaded region is approximately .5582 telling us that if a normal distribution applies, then our inspector should find in a large enough random sample that approximately 55.82% of her sample have weights between 18.1 and 18.3 ounces.Another situation where a normal distribution is used is in testing (such as the SAT, ACT, GRE, and GMAT exams and others) since a normal distribution can approximate certain discrete datatypes. The best way to see this will be through the following example. A standard test with possible scores from 0 to 100 is given to 100,000 people. It has been designed to have a mean of 65 and a standard deviation of 11 where the writers of this test hope it can be approximated by a normal distribution in the following way.The data from this test is contained in the list testscores. Since we are interested in a probability histogram of these scores, each score s will be given by an interval from s-.5 to s+.5 with weight the score's relative frequency or percentage occurence in this sample of 100,000. The lowest score on this test was 26.testscores:= [Weight(25.5..26.5,.00008), Weight(26.5..27.5,.00010), Weight(27.5..28.5,.00014), Weight(28.5..29.5,.00018), Weight(29.5..30.5,.00024), Weight(30.5..31.5,.00032), Weight(31.5..32.5,.00041), Weight(32.5..33.5,.00054), Weight(33.5..34.5,.00070), Weight(34.5..35.5,.00089), Weight(35.5..36.5,.00113), Weight(36.5..37.5,.00143), Weight(37.5..38.5,.00180), Weight(38.5..39.5,.00223), Weight(39.5..40.5,.00275), Weight(40.5..41.5,.00337), Weight(41.5..42.5,.00409), Weight(42.5..43.5,.00492), Weight(43.5..44.5,.00588), Weight(44.5..45.5,.00696), Weight(45.5..46.5,.00818), Weight(46.5..47.5,.00952), Weight(47.5..48.5,.01100), Weight(48.5..49.5,.01261), Weight(49.5..50.5,.01433), Weight(50.5..51.5,.01615), Weight(51.5..52.5,.01805), Weight(52.5..53.5,.02001), Weight(53.5..54.5,.02201), Weight(54.5..55.5,.02400), Weight(55.5..56.5,.02596), Weight(56.5..57.5,.02785), Weight(57.5..58.5,.02962), Weight(58.5..59.5,.03126), Weight(59.5..60.5,.03271), Weight(60.5..61.5,.03395), Weight(61.5..62.5,.03494), Weight(62.5..63.5,.03567), Weight(63.5..64.5,.03612), Weight(64.5..65.5,.03626), Weight(65.5..66.5,.03612), Weight(66.5..67.5,.03567), Weight(67.5..68.5,.03494), Weight(68.5..69.5,.03395), Weight(69.5..70.5,.03271), Weight(70.5..71.5,.03126), Weight(71.5..72.5,.02962), Weight(72.5..73.5,.02785), Weight(73.5..74.5,.02596), Weight(74.5..75.5,.02400), Weight(75.5..76.5,.02201), Weight(76.5..77.5,.02001), Weight(77.5..78.5,.01805), Weight(78.5..79.5,.01615), Weight(79.5..80.5,.01433), Weight(80.5..81.5,.01261), Weight(81.5..82.5,.01100), Weight(82.5..83.5,.00952), Weight(83.5..84.5,.00818), Weight(84.5..85.5,.00696), Weight(85.5..86.5,.00588), Weight(86.5..87.5,.00492), Weight(87.5..88.5,.00409), Weight(88.5..89.5,.00337), Weight(89.5..90.5,.00275), Weight(90.5..91.5,.00223), Weight(91.5..92.5,.00180), Weight(92.5..93.5,.00143), Weight(93.5..94.5,.00113), Weight(94.5..95.5,.00089), Weight(95.5..96.5,.00070), Weight(96.5..97.5,.00054), Weight(97.5..98.5,.00046), Weight(98.5..99.5,.00037), Weight(99.5..100.5,.00018)]: with(stats,statplots):hist:= statplots[histogram](testscores, colour=green):display(hist);M:= 65:S:= 11:f:= exp(-.5*(x-M)^2/S^2)/(S*sqrt(2*Pi)):plot2:= plot(f, x=25.5..100.5, y=0..1/(S*sqrt(2*Pi)), colour=red, thickness=5):display({hist, plot2});The graph of our normal distribution function f(x) is in red superimposed on our histogram. It is clear that the graph of f(x) is going through the midpoints of the tops of essentially all of these vertical bars. This indicates that the area between the graph of y = f(x) and the x-axis should give a very good approximation of the probability which corresponds to the same area in the histogram. It is because of this correlation between these two plots that it can be said that this test is approximately normally distributed with this mean and standard deviation. If these test scores had to assigned letter grades, then the curve involved in assigning these grades would be A for scores bigger than or equal to M+2*S, B for scores between M+S and M+2*S, C for scores between M-S and M+S, D for scores between M-2*S and M-S, and failure for scores below M-2*S. This is adopted to make C an average score with most people attaining it with the same number of B's as D's and usually A's as failures. Let's have Maple compute the mean M and standard deviation S to see if they really are 65 and 11 respectively for our data in testscores.with(stats, describe):describe[mean](testscores);describe[standarddeviation](testscores);These are very close to our given values in the beginning of this example which is what the test writers' hoped for. Let's now use this normal distribution to find the percentage of the 100,000 people who got scores between x = 60 and x = 80 inclusive. In using the normal distribution, we will change x = 60 to the interval 59.5 to 60.5 and x = 80 to the interval 79.5 to 80.5 since this is how the histogram and normal function f(x) relate to each other for the purposes of area giving probability. You should check that this agrees closely with the result you would get if you use the data in testscores directly. perc:= evalf(int(f, x=59.5..80.5));It appears that this percentage should be approximately 61.21%.
<Text-field style="Heading 1" layout="Heading 1">Solving Systems of Equations</Text-field>The purpose of this section is to show you how Maple can solve a single equation or a system of equations be they linear or non-linear.
Maple has several commands which solve equations such as solve, linsolve, and fsolve which usually give a sequence of solutions. fsolve looks for numerical solutions to a single equation or a system while solve and linsolve will seek exact solutions (if possible) to systems of equations where linsolve is specific to linear systems requiring the matrix of coefficients and the column of righthand side values. When solving a polynomial equation, if you use the option complex with fsolve then you will get all of the complex or real solutions with multiplicity.
The command linsolve does not give all of the solutions to a linear system if it has an infinite number of them - it only gives one solution. For this reason, you should use linsolve carefully, and mainly for square systems that have unique solutions. You should employ solve if you want all of the solutions to a linear system.
p := 2*x^4 - x^3 + 5*x - 7:fsolve(p = 0, x, complex);solve({S*cos(A) = 237.65, S*sin(A) = 157.89}, {S, A});fsolve({S*cos(A) = 237.65, S*sin(A) = 157.89}, {S, A}, {S = 0..500, A = 0..Pi/2});solve({(x - 3)^2 + (y - 7)^2 = 25,(x - 5)^2 + (y - 4)^2 = 16}, {x, y});e1 := (x - 3)^2 + (y - 7)^2 = 25:e2 := (x - 5)^2 + (y - 4)^2 = 16:fsolve({e1, e2}, {x, y});fsolve({e1, e2}, {x, y}, {x = 5..10, y = 4..7});with(linalg):m := array([[-1, 3, 5], [2, -4, 1], [0, -3, 8]]);b := array([-6, 7, -2]);linsolve(m, b);evalm(m^(-1)*b);m := array([[-1, 3, 5], [2, -4, 1]]);b := array([-6, -9]);linsolve(m, b);solve({-x + 3*y + 5*z = -6, 2*x - 4*y + z = -9},{x, y, z});JSFHYou should now try some examples of your own.
<Text-field style="Heading 1" layout="Heading 1">Basic Differential and Integral Calculus</Text-field>In this section we will examine how to compute derivatives, integrals, Taylor polynomials, and solve differential equations. The command diff will allow us to compute derivatives of a function of a single variable while integration is done using the commands int or evalf(int(. The command int tries to find an antiderivative while evalf(int( estimates a definite integral numerically.
The command taylor will compute Taylor polynomials of a function while the command dsolve will solve a system of differential equations either exactly or approximately. In the Calculus package there is a DSolve file which you should load to do systems or even complicated single equations.
f := x*exp(sin(3*x));df := diff(f, x);diff(f, x$2);derf := unapply(df, x);derf(Pi/4);evalf(%);g := x -> (x^2)*sin(x);int(g(x), x);int(g(x), x = Pi..2*Pi);evalf(%, 8);evalf(int(exp((-x^2)/2), x = -infinity..infinity));evalf(sqrt(2*Pi), 10);taylor(f, x = Pi, 5);evalf(%, 6);T := convert(%, polynom);plot({f, T}, x = 1..5);plot({f, T}, x = 2..4);dsolve(diff(y(x), x) = -x/y(x), y(x));dsolve({diff(x(t), t$2) = -.03*diff(x(t), t),
diff(y(t), t$2) = -32.2}, {x(t), y(t)});vecfld := array([t*cos(t), t*sin(t), exp(3*t)]):map(diff,vecfld,t);JSFHThe unapply command allows you to turn an expression into a function. The map command will apply another command such as diff to all the entries of an array such as vecfld.As problems, now compute and plot the 1st three Taylor polynomials for the function LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUkjbWlHRiQ2JlEiZkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JKG1mZW5jZWRHRiQ2JS1GIzYlLUYsNiZRInhGJ0YvRjJGNS8lJWJvbGRHUSZmYWxzZUYnL0YzUSdub3JtYWxGJy9GM0Y3RjUtSSNtb0dGJDYuUSI9RidGRUY1LyUmZmVuY2VHRkIvJSpzZXBhcmF0b3JHRkIvJSlzdHJldGNoeUdGQi8lKnN5bW1ldHJpY0dGQi8lKGxhcmdlb3BHRkIvJS5tb3ZhYmxlbGltaXRzR0ZCLyUnYWNjZW50R0ZCLyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGWi1JJW1zdXBHRiQ2JS1GLDYmUSJlRidGL0YyRjUtRiM2Ji1GLDYmUSRjb3NGJy9GMEZCRkVGNS1GOTYlLUYjNictSSNtbkdGJDYlUSIyRidGRUY1LUZHNi5RJyZzZG90O0YnRkVGNUZKRkxGTkZQRlJGVEZWL0ZZUSYwLjBlbUYnL0ZmbkZfcEY9RkBGQ0ZFRjVGQEZDLyUxc3VwZXJzY3JpcHRzaGlmdEdRIjBGJ0ZARkM= at LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYnLUkjbWlHRiQ2JlEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1JI21vR0YkNi5RIj1GJy9GM0Y3RjUvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRj8vJSlzdHJldGNoeUdGPy8lKnN5bW1ldHJpY0dGPy8lKGxhcmdlb3BHRj8vJS5tb3ZhYmxlbGltaXRzR0Y/LyUnYWNjZW50R0Y/LyUnbHNwYWNlR1EsMC4yNzc3Nzc4ZW1GJy8lJ3JzcGFjZUdGTi1JJm1mcmFjR0YkNigtRiM2JS1GLDYmUSNQaUYnL0YwRj9GPEY1LyUlYm9sZEdGPy9GM1Enbm9ybWFsRictRiM2JS1JI21uR0YkNiVRIjNGJ0Y8RjVGWkZmbi8lLmxpbmV0aGlja25lc3NHUSIxRicvJStkZW5vbWFsaWduR1EnY2VudGVyRicvJSludW1hbGlnbkdGY28vJSliZXZlbGxlZEdGP0ZaRmZu.
<Text-field style="Heading 1" layout="Heading 1">Recursion and Procedures</Text-field>This final section will discuss the very useful topic of recursion as well as the method of producing Maple procedures. Recursion is the easiest way to generate certain sequences such as the ones gotten from the Newton-Raphson method in approximating solutions to equations. Also, recursion is a convenient means of producing certain special functions such as the Legendre polynomials.
A Maple procedure is a means of defining a complicated function of several variables via a program (a collection or group of commands). A program in Maple is called a procedure.
First, let's produce a Newton-Raphson approximating sequence approximating the solution to the equation LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYvLUkjbW5HRiQ2JVEiMkYnLyUsbWF0aHZhcmlhbnRHUSVib2xkRicvJStmb250d2VpZ2h0R0YxLUkjbW9HRiQ2LlEnJnNkb3Q7RidGL0YyLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y6LyUpc3RyZXRjaHlHRjovJSpzeW1tZXRyaWNHRjovJShsYXJnZW9wR0Y6LyUubW92YWJsZWxpbWl0c0dGOi8lJ2FjY2VudEdGOi8lJ2xzcGFjZUdRJjAuMGVtRicvJSdyc3BhY2VHRkktSSVtc3VwR0YkNiUtSSNtaUdGJDYmUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvRjBRLGJvbGQtaXRhbGljRidGMi1GIzYlLUYsNiVRIjRGJ0YvRjIvJSVib2xkR0Y6L0YwUSdub3JtYWxGJy8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRictRjU2LlEoJm1pbnVzO0YnRi9GMkY4RjtGPUY/RkFGQ0ZFL0ZIUSwwLjIyMjIyMjJlbUYnL0ZLRmJvLUZNNiVGTy1GIzYlLUYsNiVRIjNGJ0YvRjJGZ25GaW5GW28tRjU2LlEiK0YnRi9GMkY4RjtGPUY/RkFGQ0ZFRmFvRmNvLUYsNiVRIjVGJ0YvRjJGNEZPLUY1Ni5RIj1GJ0YvRjJGOEY7Rj1GP0ZBRkNGRS9GSFEsMC4yNzc3Nzc4ZW1GJy9GS0ZlcC1GLDYlRl1vRi9GMkZnbkZpbg== near x = -1. You should also find a complex soution to this equation by using a complex starting value LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYlLUklbXN1YkdGJDYlLUkjbWlHRiQ2JlEieEYnLyUlYm9sZEdRJmZhbHNlRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUYjNiUtSSNtbkdGJDYlUSIwRidGMi9GOVEnbm9ybWFsRidGMkZBLyUvc3Vic2NyaXB0c2hpZnRHRkBGMkZB. The value n below is the number of iterations of the Newton-Raphson algorithm which will be found. The procedure newt is a function of the variable i and it carries out the iterations using the iterator g.
f := x -> 2*x^4 - x^3 + 5*x:plot(f(x), x=-2..2);df := unapply(diff(f(x), x), x);x0 := -1:n := 6:g := x -> x - f(x)/df(x);evalf(g(x0));newt := proc(i) evalf(g(newt(i-1))) end:newt(1) := x0:newton := seq(newt(i), i = 1..n+1);JSFHNow let's look at using recursion to produce the Legendre polynomials on the interval [-1, 1]. These polynomials are recursively defined by LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUklbXN1YkdGJDYlLUkjbWlHRiQ2JlEiUEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSxib2xkLWl0YWxpY0YnLyUrZm9udHdlaWdodEdRJWJvbGRGJy1GIzYlLUkjbW5HRiQ2JVEiMEYnL0Y2RjpGOC8lJWJvbGRHUSZmYWxzZUYnL0Y2USdub3JtYWxGJy8lL3N1YnNjcmlwdHNoaWZ0R0ZALUkobWZlbmNlZEdGJDYlLUYjNiUtRi82JlEieEYnRjJGNUY4RkJGRUZBRjgtSSNtb0dGJDYuUSI9RidGQUY4LyUmZmVuY2VHRkQvJSpzZXBhcmF0b3JHRkQvJSlzdHJldGNoeUdGRC8lKnN5bW1ldHJpY0dGRC8lKGxhcmdlb3BHRkQvJS5tb3ZhYmxlbGltaXRzR0ZELyUnYWN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dGFsaWNGJy1GIzYmLUYvNiVRIm5GJ0YyRjUtSSNtb0dGJDYtUSomdW1pbnVzMDtGJy9GNlEnbm9ybWFsRicvJSZmZW5jZUdRJmZhbHNlRicvJSpzZXBhcmF0b3JHRkUvJSlzdHJldGNoeUdGRS8lKnN5bW1ldHJpY0dGRS8lKGxhcmdlb3BHRkUvJS5tb3ZhYmxlbGltaXRzR0ZFLyUnYWNjZW50R0ZFLyUnbHNwYWNlR1EsMC4yMjIyMjIyZW1GJy8lJ3JzcGFjZUdGVC1JI21uR0YkNiRRIjFGJ0ZBRkEvJS9zdWJzY3JpcHRzaGlmdEdRIjBGJy1JKG1mZW5jZWRHRiQ2JC1GIzYkLUYvNiVRInhGJ0YyRjVGQUZBRkE=.
These polynomials are useful due to their many fasinating properties. We will see some of these properties shortly.
lpoly := proc(j) simplify(((2*j-3)*x/(j-1))*lpoly(j-1) - ((j-2)/(j-1))*lpoly(j-2)): end:lpoly(1) := 1:lpoly(2) := x: lpoly(3);legendrepolys := [seq(lpoly(i), i = 1..6)];legints1 := [seq(int((x^k)*lpoly(6), x = -1..1), k = 1..7)];with(linalg):legints2 := matrix(6, 6, (r, c) -> int(lpoly(r)*lpoly(c), x = -1..1));JSFHThe above examples should illustrate some of the useful features of Maple as well as showing that the Legendre polynomials form an orthogonal set of polynomials on the interval [-1,1]. You should look up the Chebychev polynomials in a Numerical Analysis text and show their properties using Maple.As one last example, we now will look at inscribing and circumscribing regular polygons of N sides to a circle of radius 1, and then using this to also estimate Pi.with(plots): with(plottools):drawpi:= proc(n)local c, t, polyins, polycir, piavg;c:= circle([0,0],1,color=red, thickness = 3):t:= 1/cos(Pi/n):polyins:= polygon([seq([cos((2*i-1)*Pi/n),sin((2*i-1)*Pi/n)],i=1..n+1)], color=green):polycir:= polygon([seq([t*cos((2*i-1)*Pi/n),t*sin((2*i-1)*Pi/n)],i=1..n+1)], color=blue):display([polyins, c, polycir], scaling = constrained);print(%);piavg:= evalf((sin(Pi/n)+tan(Pi/n))*n/2,25);end;drawpi(10);JSFHLet's now animate this procedure drawpi so that we can see these inscribed and circumscribed regular N-gons for N from 3 to 25. For this we need a different version of the drawpi procedure so that the plot is not automatically displayed and also that piavg is not shown.drawpi:= proc(n)local c, t, polyins, polycir;c:= circle([0,0],1,color=red, thickness = 3):t:= 1/cos(Pi/n):polyins:= polygon([seq([cos((2*i-1)*Pi/n),sin((2*i-1)*Pi/n)],i=1..n+1)], color=green):polycir:= polygon([seq([t*cos((2*i-1)*Pi/n),t*sin((2*i-1)*Pi/n)],i=1..n+1)], color=blue):display([polyins, c, polycir], scaling = constrained, view = [-2..2,-2..2]);end;JSFHNgons := [seq(drawpi(j), j = 3 .. 20)]:display(Ngons, insequence = true);JSFHLastly, we pull out of drawpi the piavg function to see how many sides n we need to get a good estimate of Pi.piavg:= n -> evalf((1/2)*(sin(Pi/n)+tan(Pi/n))*n, 25):piavg(100);seq(piavg(50*j), j=1..15);JSFH