#Kafung Mok #Homework 3 #Feb.2, 2014 Help:=proc(): print(`inv1(p), gf(n,q)`): end: ############ #Problem 1.# ############ #f:='f': #y:=f(x): #dy:=diff(y,x): #plot(sin(x),x=-2*Pi..2*Pi): #with(plots): #implicitplot(x^3+4*y,x=-2..1,y=-1..2); #plot3d(exp(-x^2+y^2-1)^3), x=-1..1,y=-2..2); #A:=matrix(2,3,[1,2,3,4,5,6]); #B:=matrix(3,2,[2,4,5,2,1,11]); #A&*B; #evalm("); ############ #Problem 2.# ############ #I tried writing a program to do this, but was #unsuccessful. Here are the results by using Maple. # #n:=50 #Digits:=74 # #n:=10 #Digits:=12 # #n:=20 #Digits:=26 #evalf(det(Hil(20))), det(evalf(Hil(20))); # #n:=30 #Digits:=43 # #n:=40 #Digits:=59 # #n:=60 #Digits:=88 # #n:=70 #Digits:=104 # #n:=80 #Digits:=117 # #n:=90 #Digits:=133 # #n:=100 #Digits:=148 ############## #Problem 3 a.# ############## #Counts the number of inversions in list p. inv1:=proc(p) local i,j,n,k: n:=nops(p): k:=0: for i from 1 to n-1 do for j from i+1 to n do if p[i] > p[j] then k:=k+1: fi: od: od: k: end: ############## #Problem 3 b.# ############## #Sum of q^inv1(p) over all the permutations of length n. with(combinat): gf := proc(n, q) local a, k, q1, i: a := permute(n): k := nops(a): q1 := 0: for i to k do q1 := q^inv1(op(i, a))+q1: od: q1: end: