#OK to post homework #TianHao Zhang,02/23/19 #################################Help###################################### Help := proc():print(`A(n)` ):end: #################################Part2##################################### #ArDataMV(A,v,N): inputs a pos. number A, and a vector of numbers v (given as a list), (let n:=nops(v)) and outputs a list of length N where each entry is a pair obtained by picking a random point (a list of length n) in [-A,A]^n and returns the pair [x,0] if v.x (the dot product of v and x) is negative and [x,1] if it is zero or positive. ArDataMV:=proc(A,v,N) local i, j, ra, t, x, n, sum, L: L:=[]: n:=nops(v): ra:=rand(-abs(A)..abs(A)): for i from 1 to N do x:=[]: for j from 1 to n do t:=ra(): x:=[op(x),t]: od: sum := 0: for j from 1 to n do sum := sum + x[j]*v[j]: od: if sum < 0 then L:=[op(L),[x,0]]: else L:=[op(L),[x,1]]: fi: od: L: end: #################################Part3##################################### #PAmv(L,n): that inputs a list containing data of the form [VectorOfLenghn,ZeroOrOne] where, VectorOfLengthn is a list of length n, and n is the dimension. PAmv:=proc(L,n) local i,j,v,x,N,sum: v:=[seq(0,i=1..n)]: N:=nops(L): for i from 1 to N do x:=L[i]: sum:=0: for j from 1 to n do sum := sum + x[1][j]*v[j]: od: if sum < 0 and x[2]=1 then for j from 1 to n do v[j] := v[j] + x[1][j]: od elif sum >= 0 and x[2]=0 then for j from 1 to n do v[j] := v[j] - x[1][j]: od fi: od: v: end: #################################Part4##################################### #TestPMV(L,v) where v is a vector (list) with n components TestPMV:=proc(L,v) local fn, fp, i, j, sum, n, N, x: fn:=0: fp:=0: N:=nops(L): n=nops(v): for i from 1 to N do sum:=0: x:=L[i]: for j from 1 to n do sum := sum + x[1][j]*v[j]: od: if sum >= 0 and x[2]=0 then fp:=fp+1: elif sum < 0 and x[2]=1 then fn:=fn+1: fi: od: [fn,fp,N]: end: #################################Part5##################################### #PA1corrected(L): That first transfoms the list L to the format [[data,1],ZeroOrOne], and uses your procedure PAmv(L,n) with n=2 to outputs two numbes a and b such that L[i][2]=1 iff ax+b>=0. Compare its performance to PA1(L). PA1corrected:=proc(L) local i, L1, n: n:=nops(L): L1:=L: for i from 1 to n do L1[i][1]:=[op(L1[i][1]),1]: od: PAmv(L1,2): end: