tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,35 @@
q.norm={
if(type(q) != "t_VEC" || #q != 4, error("incorrect type"));
sqrt(q[1]^2+q[2]^2+q[3]^2+q[4]^2)
};
q.conj={
if(type(q) != "t_VEC" || #q != 4, error("incorrect type"));
-[-q[1],q[2],q[3],q[4]]
};
q.add={
if(type(q) != "t_VEC" || #q != 4, error("incorrect type"));
x->if(type(x) == "t_INT" || type(x) == t_REAL,
[q[1]+x,q[2],q[3],q[4]]
,
if(type(x) == "t_VEC" && #x == 4,
q+x
,
error("incorrect type")
)
)
};
q.mult={
if(type(q) != "t_VEC" || #q != 4, error("incorrect type"));
x->if(type(x) == "t_INT" || type(x) == t_REAL,
x*q
,
if(type(x) == "t_VEC" && #x == 4,
[q[1]*x[1] - q[2]*x[2] - q[3]*x[3] - q[4]*x[4],
q[1]*x[2] + q[2]*x[1] + q[3]*x[4] - q[4]*x[3],
q[1]*x[3] - q[2]*x[4] + q[3]*x[1] + q[4]*x[2],
q[1]*x[4] + q[2]*x[3] - q[3]*x[2] + q[4]*x[1]]
,
error("incorrect type")
)
)
};

View file

@ -0,0 +1,10 @@
r=7;q=[1,2,3,4];q1=[2,3,4,5];q2=[3,4,5,6];
q.norm
-q
q.conj
q.add(r)
q1.add(q2)
q1.add(q2) \\ or q1+q2
q.mult(r) \\ or r*q or q*r
q1.mult(q2)
q1.mult(q2) != q2.mult(q1)