Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
3774 views
ubuntu2004
1
load("__common__.sage")
2
3
def generator():
4
context=choice(["context_pol","context_mat"])
5
task=choice(["task_ind","task_spa"])
6
7
if task=="task_ind":
8
n=4
9
10
#Pick if yes a linear combination or no
11
independent = choice([false,true])
12
13
if independent:
14
A=simple_random_matrix_of_rank(n,rows=4,columns=n)
15
else:
16
A=simple_random_matrix_of_rank(choice([2,3]),rows=4,columns=n)
17
18
result=independent
19
20
if task=="task_spa":
21
#Pick How many vectors in R4
22
n=choice([4,5,6])
23
24
#Pick if yes a spanning set or no
25
span = choice([false,true])
26
27
if span:
28
A=simple_random_matrix_of_rank(4,rows=4,columns=n)
29
else:
30
A=simple_random_matrix_of_rank(choice([2,3]),rows=4,columns=n)
31
32
result=span
33
34
#Create equation
35
if context=="context_pol":
36
polys=[ sum([v[i]*x^i for i in range(0,len(v))]) for v in A.columns() ]
37
vset=polys
38
vars=[var("y_"+str(i+1)) for i in range(0,A.ncols())]
39
lc=linearCombination(vars,polys,parentheses=true)
40
if task=="independent":
41
eq=Equation(lc,"0")
42
else:
43
eq=lc
44
45
if context=="context_mat":
46
matrices = [ matrix(ZZ,2,v) for v in A.columns()]
47
vset=matrices
48
vars=[var("y_"+str(i+1)) for i in range(0,A.ncols())]
49
lc=linearCombination(vars,matrices)
50
if task=="independent":
51
eq=Equation(lc,matrix(ZZ,2)) #matrix() defaults to zero matrix
52
else:
53
eq=lc
54
55
return {
56
task: True,
57
context: True,
58
"set": bracedSet(vset),
59
"equation": eq,
60
"result": result,
61
"matrix": A,
62
"rref": A.rref(),
63
}
64