TDEC 160: Final Maple ExamJeremy JohnsonName: Section:Instructions: There are three questions, each worth 4 points, for a total of 12 points (partial credit will be given). The quiz must be completed in 50 minutes and submitted to webct. Please put your name and section in the worksheet above.The quiz must be done independently using Maple. You can use all of the available help resources in Maple, but nothing else. If you have any questions, you may ask for clarification. Questions have multiple parts and you should attempt all parts. Make sure you read the instructions carefully. If you have forgotten how to use a command, use Maple's help facility.Question 1 [4 points] (Differentiation and Tangent Lines - diff, evalf, and plot)In this question you will investigate the functions 2^x and 3^x. In particular, you will compute the slope of these functions (use diff) at the point x=0 (also use evalf to compute numeric values of the slopes). The you will plot, in, in two separte plots, the function 2^x and the line tangent to 2^x at the point x=0, and the function 3^x and the line tangent to 3^x at the point x=0. Finally use the command display to combin the two plots.with(plots);Question 2 [4 points] (The Definition of the Derivative - limit, seq, evalf, and solve)In this question you will investigate the derivative of the function a^x. 1) Use the limit command to determinate the derivative of 2^x by definition (i.e. LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2OVEhRicvJSdmYW1pbHlHUTBUaW1lc35OZXd+Um9tYW5GJy8lJXNpemVHUSMxMkYnLyUlYm9sZEdRJmZhbHNlRicvJSdpdGFsaWNHUSV0cnVlRicvJSp1bmRlcmxpbmVHRjcvJSpzdWJzY3JpcHRHRjcvJSxzdXBlcnNjcmlwdEdGNy8lK2ZvcmVncm91bmRHUShbMCwwLDBdRicvJStiYWNrZ3JvdW5kR1EuWzI1NSwyNTUsMjU1XUYnLyUnb3BhcXVlR0Y3LyUrZXhlY3V0YWJsZUdGNy8lKXJlYWRvbmx5R0Y3LyUpY29tcG9zZWRHRjcvJSpjb252ZXJ0ZWRHRjcvJStpbXNlbGVjdGVkR0Y3LyUscGxhY2Vob2xkZXJHRjcvJTBmb250X3N0eWxlX25hbWVHUSVUZXh0RicvJSptYXRoY29sb3JHRkMvJS9tYXRoYmFja2dyb3VuZEdGRi8lK2ZvbnRmYW1pbHlHRjEvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLyUpbWF0aHNpemVHRjQ=). Check the answer returned by limit using diff.2) Use the formula obtained in (1) to compute the value of the derivative at x=0. Use evalf to get a numeric approximation.3) Numerically compute the value of the derivative of 2^x at x=0 using the definition of the derivative. Compute a sequence of values using LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYuLUkjbWlHRiQ2OVEhRicvJSdmYW1pbHlHUTBUaW1lc35OZXd+Um9tYW5GJy8lJXNpemVHUSMxMkYnLyUlYm9sZEdRJmZhbHNlRicvJSdpdGFsaWNHUSV0cnVlRicvJSp1bmRlcmxpbmVHRjcvJSpzdWJzY3JpcHRHRjcvJSxzdXBlcnNjcmlwdEdGNy8lK2ZvcmVncm91bmRHUShbMCwwLDBdRicvJStiYWNrZ3JvdW5kR1EuWzI1NSwyNTUsMjU1XUYnLyUnb3BhcXVlR0Y3LyUrZXhlY3V0YWJsZUdGNy8lKXJlYWRvbmx5R0Y3LyUpY29tcG9zZWRHRjcvJSpjb252ZXJ0ZWRHRjcvJStpbXNlbGVjdGVkR0Y3LyUscGxhY2Vob2xkZXJHRjcvJTBmb250X3N0eWxlX25hbWVHUSgyRH5NYXRoRicvJSptYXRoY29sb3JHRkMvJS9tYXRoYmFja2dyb3VuZEdGRi8lK2ZvbnRmYW1pbHlHRjEvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLyUpbWF0aHNpemVHRjQtSSVtc3VwR0YkNiUtSSNtbkdGJDY5USMxMEYnRi9GMkY1L0Y5RjdGO0Y9Rj9GQUZERkdGSUZLRk1GT0ZRRlNGVUZYRlpGZm4vRmluUSdub3JtYWxGJ0Zbby1GYW82OVEiMEYnRi9GMkY1RmRvRjtGPUY/RkFGREZHRklGS0ZNRk9GUUZTRlVGWEZaRmZuRmVvRltvLyUxc3VwZXJzY3JpcHRzaGlmdEdRIjBGJy1JI21vR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USdjZW50ZXJGJy8lKW51bWFsaWduR0Zmcy8lKWJldmVsbGVkR0Y3RmZxRmhxLUZjbzYzUTAmQXBwbHlGdW5jdGlvbjtGJy9GZ29RJmluZml4RidGaW9GW3BGXXBGYHBGYnBGZHBGZnBGaXBGXHFGXnFGYHFGYnFGZHFGZnFGaHEtRl1yNiZGX3IvRmNyUScwLjR+ZW1GJ0ZlckZnckYrLUklbXN1cEdGJDYlLUYsNjlRImFGJ0YvRjJGNUY4RjtGPUY/RkFGREZHRklGS0ZNRk9GUUZTRlVGWEZaRmZuRmhuRltvLUYsNjlGXHNGL0YyRjVGOEY7Rj1GP0ZBRkRGR0ZJRktGTUZPRlFGU0ZVRlhGWkZmbkZobkZbby8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRictRmNvNjNRIj1GJ0ZedEZpb0ZbcC9GXnBRL3RoaWNrbWF0aHNwYWNlRicvRmFwRmN1RmJwRmRwRmZwRmlwRlxxRl5xRmBxRmJxRmRxRmZxRmhxRmR0LUZjbzYzUSIuRidGXnRGaW9GW3BGXXBGYHBGYnBGZHBGZnBGaXBGXHFGXnFGYHFGYnFGZHFGZnFGaHFGKw==Question 3 [4 points] (Recursion and Trees) In this question you will write a recursive Maple function to compute the number of nodes in a binary expression tree. Trees will be represented as they were in Lab 5 and the code to build and manipulate trees is provided in the subsection "Expression Tree Code".First evaluate the expression tree code so that the provided routines are available in your Maple session. Second evaluate the expression that constructs the tree T and print it using the provided PrintTree function and evaluate it using the provided EvalTree function. Differentiate the tree T, with the provided DiffTree function, and check, using diff and EvalTree that the computed derivative is correct.Next write a recursive Maple function called NumberNodes, which computes the number of nodes in an expression tree. See below for a few hints on how to do and check this.Use your function to compute the number of nodes in the tree T (it should be 9) and the number of nodes in the tree returned by DiffTree with T as an input.Expression Tree CodeMakeTree := proc(val,left,right) return [val,left,right];end;NullTree := proc() return [];end;IsNullTree := proc(T) return T = NullTree();end;MakeLeaf := proc(val) return [val,NullTree(),NullTree()];end;GetLeft := proc(T) return T[2];end;GetRight := proc(T) return T[3];end;GetVal := proc(T) return T[1];end;The following function prints a tree in a human readable form. To simplify the code, the tree is printed sideways, i.e. rotated 90 degrees counter clockwise.# A function to print a binary tree.
# The root of the tree is printed to the left and the tree should be rotated to be viewed.
PrintTree := proc(T) PrintTreeAux(T,"");end;PrintTreeAux := proc(T,str)
local leadingblanks;
leadingblanks := " "; if IsNullTree(T) then return; else PrintTreeAux(GetRight(T),cat(leadingblanks,str)); # Print right child with additional indentation printf("%s %a\n",str,GetVal(T)); PrintTreeAux(GetLeft(T),cat(leadingblanks,str)); end if;end;EvalTree := proc(T) local val,left,right;
if IsNullTree(T) then
return;
end; val := GetVal(T); left := GetLeft(T); right := GetRight(T); if (val = `+`) then return `+`(EvalTree(left),EvalTree(right)); elif (val = `-`) then return `-`(EvalTree(left),EvalTree(right)); elif (val = `*`) then return `*`(EvalTree(left),EvalTree(right)); elif (val = `/`) then return `/`(EvalTree(left),EvalTree(right)); elif (val = `^`) then return `^`(EvalTree(left),EvalTree(right)); elif type(val,name) then return val; elif type(val,constant) then return val; else error "illegal expression tree"; end if;end;DiffTree := proc(T,x) local val,left,right,n;
if IsNullTree(T) then
return;
end; val := GetVal(T); left := GetLeft(T); right := GetRight(T); if type(val,constant) then
return MakeLeaf(0);
elif (val = `+`) then # Sum of derivatives return MakeTree(`+`,DiffTree(left,x),DiffTree(right,x)); elif (val = `-`) then # Difference of derivatives return MakeTree(`-`,DiffTree(left,x),DiffTree(right,x)); elif (val = `*`) then # Product Rule return MakeTree(`+`,MakeTree(`*`,left,DiffTree(right,x)),MakeTree(`*`,DiffTree(left,x),right)); elif (val = `/`) then # Quotient Rule return MakeTree(`/`,
MakeTree(`-`,
MakeTree(`*`,DiffTree(left,x),right),
MakeTree(`*`,left,DiffTree(right,x))),
MakeTree(`*`,right,right) ); elif (val = `^`) then # Chain Rule left^right -> right*left^(right-1)*diff(left,x)
n := EvalTree(right); return MakeTree(`*`,MakeLeaf(n), MakeTree(`*`,MakeTree(`^`,left,MakeLeaf(n-1)),DiffTree(left,x))); elif type(val,name) then # must put this case at the end as `*`, etc. are names. if (val = x) then return MakeLeaf(1); else return MakeLeaf(0); end if; else error "illegal expression tree"; end if;end;T := MakeTree(`+`,MakeTree(`*`,MakeLeaf(3),MakeLeaf(x)),MakeTree(`^`,MakeTree(`+`,MakeLeaf(2),MakeLeaf(x)),MakeLeaf(10)));Recursive function to compute the number of non-Null nodes in a tree. Recall that a tree is either empty (Null) or is a triple with a value and left and right children which are trees. You should use the tree functions, e.g. IsNullTree, GetLeft, GetRight, etc. in the provided expression tree code.Answering the following questions will show you how to write the function NumberNodes.1) In the base case (Null Tree) how many non-Null nodes are there?2) Suppose n1 is the number of nodes in the left child and n2 is the number of nodes in the right child (these values are obtained by recursive calls). How many nodes in the tree.Print the tree T again count the number of nodes to verify it is 9.Print the left child of T. How many nodes in the left child? Print the right child of T. How many nodes in the right child?Now you should be able to write the recursive function NumberNodes. Test it first on a NullTree and then test it on T, the left child of T, and the right child of T.